aspx:
用户控件的加载应用<body>
用户控件的加载应用    
<form id="form1" runat="server">
用户控件的加载应用    
<div>
用户控件的加载应用        
<hr />
用户控件的加载应用           
<asp:PlaceHolder ID = "Pholder" runat ="server"></asp:PlaceHolder>
用户控件的加载应用    
</div>
用户控件的加载应用    
</form>
用户控件的加载应用
</body>
用户控件的加载应用
</html>
cs:
用户控件的加载应用    protected void Page_Load(object sender, EventArgs e)
    }


注意点:用户控件在加载后或者多次加载后,部分JS文件调用内部控件ID的时候可能会产生变化
解决办法:
1、在cs中定义一个全局变量 如: public string strConName;
2、在加载控件(Pholder.Controls.Add(con1);)之后加     如:strConName = con1.ClientID;   // 获取加载控件的控件代号
3、在aspx页面中增加   <script type="text/javascript">  var strName = '<%=strConName%>';   </script> // 在JS中获取
4、页面预览之后,页面上的控件ID 变为  strName+"_tbxLoadPortEN" (_+未加载前控件ID)      document.getElementById(strName+"_tbxLoadPortEN");

   foreach (GridViewRow row in gvList.Rows)
            {
                CheckBox delItem = row.FindControl("cbxItem") as CheckBox;

                if (delItem != null && delItem.Checked)
                {
     bll.Delete(Convert.ToInt32(gvList.DataKeys[row.RowIndex].Values[0]),Convert.ToInt32(gvList.DataKeys[row.RowIndex].Values[1]));
                }
            }
Panel pl = this.FindControl(panelName) as Panel;
        TextBox tbxPersonName = GvPerson.Rows[e.RowIndex].Cells[1].FindControl("tbxPersonName") as TextBox;
        DropDownList ddSex = GvPerson.Rows[e.RowIndex].Cells[2].FindControl("ddSex") as DropDownList;
(TextBox)Findcontrol("").Text

多次加载问题
cs:

用户控件的加载应用Control Con = new Control(); 
用户控件的加载应用  
private void Page_Load(object sender, System.EventArgs e)
  }

*.ascx
放置一个Label
*.ascx.cs:

}

 

相关文章:

  • 2022-02-04
  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
  • 2021-06-14
  • 2022-12-23
  • 2022-03-05
  • 2021-11-11
猜你喜欢
  • 2022-12-23
  • 2021-08-31
  • 2021-09-28
  • 2021-09-03
  • 2021-12-02
  • 2021-11-27
相关资源
相似解决方案