Distinguish Clicks Buttons

  • Thread starter Thread starter ruca
  • Start date Start date
R

ruca

Can I distinguish between this two kinds of OnClick for Button Control:

1- btnPopup_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPopup.Click

2- btnPopup.Attributes.Add("OnClick", "...") //here I have a javascript
function that I want to use.

I want to distinguish both and use one in some situations and the other in
others situations.
Can I do this in code?
 
Well, the attirbutes one is a client-side event. So what you could do is
have that one call a function which checks some client-side condition, and
if it is such-and-so, then do your processing and return false, else dont do
your processing, and return true.

eg:

<asp:button id=who runat=server onclick="javascript:return
myFunc();"></asp:button>

In the above button the onclick (added only for readability, you would
actually add it to the attribs like you are, the above wouldnt actually
work) calls the function myFunc. myFunc would check some checkbox, or text
value or whathave.. if it needs to run, then it would, and return false, if
it doesnt, then it simply returns true.
When an attribute "onclick" returns false, it prevents the form from posting
back, and the server-side _Click never happens.

Hope this helps.
 
Back
Top