We help IT Professionals succeed at work.

asp.net attributes.add on Server

Medium Priority
1,130 Views
Last Modified: 2013-12-17
Hi,
I have a javascript function which validates an input on the client.
<Asp:button>runat=server  </asp:button>

Now in the code behind I declared on page load  attributes.add(Onclick, JavascriptFunction)
When the buton is clicked javascript works but post back happens and message box comes up and behind the aspx webpage becomes back.. When I  click the message box the page loads back again.. Is that the way it works..........I dont think so.........Where is that I am being wrong.........Can a correct example be shown
Comment
Watch Question

Commented:
One way of doing it is to return false from the javascript function

attributes.add("onclick", "return JavascriptFunction()")

function JavaScriptFunction()
{
//some code
return false;
}

Author

Commented:
can a clear example be shown
Commented:
In the serverside code do the following


attributes.add("onclick", "return JavascriptFunction()")

In the client javascript, do something like the following. The idea is to return false from the function

function JavaScriptFunction()
{
//some code
return false;
}

Author

Commented:
thanks

Explore More ContentExplore courses, solutions, and other research materials related to this topic.