As a test, I wanted to have an ASP.NET page rendered without the auto-generated javascript. Is this possible?
Assuming you're referring to ASP.NET UserControls, I would imagine that the javascript and css rendered with ASP.NET User Control is built in and cannot be prevented out the box. You may be able to override the render and prevent it?
If you are after to remove __dopostback and so on, you have to change the ASP.NET standard control behavior (like LinkButton). IMO, you can use ASP.NET MVC that gives you more controls on the markup.
Related
I am currently working with ASP.NET and the person who designed the form has used all Server Controls for things like TextBoxes and Dropdowns etc when really they are not providing postbacks.. Some of the dropdowns and textboxes are values that I need only in jQuery so as far as I can see there are no drawbacks to coverting these controls to standard html controls rather than ASP.NET server controls?
I suppose I will need to continue to have my GetDataGrid button as a server control because I will need it to postback (and receive PageLoad events etc - all asp.net events) to update the GridView? Or would it be possible to use the GridView (ASP.NET server control) from a Webmethod and call it via Jquery?
Of course in my webmethod I would need to the instance of the gridview to add the datasource - but I don't see how this would be possible without being in the ASP.NET events - or maybe I wrong?
The other thing I thought of was changing the GetGridView button to a standard HTML and calling the javascript postback from the client click event?? This way it would do a real postback and I would end up in Page_load.
Taking everything into effect i don't want to the change the GridView asp.net control as it funcions well as an asp.net server control but i am unsure how i would do this.
I remember a document being available that said "how to use asp.net webforms without server controls" but i can't seem to find it. I suppose using webforms like asp.net MVC - but i can't change the project to MVC - its out of my control.
I would love to hear some feedback with regards to how to do this or comments etc.
I find ASP.NET webforms to inject a lot of code smell into pages - I am using .NET 3.5 so a lot of the output is with tables etc...
If you use Request.Form["..."] then you can get the information which was filled in in standard html input fields.
Instead of keep on using the GridView control I suggest you take a look at either jqGrid or the new templating system that Microsoft put into place for jQuery (currently a plugin but expected to be part of core jQuery from version 1.5 on). These can bound to json which can be retrieved from a webmethod or pagemethod call to fill up the template with data.
Also i don't think its possible from asp.net (code behind) to receive values of an html >control without it having runat=server.
Use webmethods.
Set a client event (like 'onchange') on the html control and then in javascript function called when the event is fired you can use PageMethods to send your data to the code behind.
Some thoughts...
The GridView can't be created in a WebMethod and even if there was a way to get that to work, you'd be better off going with a genuine client side grid. As that's not an option, I don't think there is too much point in trying to make any major changes to your existing pages.
ViewState
Changing the textboxes, buttons etc to HTML versions, would gain you a little bit in reduced Viewstate size but add a bit of complexity in how you handle interactions with the page. You can add runat="server" to HTML controls which will give you control over what is rendered and still have access to the control on the server side.
.Net 4 gives you far more control over viewstate but unfortunately in 3.5 its not as easy.
The GridViews
You could wrap the GridViews in UpdatePanels. That's a 'cheap' way to add some interactivity to your pages although you won't be gaining anything in terms of performance.
It's also still possible to manipulate the Gridview using jQuery on the client-side. There a lots of tutorials, blog posts etc explaining how to do this on the Internet.
MVC with Webforms
Its also possible to mix ASP.Net MVC with Webforms in the same website. As it sounds like you are familiar weith MVC, you might want to consider this approach for any new pages. Here's a blog post explaining how to do this.
Update:
Here's a more recent article by Scott Hanselman on how to use MVC with an existing Webforms application.
can we use server side controls in MVC, if no then why server side control list appears.
If you use the webforms viewengine (default) you can use the controls that doesn't use viewstate in asp.net mvc as well. And if you add a form with the attribute runat="server" you can use the controls that use viewstate as well. But I'd tell you not to use any of them even if you can. They don't really add any benefit for you anyway as you do not use your code-behind classes. You can't use them in the same way in your controller action.
No, not really, as they all rely on ViewState and a lot of the web forms plumbing. As to why they appear, I'd guess it's because you're on VS2008 and MS hadn't got a good way of telling one aspx page from another.
Best method to add/remove webcontrols or user controls in asp.net for dynamic forms without postback
Try using ASP.NET Ajax, although technically this is a postback, yet it doesn't (really) feel like one for the end-user.
If that is also not allowed, you can just add html elements using javascript.
We are plannning to use Ajax in our ASP.net project. However, we still want the member panel of our web site to work in all browsers. We have decided not to use Ajax in some forms where browser independence is must.
I am now confused with whether we should use ASP.NET controls or HTML controls or both?
I have two questions:
Are there any problems that I might face using either of approach?
Also which one is better considering efficiency and performance?
The Asp.Net Controls including the ajax controls are independent of browsers, asp.net will detect your browser and try to render the best html/javascript for that browser. So you are good with server controls.
If you are going to implement the project in asp.net then for all the controls that need to be accessed via code at server side needs to be asp.net controls. Those controls that are static and only displaying some value can be html controls.
The main point is that the asp.net controls are rendered to html controls... so the client who views the web-page actually gets the html controls.
For AJAX refer this
ASP controls and HTML controls as complementary.
ASP controls bring facilities for programming like the viewstate (the control keeps its content after a post back), the binding with datatable, and a lot of presentation properties. It is really an advantage in terms of time and maintainability to use these controls. They also manage some security feature like html code injection. ASP controls could be controled and managed from the code behind page.
HTML controls are out of the native ASP.NET page process. It is sometime a good thing to have particular control that you don't want ASP.NET take in charge and modify, but it is not the core of an ASP.NET web application.
If you can use HTML - it is always better - as it is much faster.
The use of ASP controls should work on all browsers as far as I know, but it less efficient.
Better create a small example and test it on some browsers before you decide.
(I've used ajax on both explorer and Firefox and it works)
How can we refresh a web user control automatically without a page postback in asp.net 2.0? i have tried meta tags in controls head tag but it also refreshes the whole page.
You could try implementing a little bit of the ASP.NET AJAX Framework into your app and wrapping that control in an UpdatePanel. It will work with .NET 2.0
Edit: Here is a quick link to a tutorial on using the ASP.NET AJAX UpdatePanel: http://ajax.net-tutorials.com/controls/updatepanel-control/
And here is the official introduction page from the ASP.NET website: http://www.asp.net/Ajax/Documentation/Live/tutorials/IntroductionUpdatePanel.aspx
User Controls are server based controls. Your only option might be some type of javascript but depending on what you are try to accomplish, unlikely.
There are several ways to do it and it depends on what your control is made of.
One of the easiest ways to do it is to wrap the control in an UpdatePanel and then use a Timer control to just update that UpdatePanel. But that might be expensive in terms of viewstate.
Another option is to use something like Jquery and a Javascript timer to count down and then refresh using static page Methods (http://encosia.com has examples).