1

I'm trying to develop some web page in Asp.Net and C# which almost look like facebook login page where user can sign in at top of the page and sign up at the bottom, how should I do that? and when the focuses are on the textboxs of sign in part and the user hit the Enter it should go to Sign in method,

I already searched in stackoverflow about it and it seems all questions which already asked were about Asp.Net MVC which I'm not using.

4 Answers 4

1

You can assign a single event to multiple button clicks -

topButton.Click += SignInButtonClick;
bottomButton.Click += SignInButtonClick;

void SignInButtonClick(object sender, EventArgs e)
{
    //your code here

}

I presume in your case the same logic will run for both buttons, you could find out which button was clicked using sender argument that is passed into the function.

As an example, let's say I have an aspx page and I add a button to it called 'Button1' I can then add a click event via Visual Studio and it will create a methiod to handle the click event for me called Button1_Click. The method will be automatically linked to the button as the AutoEventWireup up property in c# is set to true by default.

Now, if I add a second button and call it 'Button2' but I want that button to fire the same event handler as the one used for Button1, I could add this code to the pages 'Page_Load' event handler

Button2.Click += Button1_Click;

Both buttons would then cause the 'Button1_Click' method to run when clicked.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks.sorry I can't understand how the first 2 lines work. could you give me any link to see how this work?
@ePezhman - I don't think this is what you want, this code simply allows 2 buttons to perform the same event when clicked. See my answer for how to trigger the correct button event when the user presses enter on a textbox.
0

you rather use html Controls then Asp.net Control and can use Jquery to perform the loginb or signup

    $('#login').click(function(event)
    {
      // call
      // $.ajax(),$.get or $.post method for ajax call
     });
    $('#signup').click(function(event)
    {
      // call
      // $.ajax(),$.get or $.post method for ajax call
     });
    </script>

    <form id="form1">
    <input type="button" value="login" id="login"/>
    </form>
    <form id="form2">
    <input type="button" value="signup" id="signup"/>
    </form>

Comments

0

you can connect multiple buttons to the same method by doing something like in the page load:

lbTest1.Click += Test_Click;
lbTest2.Click += Test_Click;

void Test_Click(object sender, EventArgs e) 
{ 
    //your code here 
} 

you can use the enter button to fire the method of a button by wrapping both the textbox as the button in a panel and set the defaultbutton property of the panel.

Comments

0

The simplest solution is to wrap the related controls (e.g. the signup controls) in a Panel control, and set the DefaultButton property on the Panel. You can read about it in this tutorial

2 Comments

@ePezhman Can you get the sample version to work? You will probably have to post your code if we are to help further
I couldn't get any sample code, it seemed the link was broken

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.