I hava a bottun in a webform. I want to write a one line asp code(in my own asp function) to fire the onclick event for this button. How can I do this?
Thanks for your replay. But you misunderstand my question. Your code is to bind onClick event to a specific code. So you need to click on the button manually to fire the event.
You are right. But for this button, no asp code in code behind, only javascript connect to this button.
For ASP button (Server control), use Button1.Attributes.add("onclick", "jsfunction();") connect to a js.
For Html button, use onclick="jsfunction();" .
So I want to after all asp code execute, then execute this jsfunction().
WIth ASP, if you connect javascript to a button with the way Button1.Attributes.add("onclick", "jsfunction();") , it always execute javascript firsytly, then execute ASP code. But I want to execute ASP code firstly, then execute javascript lastly.
It seems very hard, I have tried a lot of ways, but I can't do it.
Client Side has to execute first the way you are doing it. If you want to do a postback then do something with JavaScript, you will need you Register a Client Script during the postback.
KentZhou
Participant
1018 Points
573 Posts
how to raise button on click event in aps code behind?
Sep 11, 2006 03:30 PM|LINK
StrongTypes
All-Star
30801 Points
6013 Posts
ASPInsiders
Re: how to raise button on click event in aps code behind?
Sep 11, 2006 03:43 PM|LINK
<asp:Button ID="MyButton" OnClick="MyButton_Click" runat="server" />
protected void MyButton_Click(object sender, EventArgs e)
{
// Put code here
}
KentZhou
Participant
1018 Points
573 Posts
Re: how to raise button on click event in aps code behind?
Sep 11, 2006 04:09 PM|LINK
StrongTypes
All-Star
30801 Points
6013 Posts
ASPInsiders
Re: how to raise button on click event in aps code behind?
Sep 11, 2006 04:31 PM|LINK
vcsjones
All-Star
34842 Points
4424 Posts
Moderator
MVP
Re: how to raise button on click event in aps code behind?
Sep 12, 2006 02:36 AM|LINK
void Button_Click(object sender, EventArgs e) { //Click stuff }KentZhou
Participant
1018 Points
573 Posts
Re: how to raise button on click event in aps code behind?
Sep 12, 2006 01:49 PM|LINK
You are right. But for this button, no asp code in code behind, only javascript connect to this button.
For ASP button (Server control), use Button1.Attributes.add("onclick", "jsfunction();") connect to a js.
For Html button, use onclick="jsfunction();" .
So I want to after all asp code execute, then execute this jsfunction().
WIth ASP, if you connect javascript to a button with the way Button1.Attributes.add("onclick", "jsfunction();") , it always execute javascript firsytly, then execute ASP code. But I want to execute ASP code firstly, then execute javascript lastly.
It seems very hard, I have tried a lot of ways, but I can't do it.
Any solution?
vcsjones
All-Star
34842 Points
4424 Posts
Moderator
MVP
Re: how to raise button on click event in aps code behind?
Sep 12, 2006 03:58 PM|LINK
KentZhou
Participant
1018 Points
573 Posts
Re: how to raise button on click event in aps code behind?
Sep 12, 2006 04:21 PM|LINK
vcsjones
All-Star
34842 Points
4424 Posts
Moderator
MVP
Re: how to raise button on click event in aps code behind?
Sep 12, 2006 04:24 PM|LINK
KentZhou
Participant
1018 Points
573 Posts
Re: how to raise button on click event in aps code behind?
Sep 12, 2006 04:30 PM|LINK