Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 27th, 2007, 01:41 PM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default Button Query

Hi,

I have a query about asp.net buttons. Using asp.net 1.1 and vb.net 2003 code I have a login screen in which customers can either register their details for the first time or existing customers can login. On the page there are two buttons. The one near the top to register and the button near the button to click for existing customers to login. Each button has a separate onclick event associated to them.

I've noted that if an existing customer puts in their login details and hits enter on the keyboard, it jumps to the new user registration screen. Its almost like they have clicked on the top button to register.

I've done some research on the web and found this code, but this does not work apparently with two buttons on the same page :

Code:
Page.RegisterHiddenField("__EVENTTARGET", "btnLogin")
Can anybody suggest how I can add some code so when you press enter it goes to the login screen. How is it best to do this ? Here's the code of how the login screen is set up :

Code:
<table cellspacing="0" cellpadding="0" width="260">
    <tbody>
        <tr>
            <td colspan="2">
                <p class="topgrid" align="center">
                    To place the order please login 
                </p>
            </td>
        </tr>
        <tr>
            <td class="midgrid" colspan="2">
                <div align="center">New customers please register your details : 
                </div>
            </td>
        </tr>
        <tr>
            <td class="midgrid" colspan="2">
                &nbsp;</td>
        </tr>
        <tr>
            <td class="midgrid" colspan="2">
                <asp:Button id="btnRegister" onclick="btnRegister_Click" CssClass="frmbtn" Text="Register" Width="60px" runat="server"></asp:Button>
                &nbsp; 
            </td>
        </tr>
        <tr>
            <td class="linegrid" colspan="2">
                &nbsp;</td>
        </tr>
        <tr>
            <td class="midgrid" colspan="2">
                <div align="center">Returning Customer - Please login : 
                </div>
            </td>
        </tr>
        <tr>
            <td class="midgrid" colspan="2">
                &nbsp; 
            </td>
        </tr>
        <tr>
            <td class="midgrid" colspan="2">
                <asp:Label id="lblUser" runat="server" forecolor="White">Username: </asp:Label></td>
        </tr>
        <tr>
            <td class="midgrid" colspan="2">
                <div align="center">
                    <asp:TextBox id="txtUsername" Width="150px" runat="server"></asp:TextBox>
                </div>
            </td>
        </tr>
        <tr>
            <td class="midgrid" colspan="2">
                &nbsp; 
            </td>
        </tr>
        <tr>
            <td class="midgrid" colspan="2">
                <asp:Label id="lblPassword" runat="server" forecolor="White">Password: </asp:Label></td>
        </tr>
        <tr>
            <td class="midgrid" colspan="2">
                <div align="center">
                    <asp:TextBox id="txtPassword" Width="150px" runat="server" TextMode="Password"></asp:TextBox>
                </div>
            </td>
        </tr>
        <tr>
            <td class="midgrid" colspan="2">
                &nbsp; <asp:Label id="lblmessage" runat="server" cssclass="heading"></asp:Label></td>
        </tr>
        <tr>
            <td class="midgrid" colspan="2">
                <asp:Button id="btnLogin" onclick="btnLogin_Click" CssClass="frmbtn" Text="Login" runat="server" width="60px"></asp:Button>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="botgrid" colspan="2">
                &nbsp;</td>
        </tr>
    </tbody>
</table>


Thanks


 
Old July 30th, 2007, 04:05 AM
Authorized User
 
Join Date: Jun 2007
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to hericles
Default

Hi,
The quick answer to your problem is that the enter keystroke will activate whichever button has the focus, which by default is the first one on the page. Change the focus to the Log In button and then the enter keystroke will activate that.
Hope that helps,
Steve

"I will prepare and one day my chance will come."
 
Old July 30th, 2007, 08:13 AM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks - what's the easiest way to do this then ?

 
Old July 30th, 2007, 04:27 PM
Authorized User
 
Join Date: Jun 2007
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to hericles
Default

Hi,
The easiest way would be to use JavaScript, like this:
<body onload="javascript:document.Form1.Button1.focus(); ">
Change Button1 to the name of the Log In button. There are other methods using .Net server side. You can look these
up on the net.



"I will prepare and one day my chance will come."
 
Old July 31st, 2007, 04:27 AM
Registered User
 
Join Date: Jul 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

put this in htmlpart
-------------------

<table cellspacing="0" cellpadding="0" width="260">
                <tbody>
                    <tr>
                        <td colspan="2"><p class="topgrid" align="center">To place the order please login
                            </p>
                        </td>
                    </tr>
                    <tr>
                        <td class="midgrid" colspan="2"><div align="center">New customers please register your
                                details :
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="midgrid" colspan="2"></td>
                    </tr>
                    <tr>
                        <td class="midgrid" colspan="2"><asp:Button id="btnRegister" onclick="btnRegister_Click" CssClass="frmbtn" Text="Register" Width="60px"
                                runat="server"></asp:Button>
                        </td>
                    </tr>
                    <tr>
                        <td class="linegrid" colspan="2"></td>
                    </tr>
                    <tr>
                        <td class="midgrid" colspan="2"><div align="center">Returning Customer - Please login :
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="midgrid" colspan="2">
                        </td>
                    </tr>
                    <tr>
                        <td class="midgrid" colspan="2"><asp:Label id="lblUser" runat="server" forecolor="White">Username: </asp:Label></td>
                    </tr>
                    <tr>
                        <td class="midgrid" colspan="2"><div align="center"><asp:TextBox id="txtUsername" Width="150px" runat="server"></asp:TextBox>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="midgrid" colspan="2">
                        </td>
                    </tr>
                    <tr>
                        <td class="midgrid" colspan="2"><asp:Label id="lblPassword" runat="server" forecolor="White">Password: </asp:Label></td>
                    </tr>
                    <tr>
                        <td class="midgrid" colspan="2"><div align="center"><asp:TextBox id="txtPassword" Width="150px" runat="server" TextMode="Password"></asp:TextBox>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="midgrid" colspan="2">&amp;nbsp;
                            <asp:Label id="lblmessage" runat="server" cssclass="heading"></asp:Label></td>
                    </tr>
                    <tr>
                        <td class="midgrid" colspan="2"><asp:Button id="btnLogin" onclick="btnLogin_Click" CssClass="frmbtn" Text="Login" runat="server"
                                width="60px"></asp:Button>
                            &amp;nbsp;</td>
                    </tr>
                    <tr>
                        <td class="botgrid" colspan="2">&amp;nbsp;</td>
                    </tr>
                </tbody>
            </table>
----------------------------------------------

put this code in codebehind

Public Sub btnRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegister.Click

    End Sub

    Public Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click

    End Sub

 
Old August 1st, 2007, 10:19 AM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I could not get this to work despite several attempts and different ways of approaching this. So I cheated somewhat and converted the first button to a hyperlink and the login button now works when you click enter.

Thanks anyway....






Similar Threads
Thread Thread Starter Forum Replies Last Post
php/mysql delete button and delete query dungey PHP Databases 17 April 11th, 2009 12:24 PM
Button / Form Query rsm42 ASP.NET 1.0 and 1.1 Basics 2 June 5th, 2007 11:52 AM
Reset Button Query rsm42 ASP.NET 1.0 and 1.1 Basics 3 April 3rd, 2007 02:52 PM
Assigning Command Button to Query young20 Access VBA 1 November 6th, 2006 12:15 PM
Button acts depending on radio button values janise Access 4 March 10th, 2004 12:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.