弹出选择页面。

 
 
弹出选择页面。
功能介绍:点击页面上的某个控件,将数据传入到另一个页面并以弹出窗体的形式弹出。在那个页面做相应处理后回到原始页面,并将处理过的数据传会来。类似Windows的选择窗体。
 
在基础页面用如下代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SelectForm.aspx.cs" Inherits="WebPage_SelectForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    
<title>无标题页</title>
    
<script language = "javascript">
    function funInput()
    
{

        var varResult;
        var varInput 
= document.getElementById("input").innerHTML;
        
//alert(varInput);
        url = 'SelectedForm.aspx?input='+escape(varInput);    
        varResult 
= window.showModalDialog(url,[window],'scroll:yes;dialogWidth:500px;dialogHeight:500px;status:0;center:yes');
    
//    alert(varResult.button1);
        if (varResult != null
        
{
            document.getElementById(
"output").value = varResult.button1;
            
return varResult;    
        }

        
    }

    
</script>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
    
<asp:Label id = "input" runat = "server" Text="test" >test data</asp:Label>
    
<asp:TextBox ID = "output" runat = "server">aaaaaa</asp:TextBox>
    
<button style="CURSOR: hand; width: 316px; height: 29px;" onclick="funInput()" id="IMG1"/>
    
    
</div>
    
</form>
</body>
</html>

 注意:对于lable、button这类控件,要获得他们中的数据,要用innerHTML,但是对于textBox这样的控件用Value

下面是要弹出的页面的后台代码:

 

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class WebPage_SelectedForm : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
        
if (Request["input"!= null)
        
{
            System.Text.StringBuilder sb 
= new StringBuilder("<script Language="Javascript">");
            sb.Append(
"function setResult(varResult)");
            sb.Append(
"{");
            sb.Append(
"window.returnValue = new result(varResult);");
            sb.Append(
"window.close();");
            sb.Append(
"}");
            sb.Append(
"function result(varResult)");
            sb.Append(
"{");
            sb.Append(
"this.button1 = varResult;");
            sb.Append(
"}");
            sb.Append(
"<");
            sb.Append(
"/");
            sb.Append(
"script>");
            
if (!ClientScript.IsStartupScriptRegistered("Result"))
                ClientScript.RegisterStartupScript(
this.GetType(), "Result", sb.ToString());
        }


        
this.Button1.Attributes.Add("onclick""javascript:setResult('" +Request.QueryString["input"].ToString()+ "is processed')");

    }

    
protected void Button1_Click(object sender, EventArgs e)
    
{

    }

}

嘿嘿。。。。只要完成了传递数据的工作,以后想做什么都可以了呀。

posted on 2007-10-19 10:39  LongSky  阅读(229)  评论(0编辑  收藏  举报

导航