ASP.NET, Javascript value modification problem 1

ASP.NET, Javascript value modification problem 1

February 20th, 2006 // 4:02 pm @

While solving one particular case in a SharePoint webpart, I came across a very queer problem in ASP.NET Postback and Viewstate handling. Let me declare the scenario in detail :


I have a page A which has some values in hidden variables of type HtmlControls.HtmlInputHidden.


I popup a page B from page A using javascript window.open. Page B has a button called Send Mail which would send a mail to some recipients. The recipients list has to come from page A.


The standard way of passing data from one window to a javascript popup is querystring, but that is something which is not wanted. It has to work without querystring data passing, and as it is in SharePoint sessions are disabled by default, and hence passing by session is also not an option.


So the only option, is to keep a few hidden variables in page B, read the values from page A using window.opener from Javascript in page B, set the values of the hidden variables in page B, and then on click on Send Mail, access the hidden variables and send a mail using ASP.NET.


The funny problem, is that I can read the values from page A, using javascript. I can also set the values to the hidden variables ( verified by using and alert and checking the value of the hidden variable after it is set ), but as soon as I click Send Message, and try to access the value of the hidden variables from the backend ASP.NET code, the values set using Javascript are lost. On examination, the Viewstate seems to ignore the changes made to the Javascript, if the controls are hidden and does not pass it to the backend.


If the controls are like ASP.NET Textboxes, it works properly, but if they are hidden, again the same problem as above occurs. So definitely it not something exclusive for non .NET Controls.


More on this later on how I solved it when I take my next break :)


Posted on DotNetJunkies at Tuesday, November 09, 2004 1:12 PM


Category : dotNet

2 Comments → “ASP.NET, Javascript value modification problem 1”


  1. http://

    5 years ago

    Please help me out of this situation. I am also facing the datalose on postback.


  2. Amar Galla

    5 years ago

    Check my other post : http://amargalla.com/blog/?p=14

    It contains the required solution.


Leave a Reply

Latest Posts

Testimonials

"Amar clearly has a thorough knowledge of Sharepoint, this knowledge, coupled with his professionalism and dedication made him a tremendous asset to the project. He was the key contributor to the later stages of the project delivery effort (the really difficult bit, long hours and hard work that puts huge demands on people), and I can state categorically that without his focussed dedication and hard work we would not have been able to meet the timescales imposed upon the project."

Tim Ellis , Sharepoint Project Manager , Royal Bank of Scotland

Subscribe Now