Solved

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

Posted on 2011-02-16
7
1,288 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now