request.form和findecontrol之间的差异 [英] Diffrence between request.form and findecontrol

查看:125
本文介绍了request.form和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 等DataBound 控件如 GridView Repeater DataList 等。例如,如果要访问位于内部的 GridView 中的 TextBox 控件 ItemTemplate 列,您可以这样做:



Use Control.FindControl() method if you are certain about the ID name of the server control. For example, if you are accessing server controls such as TextBox, DropDownList, etc within a DataBound control like GridView, Repeater, DataList, etc. For example, if you want to access a TextBox control within GridView that resides inside an ItemTemplate 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆