简体   繁体   English

从JavaScript控制中获取价值

[英]Get value from JavaScript Control

Just wondering if you guys can help me with something. 只是想知道你们是否可以帮我一些忙。

I have created an input control via java script and am trying to get the value from that control using Page.FindControl in asp but it is not finding the control on the page. 我已经通过Java脚本创建了一个输入控件,并尝试使用asp中的Page.FindControl从该控件中获取值,但是在页面上找不到该控件。

Is it possible to find it this way and I am doing something wrong with ID's for example or should it be done by setting a key in the ViewState, or some other method? 是否可以通过这种方式找到它,例如我在ID方面做错了,还是应该通过在ViewState中设置键或其他方法来完成?

If possible can you give a explanation as to why I cannot find the new control via asp.net Page.FindControl if it isnt as simple as incorrect ID's which im sure it isnt. 如果可能的话,如果它不像不正确的ID一样简单,那我为什么不能通过asp.net Page.FindControl找到新控件呢?

Thanks for any help. 谢谢你的帮助。

Two possible resolutions for this: 两种可能的解决方案:

Use an asp:TextBox instead, in which case you won't even need to use FindControl (in most cases) 请改用asp:TextBox,在这种情况下,您甚至不需要使用FindControl(在大多数情况下)

<!-- .aspx page -->
<asp:TextBox id="TestControl" runat="server" />

and then 接着

// codebehind
string something = TestControl.Text;

or 要么

Use the text input, and find it on the Form (so old fashioned, but works) 使用文本输入,然后在窗体上找到它(老式,但可以使用)

<input id="TestControl" />

and

string something = Page.Request.Form["TestControl"];

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

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