ASP.NET彈出新窗口,獲得返回值

Page.aspx:

 

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    
<title>無標題頁</title>
    
<script type="text/javascript" >
      
function Pop() 
  
{       
   
var result=showModalDialog('downs.aspx','subpage','dialogWidth:400px;dialogHeight:300px;center:yes;help:no;resizable:no;status:no');  //打開模態子窗體,並獲取返回值
   document.getElementById("txt_id").value=result.split("'")[0];  //返回值分別賦值給相關文本框
   document.getElementById("txt_name").value=result.split("'")[1];
   document.getElementById(
"txt_pwd").value=result.split("'")[2];
  }
 
    
</script>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
    
<asp:TextBox ID="txt_id" runat="server" ></asp:TextBox>
    
<asp:TextBox ID="txt_name" runat="server" ></asp:TextBox>
    
<asp:TextBox ID="txt_pwd" runat="server" ></asp:TextBox>
    
<br />
    
    
<asp:Button ID="btnPop" runat="server" Text="PoPWindows" OnClientClick ="Pop()" />
    
    
</div>
    
</form>
</body>
</html>

 

downs.aspx: 彈出頁面

 

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    
<title>無標題頁</title>
    
<script type="text/javascript" >
     
function cc(infor_id,infor_name,infor_psw) //參數分別爲id,name和password
 
   window.returnValue
= infor_id+"'"+infor_name+"'"+infor_psw;   //返回值    
   window.close(); 
 }


    
</script>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
    
<asp:GridView ID="gvshow" runat="server" BackColor="White" BorderColor="#CCCCCC" 
            BorderStyle
="None" BorderWidth="1px" CellPadding="3" 
            onrowdatabound
="gvshow_RowDataBound" >
        
<FooterStyle BackColor="White" ForeColor="#000066" />
        
<RowStyle ForeColor="#000066" />
        
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
        
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
        
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
        
</asp:GridView>
    
</div>
    
</form>
</body>
</html>

 

downs.cs:彈出頁面後臺代碼:

 

public partial class downs : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
        
if (!IsPostBack)
        
{
            SetBind();
        }

    }

    
public void SetBind()
    
{
        
string ConnString = ConfigurationManager.ConnectionStrings["ConnStr"].ToString();
        
using (SqlConnection conn = new SqlConnection(ConnString))
        
{
            conn.Open();
            
string sql = "select top 10 gwid,machtype,isok from allinfor";
            SqlDataAdapter ada 
= new SqlDataAdapter(sql, conn);
            DataSet ds 
= new DataSet();
            ada.Fill(ds);
            gvshow.DataSource 
= ds.Tables[0];
            
this.gvshow.DataBind();
        }

    }

    
protected void gvshow_RowDataBound(object sender, GridViewRowEventArgs e)
    
{
        
if (e.Row.RowType == DataControlRowType.DataRow)
        
{
            e.Row.Attributes.Add(
"onclick""cc('" + e.Row.Cells[0].Text + "','" + e.Row.Cells[1].Text + "','" + e.Row.Cells[2].Text + "')");

        }

    }

}
發佈了11 篇原創文章 · 獲贊 0 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章