asp.net MVC bootstrap button click event? - asp.net-mvc

I am new to asp.net, razor and bootstrap and very familiar with winforms and older code.
I am trying to understand one thing: button click event in MVC?
MVC has no design view, no properties view to go right to the events. I have been trying to understand the relationship between jquery, c# and a button in a view, where does the logic live? i have created functions, tried to set a debug breakpoint, says code will never get here...
The other examples seem to be that while c# has a single onbutton click() event; in the mvc there could be several files that must line up with no intellisense to make sure its got the right handler???

You are confusing client-side JavaScript with server-side C#.
In WebForms, you create a "OnClick" event that gets called on the server, but there is no such thing in MVC. The only "onclick" is a javascript client-side event that can only do things in javascript in the browser (or make ajax calls to the server).
Button clicks, if they are set as "submit" buttons trigger form posts, which call Action Methods on the server, these are not events. They are just your MVC action methods.
So the short answer is.. there is no "OnClick" event that calls a Server side handler.

Related

if asp.net mvc doesnot support page load event then what should we do for page laod event in mvc

I am new to ASP.NET MVC .
To start learning on MVC, I was going through a tutorial on MVC, where they used the Page_Load event which is same as in Web forms.
Does MVC support events, and if so what events are supported?
If ASP.NET MVC does not support Page_Load event, then what is the alternative?
One thing that i was told before learning MVC was, 'Just forget everything about Webforms. It's old, and doesn't support separation actually.' Don't think about asp.Net webforms while learning MVC. MVC has a different life cycle.
An answer to your question is, MVC doesn't support Page_Load or any event, and it all depends on what you want to implement. Here are few tips:
1.) If you want to implement something before View (UI or html page) is rendered, you can write logic in controller before returning the View.
2.) If you want to implement something in the process of rendering page, you can use razor markups. It is quite easy to use razor.
3.) If you want to implement something after Page has been totally rendered, you can use jQuery's document.Ready().
You can start learning MVC here: http://asp.net/mvc
You should use Javascript/Jquery for event handling in MVC application. You may be use document.Ready() event handler to trigger the page load event and then handle your logic using javascript/jquery.

How to access the view page from a controller?

I've been tasked w/porting an older ASPX app to .NET MVC, and then doing some work on it.
This has been fraught with peril; not the least of my troubles is that the APSX events won't propagate in this framework (using ViewPage for the aspx.cs file - MVC 4 demands it)
I.E. - an asp:Button with a defined click event won't fire that click event anymore.
What prompted this particular question is this - I've got an asp:table that I want to reload when certain actions happen in the controller. In the code behind file, I've got a method that handles that, and it gets called from Page_Load, just fine.
But in the controller, I need to find a way to get a handle on that page itself and invoke that method. I can get a new instance of the page, but that instance won't have the table already instantiated.
How, in the controller, can I get a hold of the ViewPage created for that method?
You can't think about MVC that way. There are no click events like you think of them when you think ASP.NET.
read these
http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/intro-to-aspnet-mvc-3
http://www.w3schools.com/aspnet/mvc_intro.asp
you might find some joy with them
these will help too
Migrating from ASP.NET WebForms to MVC
and Migrating legacy ASP.NET to MVC 2 (RC): HttpApplication events not firing, User principal is null

can i open views in an ajax modal popup?

I've been searching about using ajax modal popups in asp.net mvc, and i've only seen uses where there's a simple dialog box for input.
Is it possible to open an entire view in an ajax popup? Is it possible to navigate multiple views in a single modal popup instance, as if they were going through a wizard?
I haven't found any good references about this, I would appreciate any and all links to relevant info! thank you !!
You can load any response type your heart desires via ajax and in a modal popup. Most of the good major modal plugins (jquery ui, colorbox, jquery toolbox, etc) have some simple events you can plug into. If the modal plugin doesn't natively support it you can do a simple call to JQuery's "load" method.
$("#modal-dialog").load("/ajax/url");
Create a simple route for "ajax/url" and you're set. You're probably better off returning a partial view for that "ajax/url" action but you can also return plain text, or whole page if you want.
Moral of the story is to set up an action that returns what you need (text, html, xml, etc). Make sure it can be accessed with a route, and use jQuery's ajax methods to fetch it.
using jQuery UI's dialog plugin, you could do something like:
$("#id").load(url).dialog();
and 'url' would be an action on your controller that returns a partial view. then you could put links in your partials that trigger a .load() with the url of the next partial in the wizard.
jqModal also has an AJAX loading feature:
http://dev.iceburg.net/jquery/jqModal/#examples

ASP.NET MVC & Silverlight - fire an event in both with one button?

I currently have a little form with a silverlight bit for a person to sign their name and I was wondering if there was a way to have the submit button post to the controller and a silverlight code behind action... I tried adding a dom event to fire silverlight code but I guess that doesn't fire both events...
Any ideas?
You can have Silverlight make calls back out to the DOM:
Calling Javascript functions from Silverlight (Example is Silverlight 2)
Using that method, you can have your Silverlight app complete its logic and then call back in to the page to complete the page postback logic.

Probs with ASP.NET MVC Postback + Callback Synchronously

I am trying to create an upload control for ASP.NET MVC with jQuery progress bar. In ASP.NET the implementation works no problems, but in MVC the problem is that the server doesn't respond to my callbacks until the file is uploaded.
The upload control is based on html file upload element, and I cannot for the life of me, understand how MVC handles postback + callback synchronously ?
I have searched for a whole bunch of answers, but all I can find is a "callback+callback" solution and NOT a postback+callback.
Does anyone have any idea how to solve this problem for MVC ?
Thanks
Hrmmm,
Thomas, MVC does not handle post-backs at all. Because a URL is directly routed to an Action method on a controller, a form is not meant to actually post-back to itself. Further more, all of the post back processing that Asp.Net had to handle post-backs on the server was pulled out of the .Net MVC framework.
A better approach to accomplish what you're trying to do with a progress bar would be to use JQuery with AJAX to make the call to your server and then use Javascript/CSS (possibly a lightbox approach) or a pop-up window to inform the user that they are waiting. When the Ajax call completes it's work, you can have Javascript fire the redirect to the page in your MVC that you want the user to be redirected to after the action has been performed. Making AJAX calls with JQuery is a total breeze and is pretty fun to play around with as well!
Check it...
Suggestion:
You can use the JQuery Uploadify control to show the status of
the upload. This control has a flash and html 5 type controls. Use whichever is applicable to you.

Resources