Automatically Refresh a web user control - asp.net

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).

Related

Using jQuery-AJAX to page ASP.NET datagrid

Does anyone have, or could point me to, an example of using jQuery to page through an ASP.NET datagrid control?
I would like to page through a large set of data displayed by an ASP.NET DataGrid control however I would like to avoid a page refresh and hence want to use AJAX to get the new sets of data. I would also like to avoid the ASP.NET AJAX toolkit and would like to do it all using jQuery-AJAX. Thank you.
The DataGrid is a server side control that relies on postbacks. jQuery and AJAX are client side technologies. Write a AMSX or WCF service to serve up your data and consume it with jQuery. You can use jQuery templates to make things easier. Or wrap the DataGrid in an UpdatePanel and you will have the poor man's AJAX(sometimes called AJAH).
There may be a jQuery plugin to help with this.
Here's a nice article to get you started:
Easily build powerful client-side AJAX paging, using jQuery
Try using jGrid, it´s free, but there are commercial dotnet implementations available.
It´s quite powerfull,you can do almost everything with it. And loading your data is easy to. But, you have to forget the Idea of aspnet datagrid, unless you will use updatepanel(which is very stable and usefull and has nothing to do wiht asp net ajax toolkit)

ASP.NET (webforms): Using with MINIMAL server controls and substituting with JQUERY?

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.

Ajax in existing asp .net project

I have a web page devoloped in visual studio 2008.
I have 4 dropdowns and a repeater in the page.based on the selection(search criteria) from the dropdowns the repeater value will change.
and one dropdown selection will bind values to the other dropdown also.
Since the page is causing a lot of postback we decided to implement ajax here.
I am yet to learn ajax.
Can anyone tell what is the best way to do this .which ajax control replace dropdowns?
i have already server side code written on all dropdowns.
Please give me a good solution which i can implement in less time and reuse my code.
One more update: i have a master page used in the project.
I am using update panel of ajax which does not work if i use master page.
(That means all the dropdown controls and repeater i put it in update panel.But still page postback occurs.)
In a normal page(without master page) it works? why is this happening?
Thanks
SNA
You are able to use UpdatePanel and place dropdowns inside it.
Your solution will depend on the AJAX framework you choose, but here are cascading dropdown examples in ASP.NET AJAX and jQuery
If your main reason for using AJAX is to remove the number of postbacks you are getting, then I would recommend against using Microsoft's built in solution, e.g updatepanels.
The learning curve will be higher but learn to use jQuery, maybe with a little help from jTemplate to help you build your drop downs on the page.
Using updatepanels will not reduce your postbacks as behind the scenes asp.net is doing a full page life-cycle, sending all content back to your client but only updating the update panel. jQuery will be far more efficient. (and the reason I use it!!)
Update
If you don't believe me, see... Why Update Panels are dangerous
Update #2
If you don't want to go the whole way of learning Ajax just yet (although I'd recommend it) you could always pre-load your page with all the possible drop down combinations and then swap them using javascript / javascript + jQuery.
Here is one example of how you may do it -- use jQuery for dependent drop down combos
Using this method you are more likely to be able to save the code you've already written to work out the drop down options.

How can I emulate the ASP.NET Ajax UpdatePanel when using ASP.NET MVC?

In "traditional" ASP.NET (Web Forms), the UpdatePanel control lets you do a partial refresh of a part of a page. You don't need to write much code to hook this up.
What's the equivalent in ASP.NET MVC? I'm guessing I'd need to use a partial view for the bit that I want to update, then on the client side retrieve that HTML and pump it into the innerHtml of the correct DIV?
A tutorial/example would be helpful...
A quick google with your tags throws up a bunch. This is pretty good:
http://www.iridescence.no/post/Partial-Rendering-with-ASPNET-MVC-and-jQuery.aspx
And yes, you're just calling a controller to return rendered HTML which you then inject. Much lighter than the updatepanel and almost as easy to implement.
Have a look at Superload. I think it's the closest thing to the update panel that I've seen for asp.net mvc. Otherwise you can use jquery ajax, .load() or .get(), to update any parts of the page or divs. You just have to manually set the parameters as needed.

Avoid ASP.NET postbacks

How to Avoid ASP.NET postbacks?
Use AJAX, UpdatePanels, JQuery:
http://www.asp.net/ajax/ should give you a good start.
Asp.NET is entirely based on Postbacks.
May be are you looking for partial page rendering and client side stuffs. If this is the case, you can have a look at Asp.NET Ajax.
Try using html controls if you want to avoid postbacks. ie., it doesn't post back to the server.
What is your exact requirement? You don't want to postback the control or you don't want to feel the postback of a page. If so, you can go for UpdatePanel in asp.net ajax and try using Conditional Update.
Try using Asp.net MVC3 or MVC4 People tend to prefer MVC to webforms

Resources