Search code examples
c#window.openonclientclick

ASPNET C# onclientclick


in one of my pages I got following in CodeBehind to redirect to another page.

protected void btnEASYBRIEF_Click(object sender, EventArgs e)
        {
            Response.RedirectToRoutePermanent("../Prints/EASYBRIEF.aspx?" + grdFlights.SelectedDataKey.Value);
        }

I want to change it to a "onclientclick" event like

onclientclick="window.open('../Prints/EASYBRIEF.aspx?
                     +grdFlights.SelectedDataKey.Value')"

How would be the right text after ../Prints/EASYBRIEF.aspx

Thanks in advance


Solution

  • I would create a property to access like

    Code Behind

    string _selectedValue;
    
    
    public string SelectedValue {
    
        get { return _selectedValue; }
    }
    

    Set the '_selectedValue' as your grdFlights.SelectedDataKey.Value

    Then in the .aspx page you can do

    var value = <%# SelectedValue%>;
    
    onclientclick="window.open('../Prints/EASYBRIEF.aspx?' + value)"
    

    Something to that effect.