专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > ASP.NET

ASP.NET 获取input 为 text 的值和ID解决方法

发布时间:2011-06-22 17:15:21 文章来源:www.iduyao.cn 采编人员:星星草
ASP.NET 获取input 为 text 的值和ID
我在aspx页面写了一段代码:
HTML code
<table width="100%" border="0" cellpadding="0" cellspacing="10">
<%                                   
    foreach (YM.Model.SystemSetting model in systemSettingList)
    { 
%>
    <tr>
        <td style="height: 16px; width:100px" align="right"><%=model.SystemKey%>:</td>
        <td style="height: 16px; width:270px;" align="left">
            <input id="TextBox_<%=model.SystemID %>" name="TextBox_<%=model.SystemID %>" type="text" value="<%=model.SystemValue %>" class ="box1" onfocus="this.className='box2'" onblur="this.className='box1'" style ="width:260px;" maxlength="200"/>
        </td>  
        <td align="left" class="notes">注:<%=model.SystemExplain%></td>                                  
    </tr>
<%
    }
%>
</table>

如何在CS页面获取所有TextBox的值和ID

------解决方案--------------------
foreach (YM.Model.SystemSetting model in systemSettingList)


string strInputID = "TextBox_" + model.SystemID;
string strValue = Request.Param[strInputID];

}
------解决方案--------------------
C# code
protected void btnClear_Click(object sender, EventArgs e)   
   {          foreach (Control ctl in this.Controls)      
    {              this.txtClear(ctl);      
    }  
    }      #endregion    
    private void txtClear(Control ctls)  
    {       
   if(ctls.HasControls())      
    {          
    foreach (Control ctl in ctls.Controls)        
      {              
    txtClear(ctl);          
    }       
   }        
  else        
  {       
       if (ctls.GetType().Name == "TextBox")    
          {               
   TextBox tb = new TextBox();           
       tb = (TextBox)this.FindControl(ctls.ID);                  //这里是清空所有的值,你想赋什么值直接改tx.Text即可.        
          tb.Text = "";              }         
     else if (ctls.GetType().Name == "DropDownList")          
    {                  DropDownList ddl = new DropDownList();      
            ddl = (DropDownList)this.FindControl(ctls.ID);    
              ddl.SelectedIndex = 1;           
   }        
  }   
   }
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: