0

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

2
  • i am trying to hide asp:button without using CSS or serverside Coding. How can i hide this control on loading and thanks for your response. Commented Sep 19, 2011 at 22:26
  • See below, you'll need to start the control as hidden with the style property. While this is CSS still, you'll be able to control it directly with JavaScript Commented Sep 19, 2011 at 22:36

3 Answers 3

1

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.

2
  • i am trying to hide asp:button without using CSS or serverside Coding. How can i hide this control on loading and thanks for your response. Commented Sep 19, 2011 at 22:23
  • Thanks alot again Kirk the style worked visible = Flase wont work because then i cant retreive it back from Javascript :) Commented Sep 19, 2011 at 22:37
0

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

0

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()"  />
2
  • if i set visible = false then javascript will not make it visible again Commented Sep 19, 2011 at 22:33
  • Then just set it as a style on the element instead. Hold on, adding an example to my answer. Commented Sep 19, 2011 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.