Jeremy,
As far as I understand, your problem is that when you click on a
Button1 (which is WebControls.But ton), it calls javascript function
doSomething() and then posts the form? and you dont want it to
post the form just run javascript?
If that is the case, then here is the solution.
we know that if we do this: Button1.Attribu tes.Add("OnClic k", "return
false;")
Button1 will become non-functional, and it will not do anything when
user clicks it.
now suppose you have this javascript code in your web form:
<script language=javasc ript>
function doCalculate()
{
alert('I am called');
return false;
}
</script>
now if you do this: Button1.Attribu tes.Add("OnClic k", "return
doCalculate();" )
doCalculate will execute and return 'false'.. so your web form will not be
posted back. There maybe some cases when you want to return true
(you want to post the form after some work)
Your question is already answered tho, but there
maybe soem cases where you want to use WebControls.But ton
(to access it easily from codebehind) .but if the button have nothing
to do with server, then why not use HtmlButton control as my
fellow Trevor suggested?
--
Hope this helps,
Zeeshan Mustafa, MCSD
"Jeremy" <JA*@2.com> wrote in message
news:e1******** ******@TK2MSFTN GP12.phx.gbl...
I have an ASPX page with a bunch of System.Web.UI.W ebControls.Butt on
controls on it. By default, clicking on any of these causes a Postback.
I'd like to have it so that for a couple of these buttons, no PostBack
occurs - and rather some client-side script is executed (with no postback
subsequently occuring). I have wired up the client-side script to the
Buttons in question using Attributes.Add( blah blah blah) - now I just need
to somehow prevent the Postback from occuring. I looked to set
AutoPostBack="f alse" - but that isn't apparently an option. How can I have
Buttons that do not trigger a postback?
Thanks.