导航

javascript 学习

Posted on 2004-09-07 14:04  wngwz  阅读(600)  评论(0编辑  收藏  举报
弹出模态窗体,并回传数值!
窗体:WebForm1.aspx; frame.aspx; WebForm2.aspx
WebForm1.aspx 窗体的Load事件中
if ( !IsPostBack)
{
    Button1.Attributes.Add(
"onclick","GetString(TextBox1)");
}
前台的javascript脚本:
function GetString(keys)
{
    keys.value 
= window.showModalDialog("frame.aspx?url=WebForm2.aspx");
}
frame.aspx 窗体的Load事件中
if(!IsPostBack)
{
    
if(Request.QueryString.Count >= 2//获得包含在传递字符串中健值对的个数。
    {
        
string Rurl = Request.QueryString["url"].ToString();
        
string paraname = Request.QueryString.GetKey(1);
        
string paravalue = Request.QueryString.Get(1);
        
string url = Rurl+"?"+paraname+"="+paravalue;
        
for(int i=2;i<Request.QueryString.Count;i++)
        
{
            url 
= url+"&"+Request.QueryString.GetKey(i)+"="+Request.QueryString.Get(i);
        }

        fraMultiSelect.Attributes.Add(
"src",url);
    }

    
else
    
{
        
//当通过WebForm1.aspx进入WebForm2.aspx时,首先要先经过这个框架窗体,才可以

        
string url = Request.QueryString["url"].ToString();
        fraMultiSelect.Attributes.Add(
"src",url);
    }

}
在前台添加
<iframe id="fraMultiSelect" width="100%" height="100%" frameborder="0" scrolling="no" runat="server"></iframe>
WebForm2.aspx
private void Button1_Click(object sender, System.EventArgs e)
{
    Response.Write(
"<script language='javascript'>");
    Response.Write(
"window.returnValue = '"+TextBox1.Text+"';");
    Response.Write(
"window.close();");
    Response.Write(
"</script>");
}