Reputation: 4010
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.
Upvotes: 1
Views: 3712
Reputation: 24236
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.
Upvotes: 1
Reputation: 10874
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
Upvotes: 0
Reputation: 922
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.
Upvotes: 0
Reputation: 1785
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>
Upvotes: 0