Hi Xenophon,
From the page code you provided, you're dynamically creating the Html
HIdden field, is that any particular requirement on this? Does the problem
occurs if you statically declare the html field in your aspx page and
access it in serverside code?
If anything I missed, please feel free to post here.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| NNTP-Posting-Date: Tue, 20 Dec 2005 14:18:26 -0600
| From: xenophon <xe******@onlin e.nospam>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| Subject: Hidden Form Field Value not Persisting
| Date: Tue, 20 Dec 2005 15:16:23 -0500
| Message-ID: <3k************ *************** *****@4ax.com>
| X-Newsreader: Forte Agent 2.0/32.646
| MIME-Version: 1.0
| Content-Type: text/plain; charset=us-ascii
| Content-Transfer-Encoding: 7bit
| Lines: 85
| X-Trace:
sv3-qHwXBgvFXR7+wu6 dOhPZUShiRIglaJ n2UPJpQrDaYnlP3 leoAjxHrHWvEeFB kDok2LlbsdUB
NZeR4Xu!o6IhmE6 ApxZidxcw7lkpQ8 UNUuPqQ8jTF63Dr mMlUSg2pKtQVAec guU3+ctoo1Oz1Sk W
5kg=
| X-Complaints-To:
ab***@giganews. com
| X-DMCA-Notifications:
http://www.giganews.com/info/dmca.html
| X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
| X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your
complaint properly
| X-Postfilter: 1.3.32
| Path:
TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!ne wsfeed00.sul.t-online.de!t-onli
ne.de!border2.n ntp.dca.giganew s.com!border1.n ntp.dca.giganew s.com!nntp.giga n
ews.com!local01 .nntp.dca.gigan ews.com!news.gi ganews.com.POST ED!not-for-mail
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3660 86
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
|
|
| I added a Hidden Form Field to a form in the code behind.
| The value is being set in JavaScript client-side, but it is not
| persisting to the server in the PostBack.
| I know the value is being set properly because it displays in the
| document.write method.
|
| Create a simple page and paste the below in the code-behind (ASP.NET
| 1.1-SP1)
|
| using System;
| using System.Collecti ons;
| using System.Componen tModel;
| using System.Data;
| using System.Drawing;
| using System.Web;
| using System.Web.Sess ionState;
| using System.Web.UI;
| using System.Web.UI.W ebControls;
| using System.Web.UI.H tmlControls;
|
|
| public class WebForm1 : System.Web.UI.P age
| {
| protected System.Web.UI.W ebControls.Link Button linkButton;
| protected System.Web.UI.H tmlControls.Htm lInputHidden hdfGmt;
|
| private void Page_Load(objec t sender, System.EventArg s e)
| {
| HtmlForm thisForm =
| (HtmlForm)this. FindControl("We bForm1");
| linkButton = new LinkButton();
| linkButton.Text = "click";
| linkButton.Clic k += new
| EventHandler(li nkButton_Click) ;
| HtmlInputHidden hdfGmt =
| (HtmlInputHidde n)thisForm.Find Control("hdfGmt ");
| if ( hdfGmt == null )
| {
| hdfGmt = new HtmlInputHidden (); // This line
| always runs. It should only run once.
| hdfGmt.ID = "hdfGmt";
| hdfGmt.Name = "hdfGmt";
| hdfGmt.Value = "0";
| hdfGmt.EnableVi ewState = true;
| LiteralControl litGmt = new LiteralControl( );
| litGmt.ID = "litGmt";
| litGmt.Text = @"
| <SCRIPT Language=""Java Script"">
| <!-- hide from old browsers
| var curDateTime = new Date()
| document.xxxxxx .hdfGmt.value=(-(curDateTime.ge tTimezoneOffset ()/60))
| document.write( document.xxxxxx .hdfGmt.value)
| //-->
| </SCRIPT>";
| litGmt.Text =
| litGmt.Text.Rep lace("xxxxxx",t hisForm.Name);
| thisForm.Contro ls.Add( linkButton );
| thisForm.Contro ls.Add( hdfGmt );
| thisForm.Contro ls.Add( litGmt );
| }
| }
| override protected void OnInit(EventArg s e)
| {
| InitializeCompo nent();
| base.OnInit(e);
| }
| private void InitializeCompo nent()
| {
| this.Load += new System.EventHan dler(this.Page_ Load);
| }
| private void linkButton_Clic k(object sender, System.EventArg s
| e)
| {
| }
| }
|
|
|
|
|
|
|
|
|