Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant call Javascript function from button onclick event ASP.NET 4

when ever i call a JavaScript function from asp:button onclick event i got this error message

HTML

<asp:Button ID="btnFromCalOpen" runat="server" Text=" &gt; "  onclick="ShowCal()"  CssClass = "SElementHide" />

Javascript

function ShowCal() {

    var elem = document.getElementById('MainContent_CalendarFrom');
    if (elem.visibility = "hidden" )
    {
    elema.style.visibility = "visible";
    elema.style.display = "block";
    }
    else
    {
    elema.style.visibility = "hidden";
    elema.style.display = "none";
    }
}

Error Compiler Error Message: BC30456: 'ShowCal' is not a member of 'ASP.default_aspx'.

Please Help

like image 581
Nabeel Avatar asked Sep 19 '11 21:09

Nabeel


Video Answer


1 Answers

Use OnClientClick to have your ASP.NET button run a JavaScript method before calling its server-side method. OnClick specifies the server side method to run.

<asp:Button ID="btnFromCalOpen" runat="server" 
         Text=" &gt; "  CssClass = "SElementHide" 
         OnClientClick="ShowCal()" />
like image 157
p.campbell Avatar answered Oct 27 '22 12:10

p.campbell