How to call a server side function on Leave event of a ASP.Net TextBox - asp.net

I am building a user registration form in asp.net. I want to check if the username is available or not on the leave event of the TextBox. I am not able to get the Leave Event of the TextBox.
Should I use OnBlur event of the Html TextBox.
Please Help.

How about using TextChanged server-side event and wrapping the whole thing in an UpdatePanel for very quick ajax functionality.
If you use this method make sure the AutoPostBack property is set to true for the TextBox control.

Related

Textbox textChanged event withount enabling postback

I have webpage with many textboxes. I want to call a function (CalcBalance) on TextBox_TextChanged event. This works well with textbox's Postback set to true, but this makes the app not to be user friendly because when the user scrolls down to use other textboxes, the "postback" keeps taking the user to the top of the page. i.e. the user will have to scroll down after changing the text in any textbox.
Is there any way I can call this function without enabling postback?
Thanks to Tim Schmelter. The easiest way was to put this line:
MaintainScrollPositionOnPostBack = "true" in the function (CalcBalance).

How to load user controls dynamically in ASP.NET without postback

I have a ASP.Net(C#) page. When a user selects a value in dropdownlist, some new controls will be visible to him.
I am able to that now, but the page has to reload every time and state has to be maintained between postbacks.
Is there any way to do the same without reloading of the page in a easiest way possible without using ajax control toolkit?
Additional info: the data for the dropdownlist is coming from the database, and some places it has to be all server side so i can't use javascript .
You can try this idea: http://msdn.microsoft.com/en-us/library/ms178208(v=vs.100).aspx. I have not try it before but it seems logical.
you should go through updatepanel. Put all the controls inside a updatepanel which you want to show on selectedindexchanged event of the dropdownlist and write code behind on selectedindexchanged event of the dropdownlist accordingly. Hope this will help you...

TextBox keydown event at server side in asp.net

i have a textbox on a page, now whenever any age number is entered in that page, that page should be loaded in my datalist, i have created rest of the thing, but i am not getting how to trigger the textbox onkeydown event from asp.net, i know working with that from javascript, but the problem is i have below things done in that function:
it applies the currentpage value to the static variable from textbox
it binds the datalist
it enable disable the next previous buttons accordingly
and i dont think this i can do from javascript, anyone have any resolution, how this could be achieved from server side, onkeydown event
You can capture the keydown event in a javascript function then do a AJAX call to the server. If this does not suit you, then you could try manually do postback in javascript.
So in your textbox:
mytextBox.Attributes.Add("onkeydown", "return doDataListBind()");
Now in the javascript function:
function doDataListBind()
{
__doPostBack("myTextBox"); // etc, etc
// some other code here...
}
More info can be found here:
http://geekswithblogs.net/mnf/archive/2005/11/04/59081.aspx
http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/
Try looking into or using either:
AJAX Control Toolkit, or
JQuery Autocomplete Plugin
Alternatively you could try to call _postback() function from a client side event/function for your textbox in javascript

Repeater Item Command Causes Validation

I seem to have a bit of a bug, I have a ASP.NET repeater control with a link buttons in it and the link button has the have the causes validation property set to false.
However; when clicking it which makes a panel visible on the web page, the asp.net required field validator controls trigger and shows their error messages. On those controls that I have the validator controls on.
Any ideas as to what might cause it to be ignoring the causes validation property set to false?
On my opinion, you should set different ValidationGroup properties values for repeater control and for control that is the source for required field validator. It is possible that container for repeat control has raised event that can be heared by required field validator.
If mentioned above cannot help then try to disable client validation for RequiredFieldValidator using EnableClientScript="False" for it. And activate RequiredFieldValidator when it really usefull. For example in the some button event handler you can apply such code:
MyButton.Validate();
if (MyButton.IsValid)
{
Do what you want...
}
For anybody that has this problem and stumbles across this post, here's what I found.
Turns out the problem was happening because I had EnableViewState="false" set on the Repeater. This was breaking the event postback somehow, and making every validator on the page fire. All I had to do was manually call DataBind() on the Repeater from within Page_Load(), and it cleared right up.
try to set the visablity of the panel true all the time in design view,, and check the validation again.

ASP.NET Adding OnClick event to asp:DropDownList control

I need to add the OnClick event to asp:DropDownList control, due to the existing events don't satisfy my current needs.
Is it possible to achieve this?
Thank you very much.
What reason do you have for wanting an OnClick event on the DropDownList control? If you were to implement an OnClick server-side event on the DropDownList the user would never be able to select any of the list items. This is because in order to fire a Server-Side OnClick, a postback would be required. I.e. the user would click the DropDownList, a postback would instantly occur and they wouldn't be able to select a value.
It sounds like a case of trying to fix the wrong problem, however you could probably try and use the "onclick" JavaScript attribute and handle whatever you're trying to do using client side script and AJAX?

Resources