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