How to use OnClientClick on button in asp.net c#

In this article, i have discussed how to use OnClientClick on button; we have just need to pass a JavaScript below function

OnClientClick="window.location.href='listyourplace.aspx'; return false;"


<asp:Button ID="Btnlist" runat="server" BackColor="#6ca77c" Text="List Your Place"     OnClientClick="window.location.href='listyourplace.aspx'; return false;" />
If "return false" is execute then it would never submit and OnClick(which is sever side would never executed).
"return false" statement should be conditional.
for example :-
You have needed to pass on dropdown values
    if (selectedItemsCount == 0)
{                      
    alert("Select at least one item!");
    return false;
}
else
{
    // this path ensures that when user selects at least 1 item then it
    // proceeds to server side code OnClick to be executed.
    return true;

}


On that time you need to pass code like below:-


OnClientClick="javascript:selectedItems();"
How to use OnClientClick on button in asp.net c#   How to use OnClientClick on button in asp.net c# Reviewed by NEERAJ SRIVASTAVA on 12:59:00 PM Rating: 5

No comments:

Powered by Blogger.