Reputation: 969
I am having a drop down with some values which are binded from Database. When i select a particular option i would to open the corresponding page in new tab i write the following which doesn't work so can any one help me
protected void ddlAuthoritytype_SelectedIndexChanged(object sender, EventArgs e)
{
string ddl = ddlAuthoritytype.SelectedValue;
switch (ddl)
{
case "AL":
Response.Write("<script>Window.Open('alabama-state-tax-calculator.aspx');</script>");`
}
}
Upvotes: 0
Views: 3275
Reputation: 22448
Use this:
protected void ddlAuthoritytype_SelectedIndexChanged(object sender, EventArgs e)
{
var port = Request.Url.IsDefaultPort ? "" : ":" + Request.Url.Port.ToString();
string ddl = ddlAuthoritytype.SelectedValue;
switch (ddl)
{
case "AL":
var script = string.Format("window.open('{0}://{1}{2}{3}')", Request.Url.Scheme, Request.Url.Host, port, ResolveUrl("~/alabama-state-tax-calculator.aspx"));
ScriptManager.RegisterStartupScript(this, this.GetType(), "newWindow",script, true);
break;
}
}
Upvotes: 2
Reputation: 4497
you should use the following script:
<script type="text/JavaScript">
<!--
function openWindowFromDropDownList(theURL,winName,features)
{
var SID = document.forms[0].dropdownlist1.value
if (SID > 0){
theURL = theURL + document.forms[0].dropdownlist1.value
var newWin = window.open(theURL,winName,features);
newWin.opener = self;
}
}
//-->
</script>
Upvotes: 2
Reputation: 771
So you want a postback and process the change on the server right? Does ddlAuthoritytype have its autopostback property set?
Have you tried doing a Response.Redirect in the switch instead of injecting script?
Edit: Ah, missed the new tab part, now I see why the script.
Upvotes: 0