Validating a textbox with AJAX Toolkit in ASP.NET - asp.net

I'm not really sure where or what to search for regarding the following question:
I have a TextBox control and a Label control on my page. I have a database query ready and I would like to run it on the TextBox textchanged event in order to display a "valid" or "not valid" text in the Label.
How can I achieve this without posting back the entire page on each textchanged event? I have installed the AJAX Control Toolkit and got the samples working but I don't seem to find an extender that would fit the bill. Any tips? Much appreciated, thank you.

Firstly, move away from the AjaxControlToolkit. This is for lazy web developers who dont know what they are doing.
Secondly, check out jQuery Ajax. Learn how to use it properly in order to do what you are needing to do.
Basically what you will need to do is post via jQuery Ajax to your page/webservice in order to run the database query. You can then return your data to the page and update the UI.
http://api.jquery.com/jQuery.ajax/

Related

ASP.NET: How can I show a loading image when my page performs stored procedure?

I have a page I'm working on and it works correctly in the sense that I press a button and it executes a stored procedure. The problem is the stored procedure takes awhile to complete, and I want the user to know that there is progress being made and that it's not stuck. So is there a good method to give the user some idea of the progress being made? I was going to just simply display an animated gif, but not sure how to do this. Or if there is a more preferred way to do this I'm all ears. Thanks!
Generally it is a bad idea to have a website command take time, but when you have to Microsoft have an Ajax library which works with ASP.Net - this includes a Progress bar control which can appear when you are doing a long task
The site for the ASP.Net Ajax can be found here; http://www.asp.net/ajax
The Ajax Control Toolkit which includes the progress indicator is here; http://www.asp.net/ajaxlibrary/act.ashx
If you do an AJAX call you can use jQuery to show a loading graphic. See this post How to show loading spinner in jQuery?
Yes, you can definitely use an animated .gif to display to the user while the stored procedure is executing. You'll want to use ASP.NET AJAX to accomplish this, specifically using UpdatePanel and UpdateProgress controls.
View the following URL which guides you on implementing the UpdateProgress control: http://www.asp.net/AJAX/Documentation/Live/mref/T_System_Web_UI_UpdateProgress.aspx
The section on "Specifying the Content of the UpdateProgress Control" talks about using the ProgressTemplate to show an animated image that notifies the user of the progress on the page.
--Tyler

How do I make my ASP.net control perform a postback?

I'm writing my first ASP.net control. I would like to know to know how to make the control postback when the user clicks something (but in general, I want to know how to make arbitrary events make the control postback).
Update Thanks for the answer. However, upon more Googling, it sounds like I'm supposed to make my control call a JavaScript function called __doPostBack. It says that I'm supposed to pass __doPostBack the UniqueID of the control.
You implement IPostBackEventHandler. The linked MSDN page includes a code example.

JQuery with asp.net 3.5 and doing post/call backs

I currently have a simple form that when you click the "save" button will persist it to the database.
I would like to use JQuery to do the callback for me and popup a "Save completed" div window/div of some sort.
My only problem is how do I call the btnSave_Click() event from JQuery?
If I use PageMethods the method would have to be static and therefore lose access to my textboxes and other page controls?
Thanks,
Goosey
Are you explicitly trying to avoid passing the values of the input controls? because that would be much easier.
Using a lightweight jQuery call to do the post but then expecting a full control hierarchy in the code behind to pull data out? What's the intent here? If you require that, it would probably be easier just to submit the page, and register javascript to run to pop the success message up on load.
Personally, I think the page method route and $.ajax or $.post is a much cleaner, separate way to solve the issue. That way you can just show the popup as part of the success callback.
You can use onClientClick
Have a look at the jQuery Form Plugin, it can change existing forms into Ajax forms.
You need to set __EVENTTARGET to the id of the control that you want to simulate causing the postback if you want to use the same handler. I seem to recall having to replace the underscores with dollar signs as well, but I could be wrong on that. The hidden inputs, __EVENTTARGET and __EVENTARGUMENT, are used by the framework to identify which control caused the postback. There's a nice discussion of the server side issues in this blog post, though it doesn't talk about AJAX. Google for __EVENTTARGET and postback for more info.

ASP.NET AJAX modal popup framework

I'm using ASP.NET 3.5 + Ajax Control Toolkit + jQuery (NO MVC yet)
I'm looking for a standard solution for showing a user control (.ascx) as a modal popup (like the Ajax Control Toolkit ModalPopupExtender implementation), where I can pass parameters to it before it opens. Then get some values on closing, and potentially handle events on the server.
I'm currently using a combination of the ModalPopupExtender and update panel to implement this each time I need it. It seems like it takes too much plumbing that has to be created each time.
Before creating my own packaged solution, I'm looking for an existing solution, or for a better pattern to implement this.
I've always set a hidden field value on clientside. My modalpopups data would have parameters that would come from that hidden field. This works great when you update the updatepanel.
function setfield(v) {
document.getElementById('<%=HiddenField2.ClientID%>').value = v;
}
But maybe this solution isn't a best-practice.
It didn't take me too much time to do this. Let me dig up my own implementation.
EDIT:
In it's simplest form, this is what I used. I could drop this into a UserControl and then drop that in any page I wished to use it.
Trying to self contain pop ups which use the AjaxToolkit ModalPopUpExtender
Not sure if this is the part you're wrestling with though.

How do I refresh an ASP.NET ListView using jQuery and AJAX?

I have a page with a number of ListViews that I want users to be able to sort and page through. Rather than postback and rebind the entire page each time, I would like to do it via jQuery/AJAX selectively for the control in question. I am comfortable making the client-side call to a WebMethod in my page - my question is how do I get the returned data back into the ListView via jQuery?
(Note: I don't want to use an UpdatePanel!)
I'm not sure if it'll actually be achievable to update a ListView without a postback, just because of the underlying data model of the ListView control.
You're best option to having a complete AJAX solution would be to use a JavaScript templating engine. I've done a demo on my blog using jTemplates and the MS AJAX Library v4 preview - http://www.aaron-powell.com/blog.aspx?id=1209
But despite common belief you can use an UpdatePanel and have it efficient, I also looked at that here: http://www.aaron-powell.com/blog.aspx?id=1195. The biggest thing to keep in mind when using UpdatePanels is ViewState. If you don't need ViewState saved on a control make sure it's turned off. You can really reduce your post-load by doing that. Also removing whitespace will help.

Resources