母版页中弹出模式对话框,并获取返回值

      Register.aspx页面是实现用户的注册,注册时需要选择用户所在单位,设计用弹出模式对话框(Org.aspx)里的TreeView选择用户所在单位。实现过程如下:

1、编写弹出模式对话框的脚本

//////////////////////////////////////////////////////////////////////////
// 打开模式对话框
// orgID:机构代码
// orgName:机构名称
// all:标识是否显示全部机构,为1时全部显示,为0时显示注册过的机构
//////////////////////////////////////////////////////////////////////////
function OpenOrgDlog(orgID,orgName, all,width,height) 
{       
     var me; 
     // 把父页面窗口对象当作参数传递到对话框中,以便对话框操纵父页自动刷新。
      me = "Org.aspx?id="+orgID+"&name="+orgName+"&all="+all;
     // 显示对话框。
      window.showModalDialog(me, window, 'dialogWidth=' + width + 'px;dialogHeight=' + height + 'px;help:no;status:no');
} 

2、在Register.aspx页面上添加按钮:LinkButton1,并在代码面中给按钮添加onclick属性:

                string orgName = Request.Cookies["userInfo"]["orgName"].ToString();
                string orgID = Request.Cookies["userInfo"]["orgID"].ToString();
                LinkButton1.Attributes.Add("onclick", "javascript:OpenOrgDlog('" + orgID + "','" + orgName + "',1, 600,600)");

3、构造Org.aspx页面里的TreeView及其他元素,包括确认按钮,在aspx页面的<head>部分添加:    <base target="_self" />

4、给Org.cs的确认按钮事件添加返回结果代码:

        protected void btnOK_Click(object sender, EventArgs e)
        {
            if (txbOrgID.Text == "")
            {
                return;
            }
            string script = "var wind=window.dialogArguments; wind.document.getElementById('ctl00_ContentPlaceHolder1_txbOrgId').value='" + txbOrgID.Text + "';wind.document.getElementById('ctl00_ContentPlaceHolder1_HiddenField1').value='" + HiddenField1.Value + "';window.close()";
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", script, true);
            
        }

由于Register.aspx采用母版页,并且有UpdatePanel,因此在btnOK_Click事件中的getElementById函数内用ctl00_ContentPlaceHolder1_XXX,ScriptManager.RegisterStartupScript用于在有UpdatePanel的页面中执行脚本语句。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值