asp:button question

  • Thread starter Thread starter hal
  • Start date Start date
H

hal

Is it possible when an asp:button is clicked I can have the button use
javascript client side code and fire the click event for the button
for server side code? Code below is an example of what i'm trying to
do:

<script type="text/javascript">

function SetImage()
{
alert("Testing");
}

</script>

<asp:ImageButton ID="btnSubmit" runat="server" ImageUrl="~/Images/
signin_btn.gif" Width="103" Height="33" OnClick="btnSubmit_Click" />

protected void btnSubmit_Click(object sender,
ImageClickEventArgs e)
{
//Doing Stuff
}

I've tried playing around with this code in Page_Load and can't get it
to work:

btnSubmit.Attributes.Add("onclick", "SubmitLoginForm()");

Is this possible to do, and if so what am i missing?

Thanks
 
Thanks that works fine when the page is posting back to itself. In
javascript code i have the page re-directing somewhere else, and with
your changes it still does hit the server side code. I also tried
testing this without the javascript code doing the re-direct and
putting a postbackURL on the button and that also did not hit the
server side code.

Any other suggestions?

Thanks
 
Back
Top