Tuesday, September 22, 2015

UseSubmitBehavior property of the Button control

Suggested Videos
Part 36 - Wizard control in asp.net
Part 37 - Asp.net Wizard control properties
Part 38 - Asp.net Wizard control events

In this video we will discuss about the UseSubmitBehavior property of the asp.net Button control. Let us understand the use of this property with an example. 

Design a webform with a TextBox, Label and 2 Button controls as shown in the image below.




For your convinience, I have included the HTML of the aspx page.
<div style="font-family: Arial">
    <strong>Name : </strong>
    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
    <br />
    <br />
    <asp:Button ID="btnClear" runat="server" onclick="btnClear_Click" Text="Clear"/>
    &nbsp;
    <asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click" Text="Submit" />
    <br />
    <br />
    <asp:Label ID="lblMessage" runat="server" Font-Bold="True" ForeColor="#009933"></asp:Label>
</div>



Dobule click the Clear and Submit buttons, to generate the event handlers, and paste the following code in the code behind page.
protected void btnSubmit_Click(object sender, EventArgs e)
{
    lblMessage.Text = "You enetered: " + txtName.Text;
}

protected void btnClear_Click(object sender, EventArgs e)
{
    txtName.Text = "";
}

Now, run the web application project. Enter a name in the textbox and hit the enter key on the keyboard. Notice that the cancel button has the submit behaviour.

In the HTML of the aspx page, set UseSubmitBehavior="false" for the clear button.
<asp:Button ID="btnClear" UseSubmitBehavior="false" runat="server" 
onclick="btnClear_Click" Text="Clear"/>

Now, run the web application project again. Enter a name in the textbox and hit the enter key on the keyboard. Notice that the submit button has the submit behaviour, as expected.

The UseSubmitBehavior property specifies if the Button control uses the browser's built-in submit function or the ASP.NET postback mechanism.

This property is TRUE by default. When set to FALSE, ASP.NET adds a client-side script to post the form. To view the client side script added by the ASP.NET, right click on the broswer and view source.


If you are searching life partner. your searching end with kpmarriage.com. now kpmarriage.com offer free matrimonial website which offer free message, free chat, free view contact information. so register here : kpmarriage.com- Free matrimonial website

Related Posts:

  • SQL JOINThe JOIN keyword is used in an SQL statement to query data from two or more tables, based on a relationship between certain columns in these tables. … Read More
  • SQL SELECT StatementSELECT statement is used to select data from a database. The result is stored in a result table, called the result-set. SQL SELECT Syntax SELECT col… Read More
  • Script Generator create table structureUsing TSQL to generate CREATE TABLE scripts in SQL Server has never been something that is easy to do. I have created the below system stored proc… Read More
  • SQL UNION OperatorThe SQL UNION Operator The UNION operator is used to combine the result-set of two or more SELECT statements. Notice that each SELECT statement with… Read More
  • SQL SELECT INTO StatementThe SQL SELECT INTO statement can be used to create backup copies of tables. The SQL SELECT INTO StatementThe SELECT INTO statement selects data from … Read More

0 comments:

Post a Comment