• saucer(思归)解决的关于:页面A.aspx 动态载入用户自定义控件a.ascx,但a.ascx中的按钮提交后,不执行按钮的事件,而是直接刷新页面 Virus


    还没解决啊?象我前面说的,你需要记住你目前的控件,然后在Page_Load或以前事件里重新Load,下面是个简单的例子,试着在文本框里输入b.ascx或c.ascx    
       
      1.   TestA.ascx:  
       
      <%@   Register   TagPrefix="uc"   TagName="MyControl"   Src="A.ascx"   %>  
      <form   runat="server">  
      <uc:MyControl   id="mc"   runat="server"/>  
      <hr>  
     <asp:Panel   id="ContentPane"   runat="server"   />  
      <asp:Button   id="btn"   runat="server"   Text="Refresh"   />  
      </form>  
       
      2.   a.ascx:  
       
      <asp:TextBox   id="tb1"   runat="server"   />  
      <asp:LinkButton   id="LinkButton1"   runat="server"   Text="Load"   OnClick="LinkButton1_Click"/>  
      <script   language="C#"   runat="server">  
      private   void   LinkButton1_Click(object   sender,   System.EventArgs   e)  
      {  
          string   s   =   tb1.Text.Trim();  
          if   (!s.Equals(String.Empty))  
          LoadUserControl(s);  
      }  
       
       
      string   LoadedControl  
      {  
          get  
          {  
      object   o   =   ViewState["LoadedControl"];  
      if   (o   ==   null)  
      return   "";  
      else  
      return   (string)ViewState["LoadedControl"];  
          }  
          set  
          {  
      ViewState["LoadedControl"]   =   value;  
          }  
      }  
       
      int   LoadedControlID  
      {  
          get  
          {  
      object   o   =   ViewState["LoadedControlID"];  
      if   (o   ==   null)  
      return   0;  
      else  
      return   (int)ViewState["LoadedControlID"];  
          }  
          set  
          {  
      ViewState["LoadedControlID"]   =   value;  
          }  
      }  
       
      void   LoadUserControl(string   strPathName)  
      {  
          if   (strPathName.Equals(String.Empty))  
      return;  
       
          Control   parent   =   Page.FindControl("ContentPane");  
       
          if   (LoadedControl   !=   strPathName)  
          {  
      if   (parent.Controls.Count   >   0)  
      parent.Controls.Clear();  
       
          LoadedControlID++;  
          }  
       
          LoadedControl   =   strPathName;  
       
          Control   c   =   LoadControl(strPathName);  
       
          if   (c   !=   null)  
          {  
          c.ID   =   "ID"   +     LoadedControlID.ToString()   ;  
          parent.Controls.Add(c);  
          }  
      }  
       
      void   Page_Load(Object   sender,   EventArgs   e)  
      {  
        if   (!LoadedControl.Equals(String.Empty))  
      LoadUserControl(LoadedControl);  
      }  
       
      </script>  
       
      3.   b.ascx:  
      b.ascx:   <%=DateTime.Now%>  
      <asp:Button   id="btn"   runat="server"   Text="Button   in   B.ascx"   OnClick="Button1_Click"   />  
      <script   language="C#"   runat="server">  
      private   void   Button1_Click(object   sender,   System.EventArgs   e)  
      {  
          Page.Response.Write("BUtton   in   B   is   Clicked   at   "   +   DateTime.Now.ToString());  
      }  
      </script>  
       
      4.   c.ascx:  
      c.ascx:   <%=DateTime.Now%>  
       
      <asp:Button   id="btn"   runat="server"   Text="Button   in   C.ascx"   OnClick="Button1_Click"   />  
      <script   language="C#"   runat="server">  
      private   void   Button1_Click(object   sender,   System.EventArgs   e)  
      {  
          Page.Response.Write("BUtton   in   C   is   Clicked   at   "   +   DateTime.Now.ToString());  
      }  
      </script>

    【Blog】http://virusswb.cnblogs.com/

    【MSN】jorden008@hotmail.com

    【说明】转载请标明出处,谢谢

    反馈文章质量,你可以通过快速通道评论:

  • 相关阅读:
    天空卫士陆明:数据法在企业如何落地
    陈宏申:浅谈京东电商商品文案挖掘难点与优化实践
    陈胡:Apache SeaTunnel实现 非CDC数据抽取实践
    李阳:京东零售OLAP平台建设和场景实践
    李卓豪:网易数帆数据中台逻辑数据湖的实践
    苗大东:京东基于强化学习的电商搜索排序算法
    构建AR视频空间大数据平台(物联网及工业互联网、视频、AI场景识别)
    长连接长轮询
    Nacos数据模型
    漏桶和令牌桶的区别
  • 原文地址:https://www.cnblogs.com/virusswb/p/1158095.html
Copyright © 2020-2023  润新知