[原创]在Asp.Net中使用javascript弹出窗口

在Asp.Net中使用javascript

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication3
{
    
/// <summary>
    
/// WebForm1 的摘要说明。
    
/// </summary>

    public class WebForm1 : System.Web.UI.Page
    
{
        
protected System.Web.UI.WebControls.Button Button1;
    
        
private void Page_Load(object sender, System.EventArgs e)
        
{
            
// 在此处放置用户代码以初始化页面
        }


        
public static void Alert(System.Web.UI.Page mPage,string strMsg,string strKey)
        
{
            
string strScript="<script language=javascript>alert('";
            strScript
+=strMsg;
            strScript
+="')</script>";

            
if(!mPage.IsStartupScriptRegistered(strKey))
            
{
                mPage.RegisterStartupScript(strKey,strScript);
            }

        }


        
public static void OpenWindow(System.Web.UI.Page mPage,string pageName,string strKey)
        
{
            
string strScript="<script language=javascript>window.open('";
            strScript
+=pageName;
            strScript
+="','newWindow',";
            strScript
+="'height=400, width=400, toolbar =no, menubar=no, scrollbars=no, resizable=no, location=no, status=no'";
            strScript
+=")</script>";

            
if(!mPage.IsStartupScriptRegistered(strKey))
            
{
                mPage.RegisterStartupScript(strKey,strScript);
            }

        }


        
Web 窗体设计器生成的代码

        
private void Button1_Click(object sender, System.EventArgs e)
        
{
//            Alert(this,"test","clientScript");
            OpenWindow(this,"WebForm2.aspx","ClentScript");
        }

    }

}

posted @ 2005-03-08 01:33  CrystalPipe  阅读(346)  评论(0)    收藏  举报