473,795 Members | 2,863 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="hdnTextBoxD ata" name = "hdnTextBoxData " type="hidden"
runat="server" />

if (!(Page.IsPostB ack))
{
try
{
if (Request.QueryS tring["edit"].Equals("1"))
{
string script = "<script
type=\"text/javascript\">do cument.form1.hd nTextBoxData.va lue =
window.opener.d ocument.getElem entById('hdnTxt 1').value;";
script += " alert(document. form1.hdnTextBo xData.value);";
script += "</" + "script>";

this.Page.Clien tScript.Registe rStartupScript( 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 1829
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.IsPostB ack))
{
try
{
if (Request.QueryS tring["edit"].Equals("1"))
{
string script = "<script
type=\"text/javascript\">do cument.form1.hd nTextBoxData.va lue =
window.opener.d ocument.getElem entById('hdnTxt 1').value;";
script += "
alert(document. form1.hdnTextBo xData.value);";
script += "</" + "script>";

this.Page.Clien tScript.Registe rStartupScript( 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***@discussi ons.microsoft.c omwrote in message
news:54******** *************** ***********@mic rosoft.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="hdnTextBoxD ata" name = "hdnTextBoxData " type="hidden"
runat="server" />

if (!(Page.IsPostB ack))
{
try
{
if (Request.QueryS tring["edit"].Equals("1"))
{
string script = "<script
type=\"text/javascript\">do cument.form1.hd nTextBoxData.va lue =
window.opener.d ocument.getElem entById('hdnTxt 1').value;";
script += "
alert(document. form1.hdnTextBo xData.value);";
script += "</" + "script>";

this.Page.Clien tScript.Registe rStartupScript( 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***@discussi ons.microsoft.c oma écrit dans le message de groupe
de discussion : 54************* *************** **...icrosof 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="hdnTextBoxD ata" name = "hdnTextBoxData " type="hidden"
runat="server" />

if (!(Page.IsPostB ack))
{
try
{
if (Request.QueryS tring["edit"].Equals("1"))
{
string script = "<script
type=\"text/javascript\">do cument.form1.hd nTextBoxData.va lue =
window.opener.d ocument.getElem entById('hdnTxt 1').value;";
script += "
alert(document. form1.hdnTextBo xData.value);";
script += "</" + "script>";

this.Page.Clien tScript.Registe rStartupScript( 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
7171
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 fields to carry the data from the previous forms forward. If should bascially work like this: Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 20 Fields 20 Fields 20 Fields 20 Fields 20 Fields 100 Hidden
1
9594
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 same name "junk_array". My first field of junk_array is a input type=hidden. All the others fields in junk_array that follow are type=text. I can reference this first hidden field in IE with document.form.field.value. In, fact my form works...
1
3496
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 large and I want to start reducing the amount of code on each page. Replacing tables with divs are helping some but not as much as I would like. Some pages may have up to 100 different items on it and each one has its own form for submitting the...
1
2222
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 from a db which creates hidden fields populated by prices once the onchange handler fires it sets the text for the text field price and the hidden field Tsize, but I can't get it to set the txt of oldprice from the hidden field prevprice.
9
4236
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 - however my question is, which is more performance effective, or easier on a clients resources? I mean - if I have several <input type=hidden> tags with my values that I can reference, would this have a greater overhead then, for example, having an...
10
3115
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 fields http://www.zoo.co.uk/~mmenterprises/contact.htm I am using FormMail from Matt's Script Archive. The W3C validator objected to the hidden fields unless I put, say, P round them. That gave
8
4289
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 select whether or not to search a given field. In this case it is not practical to have 20 checkboxes (each album can have up to 20 song titles).
5
2925
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 there a way to prevent this, or to reset them to visible=false?
5
2149
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
2352
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 on the page, does some processing, populates the <ASP: hidden fields, and then I need to redirect to another page, where I want access to these fields. I suspect that these have to be inside a form, but figured I should ask. I'd use a Cache or...
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10443
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10216
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10002
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7543
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.