I am new to mvc asp.net,I have already one application created in asp.net 4.0,
but i want to convert that exixting application to asp.net mvc architecture.
In my application every page is having some server control e.g. button, but i am not able to invoke the function associated with the button or server controls.
so, please guide me that how i will proceed so that i can convert my exixting application to mvc architecture.
ASP.NET Web Forms (including pages and server controls) rely on infrastructure provided by ASP.NET page and post-back model. On post-back, the control tree is re-build and state is restored using view-state and then control handles the post-back data to raise events.
ASP.NET MVC does not rely on post-back/view-state rather requests (GET/POST) are routed to appropriate controller actions (along with parameter mapping). The controller methods process the request and sends the response by rendering the view. View's function is just to accept the data passed by controller and generate corresponding HTML. Now ASP.NET webform (page) can be used as a view but there would be no post-back and no server control events. In ASP.NET MVC, a button click would POST appropriate form to some controller action.
You need to first understand & learn ASP.NET MVC before contemplating the migration.
Further, IMO, there is no point in migrating the application unless it has long shelf life and you foresee a frequent enhancement/maintenance requests in future.
Related
I could only find this but at some point it talks about the IsPostback property so I think it might be for the ASP.NET Web Forms.
Is there any information relative to the ASP.NET Web Pages Life Cycle?
Update: When I use some JavaScript, how it is related with the Life Cycle of an IController instance?
Maybe you mean the life cycle of the controller. If so you should also find this useful
The Life And Times of an ASP.NET MVC Controller
JavaScript code is always executed when th page is served to the client. This is true regardless of the technology you use. All serverside code is already executed when the page is served to the client therefore JavaScript executes after it.
ASP.NET Web Page is a view engine (with razor syntax), just like other view engines, It only do render your data + template to html.
It is usually used with ASP.NET MVC. If you want to know how request and response work in ASP.NET MVC, you can read these articles ASP.NET MVC Architecture, Routing and Filtering
I have a Silverlight application hosted inside an asp.net website. In my silverlight applicaiton, if I select a theme. Then, theme changes will gets fired. I want to get notified in asp.net web page, when the theme changed event is fired inside the silverlight application.
Note: Also, I don't want to use a data base to maintain the state of the application.
You can't easily raise an asp.net application event from your Silverlight App. It should be possible, but would require your SL app to do a POST request on the server with POST parameters interfacing well with the ASP.NET plumbing. It's hacking, I would say that's not the recommended way to do it and if you do it asynchronously (without reloading the page), it could do weird things with your viewstate.
You can however call a web service from the SL app when the user change the theme. (the webservice could be something as simple as a request handler or an aspx page with get parameters or maybe a WCF service)
You could then store values about the selected theme in the user session.
I'm a PHP developer who has to work on ASP.net projects and I'm wondering why every page is wrapped in a form. This just doesn't make sense to me.
Also What's with all the hidden input fields especially the "View State" one.
ASP.Net tries to make it so that the programmers can pretend that the web is a stateful platform, and that it behaves like a desktop application. The ViewState is basically a serialized block of the state of the page when it was generated. When the page gets posted back the server side model gets initialized to the values in ViewState, and then the new values from the posted form are applied.
Part of becoming a decent ASP.Net programmer is learning when to use ViewState and not, because the default is to use it everywhere which causes a lot of bloat in the downloaded page.
Every ASP.NET page is wrapped in a <form> element because the entire framework revolves around POST commands.
ASP.NET provides 'web controls' which are object-oriented abstractions of HTML elements (and in some cases, groups of elements) - in your server-side code you can attach commands to various events on web controls (for example, Button.OnClick, TextBox.OnChanged) - the framework wires these up using a combination of hidden fields and generated javascript. The generated javascript typically sets a hidden field few values to indicate (for example) which control triggered the post and the command arguments (if applicable), then submits the form.
ViewState is a technique used by the framework to serialize client state. It's an alternative to using session heavily, trading larger HTML payloads for a lower memory footprint on the server.
Everything in ASP.NET (aspx pages) works off of posting data.
This means that anything you place on the web page with a server-side action will cause a "post back" to itself. The post back contains information such as "what just happened" and some information that helps the web page to maintain state (which web pages don't traditionally do). The view state is part of that task of maintaining state.
If you don't like the way aspx pages try to turn web-pages into forms-style stateful applications, you can try out the ASP.NET MVC framework, which lets the web work as intended!
ASP.NET WebForms engine creates a stateful abstraction over stateless HTTP.
The key object is a server page. Controls fire events that are processed server-side. Controls maintain their states (usually, input values) between requests.
Any time you click a server control, a "postback" request is sent back to the server. ViewState actually contains the data telling the server what control fired the event. That is why there is always a form (and any more forms are not allowed).
I am adding functionality to an ASP.Net webforms application and we've decided that new development will be done MVC with a view to move all functionality over eventually.
Obviously, MVC and WebForms play together rather nicely when it comes to accessing an MVC action via a URL. However, I'd like to display the MVC view within an existing tab (telerik) control on a WebForm page. This view will be using js/css file so that will need to be considered also.
Well I'd use jquery/js to load the tab dynamically on page load / select tab. If add a js function to the required handler you can fire an ajaxGet to retrieve the html from your MVC action URL.
If needed I can get some sample code. Are you using jQuery in your ASP.Net app or MSAJAX ??
Cheers
ian
I am new to this whole sharepoint and aspx programming. I have developed a sharepoint web part that has a button control. The onclick event is mapped to a method in my web part code. When I click the button the whole page reloads and the web part is rendered again. Is there a way to prevent this reloading of the page? Is there a way to call the function method in the background? Something similar to AJAX.
Thanks,
Jagannath
You can use Ajax, it just requires some sharepoint configuration. Here are a few posts to get you started:
http://weblogs.asp.net/jan/archive/2007/02/26/using-the-ajax-control-toolkit-in-sharepoint.aspx
http://sharepoint.microsoft.com/blogs/mike/Lists/Posts/Post.aspx?ID=3
Ajax or SilverLight are your only two options for Async operations without a page refresh.
Once you know the tricks needed to get SharePoint and ASP.NET AJAX to work together it's not that difficult.
Here are the steps required:
Ensure the ASP.NET AJAX Extensions are installed on all the front-end web servers (this is not required if you are using .NET 3.5 as the Extensions are included in the Framework)
Update the Web.config file for the SharePoint Application to support ASP.NET AJAX
Ensure any page that is going to use AJAX has a ScriptManager
Use an UpdatePanel or a client-side service call to get updated data and re-render the Web Part
This blog post has some resources from a talk I did on the subject at TechEd Barcelona 2008. These resources should give you the information you need to get started.
http://msmvps.com/blogs/windsor/archive/2008/11/13/teched-emea-resources-and-demos-integrating-asp-net-ajax-with-sharepoint-2007.aspx