I do not necessarily have to use response.redirect, but that is what I had. I would like to open the selected link in a new window. How do I do that?
context
SqlConnection con = new SqlConnection("Data Source=.; uid=sa; pwd=sandesh;database=BeautyJunction;");
string strSQL = "Select BenificiaryType,BenificiaryName,DisttCode,IFSC,AC_No from BenificiaryMaster";
SqlDataAdapter dt = new SqlDataAdapter(strSQL, con);
DataSet ds = new DataSet();
dt.Fill(ds, "UserDetail");
string dat = String.Format("{0: MM_dd_yyyy}", DateTime.Now);
//string dat = Convert.ToString(DateTime.UtcNow.ToShortDateString());
sb.Append("~/Folder1/BenificiaryMaster_file_1" + dat + ".xml");
string path = sb.ToString();
ds.WriteXml(Server.MapPath(path));
LabelMessage.Text = "Your XML file has Been created with name 'BenificiaryMaster_file_1" + dat +"' <a target='_blank' href=Folder1/BenificiaryMaster_file_1.xml>click here</a> to show Benificiary record file";
//GridView1.DataBind();
If you are just handling navigation you can try a ASP:Hyperlink control rather than a button, that way the target is specified for the browser when the page is rendered:
protected void Page_Load (object sender, EventArgs e)
{
lnkViewPage.NavigateURL = sURL;
lnkViewPage.Target = "_blank";
}
Of course it is more polite to leave .Target alone because in this case the hyperlink could be right clicked and "open in new page/tab" would be available from the context menu.
You're trying to accomplish a client-side task from the server side, so you'll need to do a bit of hacking.
One option is sending back a page that's just a bit of JavaScript, which then will handle the redirect.
This isn't particularly clean, but what about:
Response.Write("<script>window.open('http://www.somesite.com/','_blank');</script>");
Use the button's OnClientClick property:
<asp:Button runat="server" ID="cmd_Test" onclientclick="window.open('YourUrl')" />
I use this code for redirects:
Response.Write("window.open('http://www.whatever.com','_blank')<"+"/script>");
The final tag needs to be formatted <"+"/script>
If I understand this correctly, you want to be able to open the redirected URL in a new window, but presumably retain the original target in the same window.
Unfortunately you cannot do this, because the redirect is served by the server and not browser. You could potentially redirect to a page that contained some script that opened a new window based on a URL querystring parameter. But this would open yourself up to XSS if your not careful.