Wednesday, March 23, 2011

Settings values into TextBox - Ajaxified Aspx

Hi there, im using AjaxToolKit in aspx, so a cue is how to set values to textbox? i was using javascript to retrieve values from another aspx, so now i have (for example) a sum of prices in a local var (in codebehind) and i want to set that value in a TextBox with runat="server"

I have to use jquery or javascript? with webmethods? how could be that? thanks

I also try this at codebehind :

((TextBox)FindControl("txtTotalAmount")).Text = total;

I found some tips for example, that id changes when are in html context, obviously something like

ctl00_cphMainContent_
how can i tame this?

From stackoverflow
  • You can try the following steps :

    1. In the page load code behind, assign the ClientID property of the textbox to a javascript variable (this will allow you to access the textbox using the getElementById method)
    2. Use a PageMethod to retrieve the sum of prices that you want to display in the textbox
    3. Use getElementById(id stored in js variable in step 1) to get a handle of the textbox and then set its "value" attribute to the value returned by the PageMethod in step 2

0 comments:

Post a Comment