2011-08-02 18 views
1

我正在下拉一些從數據庫綁定的值。當我選擇一個特定的選項我會打開相應的頁面在新標籤中我寫了下面不工作,所以任何一個可以幫助我如何在新選項卡中打開頁面從下拉列表中選擇項目

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>");` 
} 
} 
+0

並嵌套在一個UpdatePanel ddlAuthoritytype下拉? –

+0

是的,我使用嵌套在UpdatePanel中的更新panle和dropdown? – hmk

回答

2

使用此:

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; 
    } 
} 
+0

非常感謝你的工作,謝謝 – hmk

+0

但是.net2.0如何編寫代碼 – hmk

+0

歡迎您。將被警告未來的JavaScript是區分大小寫的語言。所以在JavaScript中的Window.Open字符串將導致錯誤 –

0

所以,你要回傳和處理服務器上的變化對? ddlAuthoritytype是否設置了自動回送屬性?

您是否嘗試過在交換機中執行Response.Redirect而不是注入腳本?

編輯:啊,錯過了新標籤部分,現在我明白了爲什麼腳本。

2

你應該使用下面的腳本:

<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> 
相關問題