如何获取JavaScript刷新后的控制值 [英] How to get control value after Javascript refresh
问题描述
我有了一个弹出模式窗口页面,模态返回一个值到页面,然后刷新它。我需要能够获得页面的code-背后的价值被刷新,但它返回到文本框控件的值总是,时code>刷新之后。
我怎样才能得到我使用JS返回的值?
在code在目前的测试加入我试图让有内容是刷新之前的文本框的值。
保护无效的Page_Load(对象发件人,EventArgs的发送){
TranslatePage.ObjectsSetup(Page.Controls,3);
GetUserInfo();
如果(txtCustomerType.Text =与&!&安培;!txtCustomerType.Text = lblTempCustType.Text){
SearchCustType(txtCustomerType.Text);
}
SetupControls();
字符串的测试;
测试= txtCustomerType.Text;
}
我有类似的情况,但在我的情况,我有这是越来越充满了JavaScript的下拉列表框。 JavaScript已被炒到填充下拉列表后,因此,要获得所选择的价值,我已经使用了一个额外的方法的get值,它是
公共静态字符串GetValueOfControl(WebControl的ServerControl)
{
字符串IdOfControl = ServerControl.UniqueID;
NameValueCollection中PostBackFormControls = HttpContext.Current.Request.Form;
如果(PostBackFormControls.AllKeys.Length == 0)
返回null;
字符串值= PostBackFormControls [IdOfControl]
如果(价值== NULL)
{
INT索引= 0;
对于(;指数< PostBackFormControls.AllKeys.Length;指数++)
如果(PostBackFormControls.AllKeys [指数] .EndsWith(IdOfControl))
打破;
如果(指数< PostBackFormControls.AllKeys.Length)
返回PostBackFormControls [指数]
其他
返回null;
}
其他
{
返回值;
}
}
和得到我使用的值
串区= Convert.ToString(GetValueOfControl(dropDownListBoxDistrict));
所以,所有的u需要做的就是添加的方法,并通过文本框来获取其价值,
字符串测试= Convert.ToString(GetValueOfControl(txtCustomerType));
我相信,它将为ü工作
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?
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. 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
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
这篇关于如何获取JavaScript刷新后的控制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!