[英]How to get control value after Javascript refresh
I have a page that has a popup modal window and the modal returns a value to the page and then refreshes it. 我有一个具有弹出模式窗口的页面,该模式向页面返回一个值,然后刷新它。 I need to be able to get the value in the code-behind of the page when it is refreshed but the value of the text-box control that it is returned to is always ""
after refresh. 刷新时,我需要能够获取页面代码背后的值,但刷新后返回的文本框控件的值始终为""
。
How can I get the value of the one I returned using JS? 如何获得使用JS返回的那张价值?
The code is added at a test at the moment as I try to get the value of the textbox which has contents before it is refreshed. 当我尝试获取包含在刷新之前具有内容的文本框的值时,此代码是在测试时添加的。
protected void Page_Load(object sender, EventArgs e) {
TranslatePage.ObjectsSetup(Page.Controls, 3);
GetUserInfo();
if (txtCustomerType.Text != "" && txtCustomerType.Text != lblTempCustType.Text) {
SearchCustType(txtCustomerType.Text);
}
SetupControls();
string test;
test = txtCustomerType.Text;
}
I had similar situation but in my case i had DropDown list box which is getting filled with javascript. 我有类似的情况,但在我的情况下,我有DropDown列表框,里面装满了javascript。 So to get the selected value after the javascript has been fired to fill the dropdown list, i have used one additional method the get value which is 因此,要在触发javascript来填充下拉列表后获取选定的值,我已经使用了另一种方法来获取值,即
public static string GetValueOfControl(WebControl ServerControl)
{
string IdOfControl = ServerControl.UniqueID;
NameValueCollection PostBackFormControls = HttpContext.Current.Request.Form;
if (PostBackFormControls.AllKeys.Length == 0)
return null;
string value = PostBackFormControls[IdOfControl];
if (value == null)
{
int index = 0;
for (; index < PostBackFormControls.AllKeys.Length; index++)
if (PostBackFormControls.AllKeys[index].EndsWith(IdOfControl))
break;
if (index < PostBackFormControls.AllKeys.Length)
return PostBackFormControls[index];
else
return null;
}
else
{
return value;
}
}
and to get the value I used 并获得我使用的价值
string District = Convert.ToString(GetValueOfControl(dropDownListBoxDistrict));
So, all u need to do is to add the method and pass your text box to get its value as, 因此,您要做的就是添加方法并传递您的文本框以获取其值,
string test = Convert.ToString(GetValueOfControl(txtCustomerType));
I am sure, it will work for u 我敢肯定,它将为您工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.