将java脚本变量值作为PostBackUrl查询字符串的一部分发送。

时间:2021-12-26 03:18:22

I need to send a parameter value into a query string of a PostBackUrl method within asp button.

我需要将一个参数值发送到asp按钮中的PostBackUrl方法的查询字符串中。

The value I need is already being captured within a java script function shown below.

我需要的值已经在如下所示的java脚本函数中被捕获。

How do I send the value in hiddId as part of URL ? The below method isn't working. Can someone please help ?

如何将值作为URL的一部分发送到hiddId中?下面的方法不起作用。有人能帮忙吗?

   <script language="javascript" type = "text/javascript">
        function btn_Selected() {
           var hiddId = null;
           $('#<%=GridView1.ClientID %>').find('input[type=radio]:checked').each(function () {
               hiddId = $(this).closest('tr').find('input[type = "hidden"]').val();
           });

     }

 <asp:Button ID="Btn_Update" runat="server" Text="Update" PostBackUrl="Screen_Edit.aspx?CustID='<%=hiddId%>'"

2 个解决方案

#1


0  

Instead of a post-back, just redirect using JavaScript.

不要使用后返回,只需使用JavaScript重定向。

function btn_Selected() {
           var hiddId = null;
           $('#<%=GridView1.ClientID %>').find('input[type=radio]:checked').each(function () {
               hiddId = $(this).closest('tr').find('input[type = "hidden"]').val();
           });
           window.location.href = "Screen_Edit.aspx?CustID='" + hiddId + "'"
     }

#2


0  

If you look at the HTML source of the page, the button will have an javascript onclick event that looks something like this javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$mainContentPane$Btn_Update&quot;, &quot;&quot;, false, &quot;&quot;, &quot;Screen_Edit.aspx?CustID=&quot;, false, false))

如果您查看该页面的HTML源代码,该按钮将会有一个javascript onclick事件,它看起来像这样的javascript:WebForm_DoPostBackWithOptions(新的WebForm_PostBackOptions(“ctl00$mainContentPane$ btn_update”,“”、“”、“”、“Screen_Edit.aspx?”)。

All we have to do is find a way to insert your variable after ?CustID=.

我们所要做的就是找到一种方法来插入你的变量,CustID=。

You can replace the onclick value of the button with the .attr() function of jQuery and do a search and replace to insert your variable.

您可以使用jQuery的.attr()函数替换按钮的onclick值,并进行搜索和替换以插入变量。

<script type="text/javascript">
    $(document).ready(function () {
        var hiddId = $(this).closest('tr').find('input[type = "hidden"]').val();
        $("#<%=Btn_Update.ClientID %>").attr("onclick", $("#<%=Btn_Update.ClientID %>").attr("onclick").replace("?CustID=", "?CustID=" + hiddId));
    });
</script>

#1


0  

Instead of a post-back, just redirect using JavaScript.

不要使用后返回,只需使用JavaScript重定向。

function btn_Selected() {
           var hiddId = null;
           $('#<%=GridView1.ClientID %>').find('input[type=radio]:checked').each(function () {
               hiddId = $(this).closest('tr').find('input[type = "hidden"]').val();
           });
           window.location.href = "Screen_Edit.aspx?CustID='" + hiddId + "'"
     }

#2


0  

If you look at the HTML source of the page, the button will have an javascript onclick event that looks something like this javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$mainContentPane$Btn_Update&quot;, &quot;&quot;, false, &quot;&quot;, &quot;Screen_Edit.aspx?CustID=&quot;, false, false))

如果您查看该页面的HTML源代码,该按钮将会有一个javascript onclick事件,它看起来像这样的javascript:WebForm_DoPostBackWithOptions(新的WebForm_PostBackOptions(“ctl00$mainContentPane$ btn_update”,“”、“”、“”、“Screen_Edit.aspx?”)。

All we have to do is find a way to insert your variable after ?CustID=.

我们所要做的就是找到一种方法来插入你的变量,CustID=。

You can replace the onclick value of the button with the .attr() function of jQuery and do a search and replace to insert your variable.

您可以使用jQuery的.attr()函数替换按钮的onclick值,并进行搜索和替换以插入变量。

<script type="text/javascript">
    $(document).ready(function () {
        var hiddId = $(this).closest('tr').find('input[type = "hidden"]').val();
        $("#<%=Btn_Update.ClientID %>").attr("onclick", $("#<%=Btn_Update.ClientID %>").attr("onclick").replace("?CustID=", "?CustID=" + hiddId));
    });
</script>