Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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

publicstaticstringGetValueOfControl(WebControl ServerControl)
    {
        string IdOfControl = ServerControl.UniqueID;
        NameValueCollection PostBackFormControls = HttpContext.Current.Request.Form;
        if (PostBackFormControls.AllKeys.Length == 0)
            returnnull;
        stringvalue = 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];
            elsereturnnull;
        }
        else
        {
            returnvalue;
        }
    }

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

Post a Comment for "How To Get Control Value After Javascript Refresh"