开发者

Unable to call Javascript function onload a asp:button using ASP.NET4

I 开发者_如何学编程am unable to call a Javascript function on the OnLoad event of a asp:button

HTML

<asp:Button ID="btnFromCalOpen" runat="server" Text=" &gt; "   onLoad = "AllHide()"  OnClientClick ="ShowCal()"  />

Javascript

  function AllHide() {
        alert("Hello");
  }  

Please Help


You will need to use JavaScript to toggle styles like you are trying

<asp:Button ID="btnFromCalOpen" runat="server" Text=""  OnClientClick ="ShowCal()" style="display:none;visiblity:hidden;" />

Original Comment You can't do onLoad with JavaScript for any button. What are you hoping to accomplish? We can help figure out that solution.


You can do it at the page level. The page has a javascript onload event.


You can't do that.

Here's why. The OnLoad event in ASP.NET for a control is fired while the server is building the page (on the web server), but before it sends it to the browser (running on the user's machine).

Code on the web server can't directly call code on the browser computer (which hasn't even got the page yet).

If you just want to hide the control, just do this in your markup:

<asp:Button ID="btnFromCalOpen" runat="server" Text=" &gt; "  visible="false"  OnClientClick ="ShowCal()"  />

Another approach (hidden control doesn't takes up space):

<asp:Button ID="btnFromCalOpen" runat="server" Text=" &gt; "  style="display:none;"  OnClientClick ="ShowCal()"  />

Another approach (hidden control takes up space)

<asp:Button ID="btnFromCalOpen" runat="server" Text=" &gt; "  style="visibility:hidden;"  OnClientClick ="ShowCal()"  />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜