Click here to Skip to main content
13,298,551 members (56,632 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


Posted 21 Sep 2010

Use HiddenField Control to store values from javascript function

, 21 Sep 2010
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);



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


About the Author

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.

You may also be interested in...


Comments and Discussions

Questionthe cause of the problem Pin
hussain.attiya4-Dec-11 1:50
memberhussain.attiya4-Dec-11 1:50 

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

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

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