日期:2014-05-18  浏览次数:20357 次

为什么用FindControl找不到单选按钮
代码:

<asp:Panel ID="picPanel" runat="server" GroupingText="图片上传" CssClass="picPanel">
  <div id="panel_main1" class="panel_main" runat="server">
  <div id="main1_left" class="main_left">
  <asp:FileUpload ID="fileUpLoad1" runat="server" ToolTip="选择上传文件" />
  <asp:TextBox ID="txtPicDesc1" runat="server" TextMode="MultiLine" Wrap="true" width="200px" height="120px" ToolTip="添加图片说明"></asp:TextBox><br />
  <asp:RadioButton ID="rdoLogo1" GroupName="rdoImgType1" runat="server" Text="企业Logo" />
  <asp:RadioButton ID="rdoNews1" GroupName="rdoImgType1" runat="server" Text="文章图片" /><br />





  Control rdoBtnDesc = picPanel.FindControl("rdoImgType1") as RadioButton;
  if (rdoBtnDesc == null)
  {
  Response.Write("没有数据!");
  }
  else
  {
  Response.Write(rdoBtnDesc.ID);
  }

------解决方案--------------------
用ID找,picPanel.FindControl("rdoLogo1")
------解决方案--------------------
picPanel.FindControl("rdoImgType1") as RadioButton;
FindControl("ID") 是这个把 rdoLogo1
------解决方案--------------------
web页上的,用组件的ID去找,rdoLogo1
------解决方案--------------------
asp.net页面中找控件应该是找他的ID你这是找单选按钮的分组名称当然找不到。
Control rdoBtnDesc = picPanel.FindControl("rdoLogo1") as RadioButton;
Control rdoBtnDesc1 = picPanel.FindControl("rdoNews1") as RadioButton;
------解决方案--------------------

用组名怎么找得到。。。。

用控件的ID
------解决方案--------------------
FindControl 在页命名容器中搜索带指定标识符的服务器控件。它不在页所包含的命名容器中递归搜索控件。
------解决方案--------------------
FindControl方法其作用是根据ID(注意既不是UniqueID也不是ClientID)在Control所在的命名容器中寻找相应控件
------解决方案--------------------
查找控件得用控件的ID来获取的