By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,656 Members | 801 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,656 IT Pros & Developers. It's quick & easy.

asp:button question

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"hal" <hl*****@gmail.comwrote in message
news:c5**********************************@y38g2000 hsy.googlegroups.com...
Is this possible to do, and if so what am i missing?
<asp:ImageButton ID="btnSubmit" runat="server"
ImageUrl="~/Images/signin_btn.gif" Width="103" Height="33"
OnClick="btnSubmit_Click" OnClientClick="SetImage();" />
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #2

P: n/a
hal
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

Jun 27 '08 #3

P: n/a
"hal" <hl*****@gmail.comwrote in message
news:d1**********************************@x41g2000 hsb.googlegroups.com...
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?
Slightly puzzled... Do you want this control to have any server-side
functionality or not...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.