20150812 Asp.net 父窗体获取子窗体的返回值,更新父窗体文本控件(应用)

1. 父窗体

****************************************

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

using System.Text;
//using System.Text.StringBuilder;

public partial class Tree1 : System.Web.UI.Page
{

protected System.Data.SqlClient.SqlConnection SqlConnection1;
    protected System.Data.SqlClient.SqlDataAdapter SqlDataAdapter1;
    protected System.Data.DataSet DataSet1;
    protected System.Data.DataSet DataSet2;
    string Str_sql = "";
    static string Str_selected = "";  // 选中的值
   
   
    protected void Page_Load(object sender, EventArgs e)
    {
        AddTree(0, null);
    }

private void AddTree(int Pid, TreeNode PNode)
    {
        //string sqlStr = "SELECT Item_id,Item_name,Parent_ID FROM Para_item";
        //DataTable dt = YSqlHelper.ExecuteQuery(sqlStr, CommandType.Text);

if (!IsPostBack)
        {

P_ht.H_data P_data = new P_ht.H_data();
            P_data.sql_text1 = "SELECT Item_id,Item_name,Parent_ID FROM Para_item";
            Str_sql = P_data.sql_text1;
            P_data.select_tables();
            DataSet1 = P_data.DataSet8;
            DataTable dt = DataSet1.Tables[0];

if (dt.Rows.Count > 0)
            {
                DataView dv = new DataView(dt);
                //过滤ParentID,得到当前的所有子节点 ParentID为父节点ID
                dv.RowFilter = "[Parent_ID] = " + Pid;
                //循环递归
                foreach (DataRowView Row in dv)
                {
                    //声明节点
                    TreeNode Node = new TreeNode();
                    //绑定超级链接
                    // Node.NavigateUrl = String.Format("javascript:show(‘{0}‘)", Row["Item_Name"].ToString());
                    //开始递归
                    if (PNode == null)
                    {
                        //添加根节点
                        Node.Text = Row["Item_Name"].ToString();
                        this.TreeView1.Nodes.Add(Node);
                        Node.Expanded = true; //节点状态展开
                        AddTree(Int32.Parse(Row["Item_ID"].ToString()), Node);    //再次递归
                    }
                    else
                    {
                        //添加当前节点的子节点
                        Node.Text = Row["Item_Name"].ToString();
                        PNode.ChildNodes.Add(Node);
                        Node.Expanded = true; //节点状态展开
                        AddTree(Int32.Parse(Row["Item_ID"].ToString()), Node);     //再次递归
                    }
                }
            }
        }
    }

////
    // 选中节点
    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {
        //this.Label1.Text = TreeView1.SelectedNode.Value.ToString().Trim();
        //this.Label1.Text = TreeView1.SelectedNode.Text.ToString().Trim();
        //Response.Write(TreeView1.SelectedNode.Value.ToString().Trim());
        Str_selected = TreeView1.SelectedNode.Value.ToString().Trim();
        Response.Write(Str_selected);
    }

// add
    protected void Btn_node_add_Click(object sender, EventArgs e)
    {
       
        P_ht.H_data P_data = new P_ht.H_data();
        if (Str_selected.Trim() == "")
        {
            ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
            scriptManager.RegisterStartupScript(typeof(string), "", "alert(‘提示: 选中的节点为空,您要重新点击节点才能选中节点! ‘);", true);
            return;
        }
        else
        {
            string str_Parent_ID = "0";
            Int32 i_Item_id = 0;

//select
            P_data.sql_text1 = " SELECT Item_id,Item_name,Parent_ID FROM Para_item where Item_name = ‘" + Str_selected.Trim().ToString() +"‘ ";
            Str_sql = P_data.sql_text1;
            P_data.select_tables();
            DataSet1 = P_data.DataSet8;
            if (DataSet1.Tables[0].Rows.Count > 0)
            {
                str_Parent_ID = DataSet1.Tables[0].Rows[0][0].ToString().Trim();

P_data.sql_text1 = " SELECT Item_id,Item_name,Parent_ID FROM Para_item order by Item_id desc ";
                Str_sql = P_data.sql_text1;
                P_data.select_tables();
                DataSet1 = P_data.DataSet8;

i_Item_id =  System.Convert.ToInt32(DataSet1.Tables[0].Rows[0][0].ToString().Trim())+1;
            }
            else
            {
                ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
                scriptManager.RegisterStartupScript(typeof(string), "", "alert(‘提示: 没有找到节点编号, 不能增加节点! ‘);", true);
                return;
            }

//add
            P_data.p11_count = "4";  //总数量+1

P_data.p11_ID = i_Item_id.ToString().Trim(); //编号
            P_data.p11_01 = "月当楼";
            P_data.p11_02 = str_Parent_ID;

P_data.p21_ID = "t3_01";
            P_data.p21_01 = "t3_02";
            P_data.p21_02 = "t3_03";

P_data.sql_text1 = "INSERT INTO Para_item (Item_id,Item_name,Parent_ID) VALUES "
                                               + "(@t3_01, @t3_02, @t3_03)";

P_data.write_tables();
        }

////reshfer;

//TreeNode nodeNew = new TreeNode("月当楼");// 新建节点对象

//if (TreeView1.SelectedNode == null)
        //{
        //    return;
        //}
        //else
        //{
        //    TreeView1.SelectedNode.ChildNodes.Add(nodeNew);
        //}

Server.Transfer("Tree1.aspx");

}

protected void Btn_node_edit_Click(object sender, EventArgs e)
    {
        P_ht.H_data P_data = new P_ht.H_data();
        if (Str_selected.Trim() == "")
        {
            ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
            scriptManager.RegisterStartupScript(typeof(string), "", "alert(‘提示: 选中的节点为空,您要重新点击节点才能选中节点! ‘);", true);
            return;
        }
        else
        {
           
            //select

string str_Parent_ID = "";

P_data.sql_text1 = " SELECT Item_id,Item_name,Parent_ID FROM Para_item where Item_name = ‘" + Str_selected.Trim().ToString() + "‘ ";
            Str_sql = P_data.sql_text1;
            P_data.select_tables();
            DataSet1 = P_data.DataSet8;
            if (DataSet1.Tables[0].Rows.Count > 0)
            {
                str_Parent_ID = DataSet1.Tables[0].Rows[0][0].ToString().Trim();
                Session["Tree1_Edit_name"] = str_Parent_ID;
            }
            else
            {
                ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
                scriptManager.RegisterStartupScript(typeof(string), "", "alert(‘提示: 没有找到节点编号, 不能删除节点! ‘);", true);
                return;
            }

//原窗口保留,以对话框形式打开新窗口:
            //Response.Write("<script>window.showModelessDialog(‘Tree1_edit.aspx‘)</script>");
            //return;

//
            StringBuilder s = new StringBuilder();
            s.Append(" <script language=javascript> var a=window.showModalDialog(‘Tree1_edit.aspx‘); ");
            s.Append(" if(a!=null) document.all(‘TextBox1‘).value=a;</script> ");
             Type cstype = this.GetType();

ClientScriptManager cs = Page.ClientScript;
            string sname = "lt";
            if (!cs.IsStartupScriptRegistered(cstype, sname))
            cs.RegisterStartupScript(cstype, sname, s.ToString());
            return;
           
            //
            P_data.sql_text1 = "update Para_item set Item_name = ‘户部巷‘ "
                                                  + " where Item_id =  " + str_Parent_ID.Trim().ToString() + " ";

P_data.update_tables();
        }

////reshfer;

//if (TreeView1.SelectedNode == null)
        //{
        //    return;
        //}
        //else
        //{
        //    TreeView1.SelectedNode.Value = "户部巷";
        //    TreeView1.SelectedNode.Text = "户部巷";
        //}

Server.Transfer("Tree1.aspx");
    }

// delete
    protected void Btn_node_delete_Click(object sender, EventArgs e)
    {
        P_ht.H_data P_data = new P_ht.H_data();
        if (Str_selected.Trim() == "")
        {
            ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
            scriptManager.RegisterStartupScript(typeof(string), "", "alert(‘提示: 选中的节点为空,您要重新点击节点才能选中节点! ‘);", true);
            return;
        }
        else
        {
            //select

string str_num_ID = "";
            string str_Parent_ID = "";

P_data.sql_text1 = " SELECT Item_id,Item_name,Parent_ID FROM Para_item where Item_name = ‘" + Str_selected.Trim().ToString() + "‘ ";
            Str_sql = P_data.sql_text1;
            P_data.select_tables();
            DataSet1 = P_data.DataSet8;
            if (DataSet1.Tables[0].Rows.Count > 0)
            {
                str_num_ID = DataSet1.Tables[0].Rows[0][0].ToString().Trim();
                str_Parent_ID = DataSet1.Tables[0].Rows[0][2].ToString().Trim();
            }
            else
            {
                ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
                scriptManager.RegisterStartupScript(typeof(string), "", "alert(‘提示: 没有找到节点编号, 不能删除节点! ‘);", true);
                return;
            }

// 如果有子节点提示先删除子节点,否则不予删除。( 另一种方法是写代码,用递归的方法找到所有的子节点,批量性删除 )
            P_data.sql_text1 = " SELECT Item_id,Item_name,Parent_ID FROM Para_item where Parent_ID = ‘" + str_num_ID.Trim().ToString() + "‘ ";
            Str_sql = P_data.sql_text1;
            P_data.select_tables();
            DataSet1 = P_data.DataSet8;
            if (DataSet1.Tables[0].Rows.Count > 0)
            {
                ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
                scriptManager.RegisterStartupScript(typeof(string), "", "alert(‘提示: 不能删除, 先删除所有子节点后才都能删除父节点! ‘);", true);
                return;
            }
            else
            {
                P_data.sql_text1 = " delete from Para_item where Item_id = " + str_num_ID.Trim().ToString() + " ";
                P_data.update_tables();
            }
        }

//reshfer;
        Server.Transfer("Tree1.aspx");

}

}

****************************************

2. 子窗体

****************************************

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

using System.Text;
//using System.Text.StringBuilder;

public partial class Tree1_edit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["Tree1_Edit_name"] != null)
            {
                this.TextBox1.Text = Session["Tree1_Edit_name"].ToString();
            }
            else
            {
                this.TextBox1.Text = "";
            }
        }
    }

protected void Btn_confirm_Click(object sender, EventArgs e)
    {
        //Response.Write("<script>window.close();</script>");// 会弹出询问是否关闭
        //Response.Write("<script>window.opener=null;window.close();</script>");// 不会弹出询问

// 不会弹出询问
        //ClientScript.RegisterStartupScript(Page.GetType(), "", "<script language=javascript>window.opener=null;window.open(‘‘,‘_self‘);window.close();</script>");

//Response.Write("<script>window.returnValue=1;window.close();</script>");

//
        StringBuilder s = new StringBuilder();
        s.Append("<script language=javascript>" + "\n window.returnValue=‘" + this.TextBox1.Text.Trim().ToString() + "‘;" + "\n window.close();" + "\n </script>");
        Type cstype = this.GetType();
        ClientScriptManager cs = Page.ClientScript;
        string csname = "ltype";
        if (!cs.IsStartupScriptRegistered(cstype, csname))
            cs.RegisterStartupScript(cstype, csname, s.ToString());

//Response.Write("<script language=javascript>opener.location.href=opener.location.href;</script>");

}

}

****************************************

时间: 2024-10-06 02:38:27

20150812 Asp.net 父窗体获取子窗体的返回值,更新父窗体文本控件(应用)的相关文章

python多线程获取子线程任务返回值

今天想实现多线程更新资产信息,所以使用到了threading,但是我需要每个线程的返回值,这就需要我在threading.Thread的基础上进行封装 def auto_asset(node): ret = salt.remote_grains_execution_sigle(node) asset_info={} asset_info['os']= ret[node]['oscodename'] asset_info['kernelrelease']= ret[node]['kernelrel

iframe父页面获取子页面的高度

最近做项目中用到了iframe,子页面更改父页面的高度,经过九九八十一难,找到了解决的办法. $(window).load(function() {  var h=$(document).height();  var ifHeight = $(window.top.document).find(".XX").css({  height:h }); }); window.top:是获取子页面所有body以上的元素. window.parent()是获取子页面body的上一级父元素.

ASP.NET购物车Cookie获取,创建,添加,更新,删除的用法

#region 添加购物车 public void GetShoppingCart(int skuId, int quanlity) { HttpCookie cookie = HttpContext.Current.Request.Cookies["myCart"];//获取cookie var reg = Session["userInfo"] as Registration; 用户登入状态 #region  未登入状态时 if(reg == null) { i

ASP.NET编辑与更新数据(非GridView控件实现)

Insus.NET在实现<ASP.NET开发,从二层至三层,至面向对象 (5)>http://www.cnblogs.com/insus/p/3880606.html 中,没有把数据编辑与更新功能一起演示,留下给网友们自由发挥,但是还是有网友想看看Insus.NET用实现方法. 以前Insus.NET的做法,是在GridView控件中进行.如这篇视频教程<GridView Edit Update Cancel Delete>http://www.cnblogs.com/insus/

Selenium2学习-036-WebUI自动化实战实例-034-JavaScript 在 Selenium 自动化中的应用实例之六(获取 JS 执行结果返回值)

Selenium 获取 JavaScript 返回值非常简单,只需要在 js 脚本中将需要返回的数据 return 就可以,然后通过方法返回 js 的执行结果,方法源码如下所示: 1 /** 2 * Get Object of return from js 3 * 4 * @author Aaron.ffp 5 * @version V1.0.0: autoSeleniumDemo main.aaron.sele.core SeleniumCore.java execJSR, 2015-8-9

怎样获取shell函数的返回值及shell命令的返回值?

1.获取shell函数调用的返回值: #!/bin/sh info() { cat jlb.sh } res=`info` echo "state: "$? echo "res: "${res} 说明:res=`info`这一行为调用函数info,里面的符号`不是单引號,而是Esc按键以下的那个.另外$?返回的为上一条命令的运行状态,不是返回值. 2.获取shell命令的返回值,原理同上,比如: #!/bin/sh info=`cat jlb.sh` echo &q

如何获取shell函数的返回值及shell命令的返回值?

1.获取shell函数调用的返回值: #!/bin/sh info() { cat jlb.sh } res=`info` echo "state: "$? echo "res: "${res} 说明:res=`info`这一行为调用函数info,里面的符合`不是单引号,而是Esc按键下面的那个,另外$?返回的为上一条命令的执行状态,不是返回值: 2.获取shell命令的返回值,原理同上,例如: #!/bin/sh info=`cat jlb.sh` echo &q

asp.net 父窗体获取子窗体的返回值,可用来对父窗体局部更新

今天在项目上遇到了这个问题,其实只是window.returnValue的简单应用,不是asp.net的专属内容.作为积累,记录一个简单的实现模型. 图1  用到的文件 从图1中我们可以看到,只用到了两个页面,其中Default.aspx作为父页面,Default2.aspx作为子页面被弹出.Default.aspx页面上有两个TextBox一个Button,代码如下: 1 <%@ Page Language="C#" AutoEventWireup="true&quo

vue组件之间传值、父组件获取子组件的方法

1.子组件向父组件传值 子组件 <template>     <div class="app">        <input @click="sendMsg" type="button" value="给父组件传递值">     </div> </template> <script> export default {       data () {    

父页面获取子页面的内容

需求说明:两个JSP页面,父页面需要子页面的内容,但子页面是隐藏的,具体来说,子页面是一系列的模板,父页面要通过id来获取这些模板,不愿意通过<include>方式导入,因为如果模板过多,就导致整个父页面太大,加载缓慢,以下两个方案,不知有没有解决这个问题. 1,通过ajax方式 实现过程:通过ajax请求到子页面中,子页面获取参数id使用java和js变量的交互后,返回需要的模板信息 缺点:把js变量转换成java变量比较麻烦,需要使用form表单来提交,而且jsp中的java脚本是在服务器