弹出按钮上未显示弹出窗口 [英] Pop Up not getting displayed on Button Click

查看:87
本文介绍了弹出按钮上未显示弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我试图单击一个按钮打开一个弹出窗口.我尝试了以下代码,但它不起作用:

Hello,

I am trying to open a popup window on click of a button.I have tried the following code but it is not working:

Button btn = Page.FindControl("btndefer") as Button;
btn.Attributes.Add("onClick","javascript:window.open(''DeferReason.aspx'',''width=500,height=245,left=350,top=400'')");



也尝试过:



Have also tried:

btndefer.Attributes.Add("onClick", "window.open(''DeferReason.aspx''); return false;");



也尝试过



Also tried

string popupScript = "<script language=''javascript''>" +
     "window.open(''DeferReason.aspx '',  " +
     "''width=200, height=200, menubar=no, scrollbars=yes'')" +
     "</script>";
      Page.RegisterStartupScript("PopupScript", popupScript);



如何使其运作?

Bye



How to make it working?

Bye

推荐答案

尝试一下

Try this

<%@ Page Language="C#" %>
<%@ Import namespace="System.Text" %>
<script runat="server">
    void Page_load(object sender, EventArgs e)
    {
       Button1.Attributes.Add( "onclick", "popWin();return false;" ); 
     }
</script>
<html>
<head>
  <script>
   function popWin(){
        window.open('http://msdn.microsoft.com', '', '');");
   }
   </script>
    </head>
<body>
    <form runat="server">
        <asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Go!"></asp:Button>
    </form>
</body>
</html>


如果您使用按钮,则可以像
一样使用OnClientClick
If ur using button then u can use OnClientClick like

<asp:Button ID="Button1" OnClientClick="return testing();" runat="server" Text="Button" />



在javascript中写成



in javascript write like

function testing()
   {
    window.open("Default2.aspx");
    return false;
   }


您的代码中的错误是
The Error in your code is that
Button btn = Page.FindControl("btndefer") as Button;
btn.Attributes.Add("onClick","javascript:window.open('DeferReason.aspx','width=500,height=245,left=350,top=400')");


当您编写此代码时,.net会在html中执行此操作



when you write this code what .net does is this in html


<input type="submit"  önclick="javascript:window.open(" deferreason.aspx="," width="500,height=245,left=350,top=400'')''" value="Error Code"></input>



因此,在上面的代码中,您看到onClick .net之前的the放置了单引号,并且在代码中也放置了单引号,因此引号是问题

所以试试这个



So in the above you see that the before the onClick .net puts single Quotes and you have put single Quotes in the code as well so it the quotes is the problem

So try this

Button btn = Page.FindControl("btndefer") as Button;
btn.Attributes.Add("onClick","javascript:window.open(\'DeferReason.aspx\',\'_blank\',\'width=500,height=245,left=350,top=400\')");



参见修订后的代码



See this revised code


这篇关于弹出按钮上未显示弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆