2012-04-05 89 views
0

我有一個鏈接按鈕裏面的UpdatePanel在一個div彈出。在Button_Click上,我希望通過javascript打開一個新窗口。 我嘗試了ScriptManager.RegisterStartupScript以及ScriptManager.RegisterClientScriptBlock,但Window並未打開。無法打開從更新面板裏面linkbutton點擊一個新的窗口

<asp:UpdatePanel ID="UpdatePanel2" runat="server"> 

              <ContentTemplate> 
       <form class="message-form" action="#"> 
        <fieldset> 
    <asp:LinkButton ID="LinkButton1" runat="server" class="btn-facebook" Text="facebook" OnClick="LinkButton1_Click"></asp:LinkBu 

tton> 
        <label for="TextBox1">Or send a message on Blissdate here:</label> 
       <div class="textarea"> 
        <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Rows="10" Columns="30"></asp:TextBox><asp:Label ID="lbl" runat="server" /> 
       </div> 
       <div class="btn-holder"> 
        <asp:LinkButton ID="LinkButton2" runat="server" class="btn-send" Text="send" OnClick="LinkButton2_Click"></asp:LinkButton> 
       </div> 

      </fieldset> 
     </form> 

protected void LinkButton1_Click(object sender, EventArgs e) 
    { 
      DataRow[] row1 = ds.Tables[0].Select("FB_Id='" + HiddenField3.Value + "'"); 
      string url = row1[0].ItemArray[3].ToString(); 
      lbl.Text = url; 
      //ScriptManager.RegisterClientScriptBlock(this, GetType(), "newPage", "window.open('" + url +');", true); 
      ScriptManager.RegisterClientScriptBlock(this, GetType(), "newpage", "open('" + url + "');", true); 
    } 





<script type="text/javascript"> 
    function open(url) { 
     var w = window.open(url, '', 'width=1000,height=600,toolbar=0,status=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1'); 

     w.focus(); 

    } 
</script> 

請告訴我,如果事情是錯的代碼..

回答

5

重命名您的open函數爲別的。如果您在瀏覽器中啓動JavaScript控制檯,則會看到無數遞歸調用open。我不是JavaScript專家,但我相信你會遇到堆棧溢出異常。

<script type="text/javascript"> 
function customOpen(url) { 
    var w = window.open(url, '', 'width=1000,height=600,toolbar=0,status=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1'); 
    w.focus(); 

} 
</script> 

然後更改您的註冊:

ScriptManager.RegisterClientScriptBlock(this, GetType(), "newpage", "customOpen('" + url + "');", true); 
+0

哦這就是偉大的..謝謝了很多。它打開:-) – Tani 2012-04-05 06:28:57

+0

謝謝。這個對我有用。 :) – 2015-06-29 06:32:13

0

檢查瀏覽器彈出窗口阻止程序已啓用。請禁用,它將工作....

+0

未禁用.. – Tani 2012-04-05 06:08:43

相關問題