简体   繁体   中英

re-use parameter from html href in asp c#

I'm opening a new window to another .aspx page in which I pass a couple of parameters and I wanted to re-pass the parameter ID from the actual page:

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

As you can see, the type parameter works well but I don't have the slightest idea how to get the "specialID" from the current page which would be:

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

So i want to get that 36 (which is a dynamic number so I can't actually put a 36 directly over there) in order to open the second page as follows:

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

As I said at the beginning the user IS at he FirstPage.aspx and upon pressing a button will go to the SecondPage.aspx

hi you can change the OnClientClick to call a javascript function which will get the specialId and then call the window.open with the full string.

for example

function openWindow(){

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

I finally could do it doing the following in the 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();
    }

On Page_Load() do following

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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