Hidden Fields

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
 
C

Cowboy \(Gregory A. Beamer\)

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top