Hidden Fields

  • Thread starter Thread starter Manny
  • Start date Start date
M

Manny

Hello Folks,

I am having an issue with retrieving value of hidden field in the
codebehind. The value of the control is set using Javascript defined in the
Page Load Event. I have tried putting the code in the Page Init to without
any results. Could someone please assist?

Code Snippet:

<input id="hdnTextBoxData" name = "hdnTextBoxData" type="hidden"
runat="server" />

if (!(Page.IsPostBack))
{
try
{
if (Request.QueryString["edit"].Equals("1"))
{
string script = "<script
type=\"text/javascript\">document.form1.hdnTextBoxData.value =
window.opener.document.getElementById('hdnTxt1').value;";
script += " alert(document.form1.hdnTextBoxData.value);";
script += "</" + "script>";

this.Page.ClientScript.RegisterStartupScript(Page.GetType(), "scr", script);

}
}
catch (Exception ex) { }
}

If you review the code, I have one liner with Alert showing the Value of the
Hidden Field which works fine. However when I write
Response.Write(hdnTextBoxData.Value), it returns an empty string.

Thanks

Manny
 
You have to wait until submit to retrieve a value set on client side. It
sounds like you are trying something like this:

if (!(Page.IsPostBack))
{
try
{
if (Request.QueryString["edit"].Equals("1"))
{
string script = "<script
type=\"text/javascript\">document.form1.hdnTextBoxData.value =
window.opener.document.getElementById('hdnTxt1').value;";
script += "
alert(document.form1.hdnTextBoxData.value);";
script += "</" + "script>";

this.Page.ClientScript.RegisterStartupScript(Page.GetType(), "scr", script);

}
}
catch (Exception ex) { }

Response.Write(hdnTextBoxData.Value);
}

I realize it is not here, but somewhere else. But if you are doing this in
Page_Load or some other event, prior to submit, you will not get the value.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
 
Back
Top