简体   繁体   English

Javascript刷新后如何获取控件值

[英]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.

相关问题 编辑项目后如何刷新列表视图控件? - How to refresh a listview control after editting an item? 回发后获得控制的价值 - Get value of control after postback 如何使用propertymanager刷新Winform控件值? - How to refresh winform control value use propertymanager? 如何在Webbrowser Control上获取JavaScript函数/ Object的返回值 - How to get the return value of a JavaScript function/Object on Webbrowser Control 如何从 webbrowser 控件获取 onclick 中的实际 JavaScript 值? - How to get actual JavaScript value in onclick from webbrowser control? 回发后如何获得动态控件的值? - How Do I Get a Dynamic Control's Value after Postback? 如何使用javascript 1分钟后刷新Repeater? - how to refresh Repeater after 1 minute with javascript? Visual Studio 2017,Asp.net,c#DropDownList控件,如何在选择新值后刷新文本框 - Visual Studio 2017, Asp.net, c# DropDownList Control, How to Refresh Text Boxes After a New Value is Selected 如何在 blazor 中刷新页面重置值后? - How to after refresh page resetting value in blazor? 将数据插入表后,如何刷新GridView控件? - How do I refresh a GridView control after inserting data into the table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM