473,320 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Hidden Fields

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').v alue;";
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
Aug 21 '08 #1
2 1810
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').v alue;";
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! |
********************************************
"Manny" <Ma***@discussions.microsoft.comwrote in message
news:54**********************************@microsof t.com...
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').v alue;";
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
Aug 21 '08 #2
This is expected. An ASPX page (server side) does nothing else than
*generating* the content of an HTML page and once done this is the browser
(client side) that will display this page running possibly embedded
JavaScript code...

--
Patrice

"Manny" <Ma***@discussions.microsoft.coma écrit dans le message de groupe
de discussion : 54**********************************@microsoft.com...
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').v alue;";
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

Aug 21 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ryann | last post by:
Hello. I am creating a form that has 5 steps/pages. Each page contains about 20 fields. But I don't want to write them until they submit on the last page. I figured out that I can use hidden...
1
by: mark.reichman | last post by:
First off.. Thanks to Grant Wagner for help in a previous thread related to this one. I am at a total loss... I have multiple fields in a form with the same name. Lets call the fields with the...
1
by: Sam Wuebben | last post by:
I would like to add a few hidden field values to a form as it is submited via JavaScript. I have a static page shopping site that uses MIVA shopping cart. Some of the pages are getting quite...
1
by: Roy Adams | last post by:
Hi Group I'm trying to write from dynamically created hidden fields to a txt field in the onchange event handler within a select. basically the number for the for loop is generated by a field...
9
by: Randell D. | last post by:
Folks, I have a large amount of values to store (we're talking tens, if not hundreds of bytes). I need this for a client side application - ignore the security consequences for the moment -...
10
by: Mark McLellan | last post by:
Dear all Following the oft-repeated advice here and ciwas I have made my site nearly 4.01 strict (working on it). There are some items on which I would appreciate your advice: 1. Hidden...
8
by: John | last post by:
Hello. I have a search form for music albums which among other things I need to search all the song titles of the song. Normally in a search form I would have checkboxes the user can use to...
5
by: NTE | last post by:
Access 2000, My application has a main form that the users interact with. There are 2 hidden fields. When they select "filter by form" from the menu, the hidden fields become visble. Is...
5
by: Roshawn Dawson | last post by:
Hi, Are hidden fields passed in the querystring when a form is posted back? If they are, must the hidden fields be server controls in order to access them from .net code? Thanks, Roshawn
5
by: HockeyFan | last post by:
I know that <input type="hidden" fields are used within a form, but do <ASP:HiddenField s have to be in a form to be used? I've got a VB-based (codebehind) that catches the click event of a button...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.