Click here to Skip to main content
15,917,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,
This problem is related to my last posted thread How to pass values from one HTML page to other using javascript. I was trying to pass values from one HTML page to another without using code behind. I adopted javascript and than i got the values from first page and showed them in label on second HTML page. Now I want to use those values for further processing. So, I tried fetching the values in the label but it is showing me empty string "". Whether I do it on code behind or try to do this on HTML markup using
ASP.NET
<script runat="server">. 
I am not able to get the values. I tried debugging and it showed empty string. Can anyone guide me where am I going wrong ?

Any help will be highly appreciated !

XML
<form id="form1"  runat="server">
    <asp:Label ID="lbl" runat="server"><br />
    <asp:TextBox ID="Text1" runat="server">

    <asp:Button ID="Button1" runat="server" Text="Button" />
    </form>
    <%--/* javascript starts here*/--%>

    <script language="JavaScript">
function getParams(){
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++){
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
}
}
return params;
}
params = getParams();
firstname = unescape(params["firstname"]);
lastname = unescape(params["lastname"]);
age = unescape(params["age"]);
//document.write("firstname = " + firstname + "<br>");
//document.write("lastname = " + lastname + "<br>");
//document.write("age = " + age + "<br>");
//document.getElementById('<%=lbl.ClientID%>').innerHTML = firstname;

document.forms["form1"].elements["Text1"].value = firstname;


    </script>

</body>
Posted
Updated 16-Aug-12 11:15am
v4
Comments
[no name] 16-Aug-12 7:20am    
may be you use that in (!ispostback)
Taresh Uppal 16-Aug-12 7:34am    
I did still the same result !
ZurdoDev 16-Aug-12 8:03am    
Show the code you are using.
Taresh Uppal 16-Aug-12 8:15am    
<form id="form1" runat="server">
<asp:Label ID="lbl" runat="server"><br />
<asp:TextBox ID="Text1" runat="server">
  
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
<%--/* javascript starts here*/--%>

<script language="JavaScript">
function getParams(){
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++){
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
}
}
return params;
}
params = getParams();
firstname = unescape(params["firstname"]);
lastname = unescape(params["lastname"]);
age = unescape(params["age"]);
//document.write("firstname = " + firstname + "
");
//document.write("lastname = " + lastname + "<br>");
//document.write("age = " + age + "<br>");
//document.getElementById('<%=lbl.ClientID%>').innerHTML = firstname;

document.forms["form1"].elements["Text1"].value = firstname;


</script>

</body>
Taresh Uppal 16-Aug-12 8:15am    
and on page load :

lbl.Text = Convert.ToString(Text1.Text);

1 solution

use documents.formname.getElementById property to yoyr Page
 
Share this answer
 
Comments
Taresh Uppal 17-Aug-12 2:15am    
could you please tel me where to use it ??
Taresh Uppal 17-Aug-12 2:21am    
i dont thnk os there is any property with formname !

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900