Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
how to send a value with query string in button click...
How to Pass Value of Level1
Here is my Code..
HTML
<script type="text/javascript">
var Demand = function () {
    var Label1 = document.getElementById('Label1').innerText;
    debugger;
    window.open("AddM.aspx?Id=" + Label1, 'Define', 'width=1000,height=600,left=0,top=0,scrollbars=yes,resizable=yes,menubar=yes');
    return false;
}
</script>

Level....>
we get this level value
ASP.NET
<asp:Label ID="Label1" runat="server" Text="Label">


And My button Click...
ASP.NET
<asp:Button ID="AddM" runat="server" Text="Add Medicine" CssClass="nm" 
        onclientclick='return Demand()' 
        >

After run my application the outpur URL is "http://localhost:2193/Web/OutPatient/AddM.aspx?Id=undefined"
Posted
v5
Comments
JoCodes 29-Nov-13 1:56am    
Can see that you already passing regid as querystring to open your popup ? Are you looking to pass multiple query strings? can you make the question clear?
Parmendra choudhary 29-Nov-13 1:59am    
After run my application the outpur URL is "http://localhost:2193/Web/OutPatient/AddM.aspx?Id=undefined"
JoCodes 29-Nov-13 2:20am    
Thats because you are not passing the parameter to your JS method call . Pass the clientid of your label to the calling code and handle the value of the label in the JS function
TrushnaK 29-Nov-13 2:00am    
you havent pass value to javascript Demand(regid) through onclientclick='Demand()'.
Parmendra choudhary 29-Nov-13 2:00am    
sir please tell me how to pass it

Hi Parmendra,

based on my understanding or ur problem i have come with one solution..

i guess it will work for your requirement...

Note these things:

i dont know why you r making the label as invisible.
if it is invisible , it wont render in the browser, then u wont get the value of it...
instead u can use a hidden field to store in the browser...




XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="jquery-1.10.2.min.js" type="text/javascript"></script>
   <script type="text/javascript">

       var Demand = function () {
           var Label1 = document.getElementById('Label1').innerText;
           debugger;
           window.open("AddM.aspx?Id=" + Label1, 'Define', 'width=1000,height=600,left=0,top=0,scrollbars=yes,resizable=yes,menubar=yes');
           return false;
       }


    </script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Label ID="Label1" runat="server" Text="12313322" Visible="true" />
    <br />
     <asp:Button ID="AddM" runat="server" Text="Add Medicine" CssClass="nm"
        onclientclick='return Demand()'   />
    </form>
</body>
</html>
 
Share this answer
 
Comments
Parmendra choudhary 29-Nov-13 2:21am    
its not correct solution
Parmendra choudhary 29-Nov-13 2:23am    
same problem
Karthik_Mahalingam 29-Nov-13 5:06am    
y u need to call javascript from code behind ??
y making complicated ???
Parmendra choudhary 29-Nov-13 5:10am    
Any one can help me
Karthik_Mahalingam 29-Nov-13 5:17am    
Please explain me your task in details..

i wil give u a clear solution...


instead of doing a single line chatting.. u can give the detailed requirement of your task...

we will give u a solution..

we are here to help one another..

Problem

1. You have set Visible = "false" for that Label. So, it will not render on Browser. Instead do style = "display:none;".
ASP.NET
<asp:Label ID="Label1" runat="server" Text="Label" style="display:none;"></asp:Label>

Now, it will render but will be hided. So, you can get its value.

2. You are not sending any value on function call inside the Button onclientclick='Demand()'. But you are reading the parameter regid, which will always by undefined.
As you are trying to read the Label's value, so don't pass any parameter. Directly read its value in function like below...
XML
<script type ="text/javascript">
function Demand() {
    var regid = document.getElementById('Label1').innerText;
 
    window.open("AddM.aspx?Id=" + regid, 'Define', 'width=1000,height=600,left=0,top=0,scrollbars=yes,resizable=yes,menubar=yes');
}
</script>
 
Share this answer
 
v2
Comments
Parmendra choudhary 29-Nov-13 2:34am    
same error............

URL=http://localhost:2193/Web/OutPatient/AddM.aspx?Id=undefined
Can you debug and see what is the value of regid inside the function.

Just do like below...

function Demand() {
debugger;
var regid = document.getElementById('Label1').innerText;

window.open("AddM.aspx?Id=" + regid, 'Define', 'width=1000,height=600,left=0,top=0,scrollbars=yes,resizable=yes,menubar=yes');
}
Parmendra choudhary 29-Nov-13 4:29am    
no solution same error
http://localhost:2193/Web/OutPatient/AddM.aspx?Id=undefined
I am asking- what is the value of Label when you hit the debugger.
Parmendra choudhary 29-Nov-13 5:34am    
when debugger go there the value show is undefined
try it this is run on my side:-

XML
<head id="Head1" runat="server">
    <script type="text/javascript">
       var Demand = function () {
           var regId = document.getElementById('Label1').innerText;
           debugger;
           window.open("AddM.aspx?Id=" + regId, 'Define', 'width=1000,height=600,left=0,top=0,scrollbars=yes,resizable=yes,menubar=yes');
           return false;
       }

    </script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Label ID="Label1" runat="server" Text="12313322" Visible="true" />
    <br />
     <asp:Button ID="AddM" runat="server" Text="Add Medicine" CssClass="nm"
        onclientclick='return Demand()'   />
    </form>
</body>
</html>
 
Share this answer
 
Comments
Parmendra choudhary 29-Nov-13 4:27am    
http://localhost:2193/Web/OutPatient/AddM.aspx?Id=undefined
Parmendra choudhary 29-Nov-13 4:28am    
How to show this type of value
TrushnaK 29-Nov-13 4:40am    
see your label declaration. <asp:Label ID="Label1" runat="server" Text="Label">
and see my label declaration. <asp:Label ID="Label1" runat="server" Text="12313322" Visible="true" />.
Parmendra choudhary 29-Nov-13 5:30am    
no problem bro its same problem
TrushnaK 29-Nov-13 6:32am    
how it dosent work for you.
i have tested it gives result like http://localhost:4093/WebSite9/AddM.aspx?Id=12313322. in url
Instead of using InnerHtml Use value Property of control in your js function
try this hope this will help you

XML
<script type="text/javascript">
var Demand = function () {
    var Label1 = document.getElementById('Label1').value;
    debugger;
    window.open("AddM.aspx?Id=" + Label1, 'Define', 'width=1000,height=600,left=0,top=0,scrollbars=yes,resizable=yes,menubar=yes');
    return false;
}
</script>
 
Share this answer
 
Please follow below code it might be help to you.
This will work if you use JQUERY


ASP.NET
<asp:label id="Label1" runat="server" text="Label" style="display:none;" />


XML
<script type ="text/javascript">
    function Demand() {
        var regid = $('#<%=Label1.ClientID%>').html();
        window.open("AddM.aspx?Id=" + regid, 'Define', 'width=1000,height=600,left=0,top=0,scrollbars=yes,resizable=yes,menubar=yes');
    }
</script>
 
Share this answer
 
v3

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