Can ASP.Net form have method=get or post attribute?

Viewed 5151

I am new to asp.net.

My question is, can a ASP.net form with runat="server", have a method attribute in it?

For example:

<form id="form1" runat="server" method="get">
.......
</form>

Is this possible?

3 Answers

yes you can try like below.

design part you can design a form like :

<form id="form1" runat="server" method="post">
    <input type="radio" name="Gender" value="male" id="test" checked="checked" />
    male
    <input type="radio" name="Gender" value="female" />female
    <input type="submit" value="test" />
    <asp:Button ID="btn" runat="server" Text="value" />
</form>

and how to get value from the form :

if (Request.Form["Gender"] != null)
 {
     string selectedGender = Request.Form["Gender"].ToString();
 }

with this way you can get the value from form in asp.net.

i hope it will help you.

Yes,You can use use Method attribute..

The default will be Method="Post"

The form is always submitted to the page itself. If you specify an action attribute, it is ignored. If you omit the method attribute, it will be set to method="post" by default. Also, if you do not specify the name and id attributes, they are automatically assigned by ASP.NET.

If you select view source in an .aspx page containing a form containg these properties...

Please refer : http://www.w3schools.com/aspnet/aspnet_forms.asp

Related