Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Form builder demo
<!--[if lt IE 9]>

<label>Type form title here...</label>

<![endif]-->






<!-- Action bar - Suited for buttons on form -->


<label class="control-label">Text Input</label>
<input type="text" placeholder="Text here..." class="ctrl-textbox">

<button class="btn ctrl-btn">Simple Button</button>

Posted
Updated 1-Oct-13 8:08am
v3

You don't really need any ASP.NET controls for that. In your form, you should include the button with the special type "submit", for example:
XML
<form name="input" action="some-URI" method="post">
   Some data: <input type="text" name="someText"><br/>
   <!-- ... -->
   <input type="submit" value="Submit">
</form>


This "submit" type is the key, this will become the button what initializes HTTP request. Another keys is having name attributes for all input controls, those you want to contribute to the data sent in the HTTP request; of course their values should be unique in the form. In my sample, "some-URL" should load the script which handles HTTP request. All the data from all controls (again, having "name" attribute) in your form will be posted and available in the ASP.NET code behind this page. It can be the same page as the one with this form, but it requires some attention.

You did not ask about handling of the request on the server side with ASP.NET, so I assume you know that.

—SA
 
Share this answer
 
v2
Comments
abey e mathews 1-Oct-13 15:02pm    
can i use like this


<form method="post" action="search.aspx">
<table><tr>
<td>Keyword</td>
<td><input type="text" id="Keyword" name="Keyword" /></td>
</tr><tr>
<td><input type="submit" id="Go" value="Search" /></td>
</tr></table>
</form>
Sergey Alexandrovich Kryukov 1-Oct-13 15:23pm    
Looks fine. Input type "submit" is in place, "name" is used...
—SA
I know this is very OLD, but NOW myself Im struggling with helping a project that of course also is very old, but anyway, as they are using Web forms or ASPX, here is what I have for anyone having the same issue

1. when working with ASPx, I personally dont recommend to use

Form post/get method, because you will have to deal with same page
page load and check for fields there

Instead use a simple asp:button control to postback
and read info from there... I wrote lots more but my answer was chopped


Below, is the chunk of code MS uses there to post to same page code behind:


C#
<div class="form-horizontal">
        <h4>Create a new account</h4>
        <hr />
        <asp:ValidationSummary runat="server" CssClass="text-danger" />
        <div class="form-group">
            <asp:Label runat="server" AssociatedControlID="Email" CssClass="col-md-2 control-label">Email</asp:Label>
            <div class="col-md-10">
                <asp:TextBox runat="server" ID="Email" CssClass="form-control" TextMode="Email" />
                <asp:RequiredFieldValidator runat="server" ControlToValidate="Email"
                    CssClass="text-danger" ErrorMessage="The email field is required." />
            </div>
        </div>
        <div class="form-group">
            <asp:Label runat="server" AssociatedControlID="Password" CssClass="col-md-2 control-label">Password</asp:Label>
            <div class="col-md-10">
                <asp:TextBox runat="server" ID="Password" TextMode="Password" CssClass="form-control" />
                <asp:RequiredFieldValidator runat="server" ControlToValidate="Password"
                    CssClass="text-danger" ErrorMessage="The password field is required." />
            </div>
        </div>
        <div class="form-group">
            <asp:Label runat="server" AssociatedControlID="ConfirmPassword" CssClass="col-md-2 control-label">Confirm password</asp:Label>
            <div class="col-md-10">
                <asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password" CssClass="form-control" />
                <asp:RequiredFieldValidator runat="server" ControlToValidate="ConfirmPassword"
                    CssClass="text-danger" Display="Dynamic" ErrorMessage="The confirm password field is required." />
                <asp:CompareValidator runat="server" ControlToCompare="Password" ControlToValidate="ConfirmPassword"
                    CssClass="text-danger" Display="Dynamic" ErrorMessage="The password and confirmation password do not match." />
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <asp:Button runat="server" OnClick="CreateUser_Click" Text="Register" CssClass="btn btn-default" />
            </div>
        </div>
    </div>
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900