如何在按钮单击中使用查询字符串发送值 [英] how to send a value with query string in button click

查看:53
本文介绍了如何在按钮单击中使用查询字符串发送值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在按钮点击中发送带有查询字符串的值...

如何传递Level1的值

这是我的代码..

 <   script  < span class =code-attribute>   type   =  text / javascript >  
var 需求= < span class =code-keyword> function (){
var Label1 = document .getElementById(' Label1')。innerText;
调试器;
window .open( AddM.aspx ?Id = + Label1,' 定义'' width = 1000,height = 600,left = 0,top = 0,scrollbars = yes,resizable = yes,menubar = yes' );
return false ;
}
< / 脚本 >



等级....>

我们得到这个级别值

 <   asp:标签    ID   =  Label1    runat   =  server   文字  = 标签 >  





和我的按钮点击...

 <   asp:按钮    ID   =   AddM    runat   =  server   文字  = 添加医学    CssClass   =  nm     

onclientclick =' 返回Demand()'

< span class =code-attribute> >



运行我的应用程序后,outpur URL为http:// localhost:2193 / Web / OutPatient / AddM.aspx?Id = undefined

解决方案

嗨Parmendra,



基于我的理解或你的问题我已经有了一个解决方案..



i猜它会对你的需求有效irement ...



请注意以下事项:



i不知道为什么你让标签看不见。

如果它是隐形的,它不会在浏览器中呈现,那么你就不会得到它的价值......

而不是你可以使用一个隐藏的字段来存储浏览器...









 <   html     xmlns   =  http://www.w3.org/1999 / xhtml >  
< head runat = server >
< ; < span class =code-leadattribute> script src = jquery-1.10.2.min.js 类型 = text / javascript > < / script >
< script 类型 = text / javascript >

var Demand = function(){
var Label1 = document.getElementById( '的Label1')的innerText。
调试器;
window.open(AddM.aspx?Id =+ Label1,'Define','width = 1000,height = 600,left = 0,top = 0,scrollbars = yes,resizable = yes,menubar =是');
返回false;
}


< / script < span class =code-keyword>>
< title > < / title >
< / head >
< body >
< 表格 id = form1 runat = 服务器 >
< asp:标签 ID = Label1 runat = server 文本 = 12313322 可见 = true / >
< br / >
< asp:按钮 ID = AddM runat = server 文本 = 添加药物 CssClass = nm

onclientclick =' 返回Demand()' < span class =code-attribute> / >
< / form >
< / body >
< / html >


问题



1哟你为那个标签设置了 Visible =false。因此,它不会在浏览器上呈现。而是 style =display:none;

  <   asp:标签    ID   =  Label1    runat   =  server   文字  = 标签   样式  =  display:none; >  <   / asp:标签 >  



现在,它将呈现但将会呈现墙根。所以,你可以得到它的价值。



2.你没有在Button onclientclick ='Demand()中的函数调用上发送任何值。但是你正在读取参数 regid ,这将始终是未定义的。

当你试图读取Label的值时,所以不要通过任何参数。直接在下面的函数中读取它的值...

 <   script     type     =  text / javascript >  
函数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 =是,菜单栏=是);
}
< / script >


尝试这是在我身边运行: -



 <   head     id   =  Head1    runat   =  server >  
< script type = text / javascript >
var Demand = function ( ){
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 =是');
返回false;
}

< / script >
< title > < / title >
< / head >
< body >
< 表格 id = form1 runat = server >
< asp:标签 ID = Label1 runat = server 文字 = 12313322 可见 = true / >
< br / >
< asp:按钮 ID = AddM runat = 服务器 文字 = 添加药物 CssClass = nm

onclientclick =' 返回Demand()' / > ;
< / form >
< / body >
< / html >


how to send a value with query string in button click...
How to Pass Value of Level1
Here is my Code..

<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:Label ID="Label1" runat="server" Text="Label">



And My button Click...

<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"

解决方案

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...




<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>


Problem

1. You have set Visible = "false" for that Label. So, it will not render on Browser. Instead do style = "display:none;".

<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...

<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>


try it this is run on my side:-

<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>


这篇关于如何在按钮单击中使用查询字符串发送值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆