简体   繁体   English

将值设置为文本框-Ajaxified Aspx

[英]Settings values into TextBox - Ajaxified Aspx

im using AjaxToolKit in aspx, so a cue is how to set values to textbox? 我在aspx中使用AjaxToolKit,所以提示是如何将值设置为文本框? 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" 我正在使用javascript从另一个aspx检索值,所以现在我有了(例如)本地变量的价格之和(在代码背后),并且我想在文本框中使用runat =“ server”设置该值

I have to use jquery or javascript? 我必须使用jquery或javascript吗? with webmethods? 网络方法? how could be that? 怎么可能 thanks 谢谢

I also try this at codebehind : 我也可以在codebehind上尝试:

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

I found some tips for example, that id changes when are in html context, obviously something like 我发现了一些技巧,例如,在html上下文中id会更改,显然是这样的

ctl00_cphMainContent_
how can i tame this? 我该如何驯服?

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) 在后面的页面加载代码中,将文本框的ClientID属性分配给javascript变量(这将允许您使用getElementById方法访问文本框)
  2. Use a PageMethod to retrieve the sum of prices that you want to display in the textbox 使用PageMethod检索要在文本框中显示的价格总和
  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 使用getElementById(步骤1中存储在js变量中的id)获取文本框的句柄,然后将其“值”属性设置为步骤2中PageMethod返回的值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM