繁体   English   中英

在ASP C#中重复使用HTML href中的参数

[英]re-use parameter from html href in asp c#

我正在打开另一个.aspx页面的新窗口,在其中我传递了两个参数,并且我想从实际页面中重新传递参数ID:

<asp:Button ID="Button1" runat="server" CausesValidation="False" meta:resourceKey="btnAddRow2" 
OnClientClick="window.open('SecondPage.aspx?type=Usuaris&id=SPECIALID', '_blank')" Text="Miau" />

如您所见,type参数可以很好地工作,但是我丝毫不知道如何从当前页面获取“ specialID”,即:

http://blablabla.com/FirstPage.aspx?SPECIALID=36

所以我想得到那个36(这是一个动态数字,所以我实际上不能直接在上面放一个36)以便打开第二页,如下所示:

http://blablabla.com/SecondPage.aspx?type=Usuaris&SPECIALID=36

就像我在一开始所说的那样,用户位于他的FirstPage.aspx上,按下按钮后将转到SecondPage.aspx

您好,您可以将OnClientClick更改为调用javascript函数,该函数将获取specialId,然后使用完整字符串调用window.open。

例如

function openWindow(){

var specialId = document.getElementById('someElement').value;
window.open('SecondPage.aspx?type=Usuaris&id=' + specialId, '_blank')"
}

我终于可以在FirstPage.aspx执行以下操作:

    function getParameterByName(name) {
        var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
        return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
    }

    function AddUsuario() {
        var id = getParameterByName("id");
        window.open('SecondPage.aspx?type=Usuarios&id=' + id, '_blank');
        location.reload();
    }

在Page_Load()上执行以下操作

Button1.Attributes.Add("onclick", 
    String.Format("window.open('SecondPage.aspx?type=Usuaris&id={0}', '_blank');",
    Request.QueryString["SPECIALID"]));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM