Default button in asp.net (main page)?

in my web application, I have a main page and I want to implement defaultbutton for the login page when the user presses enter (my application has a main page), how can I put the default button.

+5
source share
6 answers

Nothing to do with main pages - see here how web browsers interpret forms.

http://geekswithblogs.net/ranganh/archive/2006/04/12/74951.aspx

Personally, I would embed the form in my own Panel control and set the defaultbutton property to the value of the submit button.

NOTE. This will only work in ASP.NET 2.0 and higher.

+1
source
Page.Form.DefaultButton = crtlLoginUserLogin.FindControl("LoginButton").UniqueID

or simply

Page.Form.DefaultButton = LoginButton.UniqueID

This will work.

+17

, , .

<form id="form1" runat="server" defaultbutton="MyButton" >

:

DefaultButton 'form1' IButtonControl.

Page_Load Content/User Control:

protected void Page_Load(object sender, EventArgs e)
        {
            Button myButton = (Button)FindControl("MyButton");

            Page.Form.DefaultButton = myButton.UniqueID;
        }
+3

IMHO, , , LoginView. .

<asp:LoginView ID="LoginView1" runat="server">
</asp:LoginView>

Asp.Net . , , .

: , , , -, :

protected void Button1_Click(object sender, EventArgs e)
    {
      Response.Redirect("MyApplication/SomePage.aspx");
    }

,

+1

VB :

   Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load      
       'cast the master page form to set the default values for the Default button and Default focus'
       Dim myForm As HtmlForm = TryCast(Me.Master.FindControl("myMasterForm"), HtmlForm)
       myForm.DefaultButton = Me.btnAdd.UniqueID
       myForm.DefaultFocus = Me.txtMyTextbox.UniqueID
   End Sub
+1
(Page.Master.FindControl("Form1") as HtmlForm).DefaultButton = this.cmdSubmit.UniqueID;

http://www.dotnetthoughts.net/2010/06/21/asp-net-default-button-and-master-pages/

0

All Articles