Monday, March 26, 2012

Access HiddenField when using Update Panel

Hello,

I have a page that using update panel. I register hiddenfield using ScriptManager.Registerhiddenfield. I want to get the value, but it always failed.

This is the code :

protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = this.Request.Form["__vsKey"];
}

protected void Button1_Click(object sender, EventArgs e)
{
ScriptManager.RegisterHiddenField(this, "__vsKey", "myValue");
}

When I don't use update panel, it's working properly. Do anyone know how to access the value?

Thanks before

What kind of error you are getting ?

To register a hidden field for a control that is inside anUpdatePanel control so that the field is registered only when the panel is updated, use theRegisterHiddenField(Control, String, String) overload of this method. If you are registering a hidden field that does not pertain to partial-page updates and you want to register a hidden field only one time during initial page rendering, use theRegisterHiddenField(String, String) method of theClientScriptManager class.


The problem is I don't get the value from this hiddenfield when using UpdatePanel. It always return null value.

I'm using a button to register the hiddenfield

protected void Button1_Click(object sender, EventArgs e)
{
ScriptManager.RegisterHiddenField(this, "__vsKey", "myValue");
}

And when the page load, a label display the hiddenfield value

protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = this.Request.Form["__vsKey"];
}

But, the label display nothing when I use UpdatePanel.

No comments:

Post a Comment