request.form和findecontrol之间的差异 [英] Diffrence between request.form and findecontrol
问题描述
实际上我想了解Request.Form和FindControl之间的区别。或者我们可以说当我们使用Request.Form时和在ASP.NET中使用FindContrl时尖锐的语言
我尝试过:
试图理解Request.Form和使用FindControl之间的区别
actually i want to understand what is the difference between Request.Form and FindControl . Or we can say when we use Request.Form and When we Use FindContrl in ASP.NET C sharp Language
What I have tried:
trying to understand the difference between Request.Form and Use of FindControl
推荐答案
你可以访问这些2的网页控件和差异如下 -
You can access the web controls with these 2 and difference is as below -
Request.Form simply looks at the POST data of your Http Request, and gets the various form field data. You can access perticular web control by name of control as parameter. You can access web control with Request.Form when your web request is submitted from browser.
FindControl is method of Control class from which your web controls are derived and will help you to get control by ID parameter
使用Control.FindControl()
方法,如果您确定服务器控件的ID
名称。例如,如果您在中访问服务器控件,例如
控件如TextBox
,DropDownList
等DataBoundGridView
,Repeater
,DataList
等。例如,如果要访问位于内部的GridView
中的TextBox
控件ItemTemplate
列,您可以这样做:
UseControl.FindControl()
method if you are certain about theID
name of the server control. For example, if you are accessing server controls such asTextBox
,DropDownList
, etc within aDataBound
control likeGridView
,Repeater
,DataList
, etc. For example, if you want to access aTextBox
control withinGridView
that resides inside anItemTemplate
column, you could do something like this:
protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.DataRow) {
TextBox tb = (TextBox)e.Row.FindControl("TextBox1");
if(tb != null)
//You've found the TextBox with ID TextBox1
}
}
如果您正在使用动态控件并且想要动态访问动态控件的值,请使用 Request.Forms
集合跨回发创建服务器控件。例如,请参阅: https://www.aspsnippets.com/Articles /Dynamic-Controls-Made-Easy-in-ASP.Net.aspx [ ^ ]
Use Request.Forms
collection if you are working with dynamic controls and you want to access the value of the dynamically created server controls across postbacks. For example, see: https://www.aspsnippets.com/Articles/Dynamic-Controls-Made-Easy-in-ASP.Net.aspx [^]
这篇关于request.form和findecontrol之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!