Question : target a blank window with asp:button

Hello good people,

I want to use a button to open a blank window and load it with a specific page.

I can do this with an asp:hyperlink using target="_blank".

I need to use a button. I'm close with the code below but not close enough.

I think I'm only limited by escaping out characters... we'll see :)

Thank you,

Christopher
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
Working link:
 
     View Printable Version
 
 
 
Code Behind:
 
        protected void hlPrintableVersion_OnLoad(object sender, EventArgs e)
        {
            string strDateSelected = ddlStatementDates.SelectedValue;
            hlPrintableVersion.NavigateUrl = "~/member_statement_print.aspx?date=" + strDateSelected;            
        }
 
 
 
########################################
 
I want:
 
     
 
 
 
Code behind:
 
     protected void btnViewPrintVersion_Click(object sender, EventArgs e)
     {        
            string strDateSelected = ddlStatementDates.SelectedValue;
            OnClientClick="window.open('~/member_statement_print.aspx?date=' + strDateSelected;'); return false;"
      }

Answer : target a blank window with asp:button

Now you're making things complicated.

The code that I gave you already does what you need.

First of all, do not set OnClientClick in your aspx page, we add it instead in the code.

In the btnViewPrintVersion_PreRender function we specify a javascript that will open a window with the following URL : ~/member_statement_print.aspx?date=XXXX where XXXX will be the value of the selected item in the ddlStatementDates list.

If you need to change URL of the opening window, change it in btnViewPrintVersion_PreRender. If you need to change your XXXX value, change it in your ddlStatementDates list values.

Here it is simplified :

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
== ASPX ==
 

 
 
== Code ==
 
    protected void btnViewPrintVersion_PreRender(object sender, System.EventArgs e)
    {
        string urlRelativeToApplication = "/member_statement_print.aspx";
        string dateParameterName = "date";
 
        ((Button)sender).OnClientClick = "window.open('" + HttpContext.Current.Request.ApplicationPath + urlRelativeToApplication + "?" + dateParameterName + "=' + document.getElementById('" + ddlStatementDates.ClientID + "')(document.getElementById('" + ddlStatementDates.ClientID + "').selectedIndex).value); return false;";
    }
 
Random Solutions  
 
programming4us programming4us