Solved

asp.net set default button (enter) as user's control btnLogin

Posted on 2011-02-16
7
1,292 Views
Last Modified: 2012-08-13
trying to set login button (Button1) in user control as default button in the page default.aspx

 
LoginBox.ascx
------------- 
<asp:Button ID="Button1" runat="server" Text="Login" OnClick="Button1_Click" CssClass="mainbutton" />

Open in new window

0
Comment
Question by:doramail05
7 Comments
 
LVL 4

Expert Comment

by:ong-hh
ID: 34913147
0
 
LVL 13

Expert Comment

by:agarwalrahul
ID: 34913196
just put this property in your form tag (in aspx page):

defaultbutton="Button1"

 your form tag looks something like this:

<form id="form1" runat="server" defaultbutton="Button1">
0
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 34913519
Hi, Use this javascript for set default button

function clickButton(e, buttonid)
{
var bt = document.getElementById(buttonid);
if (typeof bt == 'object'){
if(navigator.appName.indexOf("Netscape")>(-1)){
if (e.keyCode == 13){
bt.click();
return false;
}
}
if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1))
{
if (event.keyCode == 13){
bt.click();
return false;
}
}
}
}
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:informaniac
ID: 34913538
Can u set the UseSubmitBehavior=true to the button in the usercontrol and check.
0
 
LVL 8

Expert Comment

by:Anurag Agarwal
ID: 34913547
hello doramail05!!


I think i got a better solution fr tht as default button technique won't help !!

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       SetFocus("ClientIDGenerated_button_of_LoginBox.ascx")
    End Sub

to find client ID you just need to drag the LoginBox.ascx in aspx page and see the source code of the page. there u will find the client id (ID) generated for the login button which you want to set as default.
0
 
LVL 1

Accepted Solution

by:
doramail05 earned 0 total points
ID: 34913989
got it already,

Dim _uc As UserControl = DirectCast(Page.FindControl("loginBox1"), UserControl)

        Dim _btnClick As Button = DirectCast(_uc.FindControl("Button1"), Button)

        Form.DefaultButton = _btnClick.UniqueID

Open in new window

0
 
LVL 1

Author Closing Comment

by:doramail05
ID: 34941486
solved already from other post/forum
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question