Click here to Skip to main content
Click here to Skip to main content

Tagged as

Use HiddenField Control to store values from javascript function

, 21 Sep 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
To be able to get the value in the PostBack from the ASP.Net TextBox control that assigned by an external javascript function, you have to store the same value also in a HiddenField Control.
 
Then in the PostBack Event you can get the value of the HiddenField Control But not the TextBox Control, because the TextBox Control value will be reseted.
 
Here is an Example:

 
We passed the controls ClientIDs as querystring to the popup window, then from the popup window we have the following javascript to assign the values to the controls in the opener aspx page :
 
window.opener.document.getElementById('<%=Request["lat_ctr_id"]%>').value = marker.getPoint().lat();
 
 window.opener.document.getElementById('<%=Request["ctr_hdn_lat_id"]%>').value = marker.getPoint().lat();
 
Now from my cs file, i have a search button with click event (this will do postback)
 
protected void btn_search_Click(object sender, EventArgs e)
   {
       //this will not work.. the "lat" querystring will be empty
       //Response.Redirect("search_results.aspx?lat=" + txt_lat.Text  ) ;

       //this will work.
       Response.Redirect("search_results.aspx?lat=" + hdn_lat.Value);
 

   }
 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

hussain.attiya
Architect Gulf air - Bahrain
Bahrain Bahrain
Current Position is : Information System Analyst
 
Leading a Team of Developers for developing ecommerce websites and systems integration using several integration methods such as XML.
 
Manage ISP infrastructure, web servers, database servers, application servers, email servers and networks. Design the architecture of complex web applications; build web applications in JAVA, asp, asp.Net; manage web sites including networking and database; experienced in MS Sql Server and Oracle;
 
stay current with emerging trends and technological advances in the industry.
 
MCTS,MCAD VB.NET, ASP.NET and XML Services,BTEC National Diploma in Computer Studies.

Comments and Discussions

 
Questionthe cause of the problem Pinmemberhussain.attiya4-Dec-11 1:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.1411023.1 | Last Updated 21 Sep 2010
Article Copyright 2010 by hussain.attiya
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid