what is the use of Request.Form[""] in .net

Posted by Swappy_Gaj under ASP.NET on 1/8/2015 | Points: 10 | Views : 1687 | Status : [Member] | Replies : 5
What exactly is the use of Request.Form[""] in ASP.NET




Responses

Posted by: kgovindarao523-21772 on: 1/8/2015 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

If you want to access client controls, you will use Request.Form[""].
For example,
You have an aspx page which contains some server side & client side side controls.
If you want to access server controls in .cs page, you can access by its id. but you won't in case of client controls.
So if you alse want to access this, you have to use Request.Form[""].

in .aspx page
<asp:TextBox ID="txtServerControl" runat="server" Text=""/>
<input type="text" name="txtClientControl" id="txtClientControl" value=""/>

now in .cs page:
string serverControlVal=txtServerControl.Text;
string clientControlValue=Request.Form["txtClientControl"];

Please mark as answer if you satisfied with the response.




Thank you,
Govind

Swappy_Gaj, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 1/8/2015 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi,
I agree with K Govindarao.But we can also access client control in code behind,if we add runat = "server" attribute in control definition as
<input type="text" name="txtClientControl" id="txtClientControl" value="" 
runat = "server" />

Now,we can access client-control value by their Value property as
string clientControlValue = txtClientControl.Value;

Kindly check this too.

Swappy_Gaj, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 1/8/2015 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi,
We can also access server-side control with request.form as
string serverControlVal = Request.Form["txtServerControl"];

So,Request.Form will be used for accessing both control values i.e. server and client side control values.

Swappy_Gaj, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: kgovindarao523-21772 on: 1/8/2015 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,
If you take
<input type="text" name="txtClientControl" id="txtClientControl" value="" runat = "server"  />
and if this control is a page which has a master page then
string clientControl= Request.Form["txtClientControl"];
statement wont work.

Thank you,
Govind

Swappy_Gaj, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 1/9/2015 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi K.Govindarao,
You take client-side control but give an example of server-side control.
Kindly clarify these.



Swappy_Gaj, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response