How should I bind to my textbox's events? - asp.net

I am populating a textbox (txtFileNature) with a value from a popup window. The textbox has an onfocus handler set to
onfocus=("this.blur();")
The problem is that I want to do some calculations based on the value of txtFileNature and want to display the result below it. In which event can I can use my VB code. I can't use the textchanged event since I am not typing in the textbox.

Use client-side event - Javascript:
http://www.w3schools.com/jsref/jsref_onchange.asp
http://benreichelt.net/blog/2006/03/02/firing-javascript-events-when-textbox-changes/

Depending on the nature of the calculation, you can either do this on the server side or the client side. If the nature of the calculation allows it to be done on the client, you should do your calculation using the onchange client-side event, as fusion wrote in his answer.
If it's a server-side calculation you need, then you have a number of options. I'm assuming you have some client-side event that populates the txtFileNature textbox on the client. You can add to that event to have it trigger an AJAX call or a postback (depending on your application) to get the result of the calculation. Alternatively you can use the onchange client-side event to trigger a postback or AJAX call. Either way, the end result is the same.

Related

can onclient click event update a label

I have an ASP.NET Web Forms page that contains six text box inputs.
When a user tries to submit the form, I want to compare all six inputs to ensure all of the values are unique.
I know I can do this using code behind, but I would prefer to do this client-side. I know i can create a Javascript function to validate the input and cancel the form submission using return validate() on onClientclick.
The onclientclick event needs to:
1 cancel the submission
2 show an error message
Please let me know if this is possible.
I could not find an event handler for onClientclick.
You can't use a normal event handler in code behind because that requires a postback.
Use jQuery for the validation and setting the error message.

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

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?

ASP.NET AJAX: How can I send information to the client from server-side

The page has already run its' initialise/load sequences etc but then catches an event. How can I then send value(s) from this event to the client.
That probably doesn't make much sense, hopefully this will clarify:
I have a grid (Telerik RadGrid) in a user control (A) and when the user selects a row in that grid, I want to update another user control (B) with the selection.
I have wired up an event so that user control B is notified of the newly selected value however setting say a textbox value in user control B server-side isn't rendering (I'm presuming because the grid selection is happening over AJAX and therefore user control B never re-renders?).
So, how can I either force user control B to re-render with the updated values or how can I send these values to the client using an AJAX like call? Or am I going about this the wrong way entirely. The core question really is how can I get data from user control A to user control B when the page isn't being posted back.
Thanks!
There are ways to push data from the server (one is called "long polling") but this does not apply here. Are you sure that your grid event fires and the event handler executes? If you are, and you update control (B) but the change does not appear, put control (B) or both into an asp:UpdatePanel and call the Update() method on it in the event handler after changing the value. This will trigger another Ajax postback that should refresh your control.

How can I trigger a server-side event from a client-side event?

Short version
All I need is that, in a ModalPopUp, when the DoubleClick event of a ListItem fires, the click event of my OK button should be executed.
Detail
I have a ModalPopUpExtender, which hosts a user control. The user control has an OK and a Cancel button. Along with that, it has a dynamic ListBox added to it. So far, I've considered the following possible solutions:
Use Ajax.Net. But, I cannot afford to have a WebMethod.
Use a ClientScriptCallBack. This will need a lot of JavaScript, since I have made almost every control dynamic.
Is there any other way apart from using an UpdatePanel?
Have a look at this way using __doPostback
calling a VB.net function from javascript

Resources