javascript trouble

Discussion in 'ASP .Net' started by Jeff, Dec 21, 2008.

  1. Jeff

    Jeff Guest

    hi

    asp.net 2.0

    Here is the markup of a webpage I'm having trouble with. The trouble is that
    nothing happens when I click on that button (<input id="Button1).

    Any ideas what I do wrong here?

    <%@ Control Language="C#" AutoEventWireup="true"
    CodeFile="CalendarControl.ascx.cs" Inherits="Controls_CalendarControl" %>

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <input id="Button1" type="button" value="..." onclick="OnClick" /><br />

    <div id="divCalendar" runat="server" style="display:none;
    position:absolute;">
    <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
    </div>


    <script type="text/javascript" >
    function OnClick()
    {
    if (divCalendar.style.display == "none")
    divCalendar.style.display = "";
    else
    divCalendar.style.display = "none";
    }
    </script>
     
    Jeff, Dec 21, 2008
    #1
    1. Advertising

  2. On Dec 21, 2:29 pm, "Jeff" <> wrote:
    > hi
    >
    > asp.net 2.0
    >
    > Here is the markup of a webpage I'm having trouble with. The trouble is that
    > nothing happens when I click on that button (<input id="Button1).
    >
    > Any ideas what I do wrong here?
    >
    > <%@ Control Language="C#" AutoEventWireup="true"
    > CodeFile="CalendarControl.ascx.cs" Inherits="Controls_CalendarControl" %>
    >
    > <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    > <input id="Button1" type="button" value="..." onclick="OnClick" /><br />
    >
    > <div id="divCalendar" runat="server" style="display:none;
    > position:absolute;">
    >     <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
    > </div>
    >
    > <script type="text/javascript" >
    > function OnClick()
    > {
    >     if (divCalendar.style.display == "none")
    >         divCalendar.style.display = "";
    >     else
    >         divCalendar.style.display = "none";}
    >
    > </script>


    Try onclick="javascript:OnClick();"
     
    Alexey Smirnov, Dec 21, 2008
    #2
    1. Advertising

  3. Jeff wrote:

    > <input id="Button1" type="button" value="..." onclick="OnClick" /><br />


    With client-side scripting the event handlers take script code, not
    simply names of methods. So you want to call the function named
    'OnClick' and the proper function call syntax in JavaScript is
    OnClick()
    and not
    OnClick.
    So try
    <input onclick="OnClick();" ...>


    > <div id="divCalendar" runat="server" style="display:none;
    > position:absolute;">
    > <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
    > </div>
    >
    >
    > <script type="text/javascript" >
    > function OnClick()
    > {
    > if (divCalendar.style.display == "none")


    I wouldn't rely on browsers like IE expose elements by there id but
    instead use the W3C document.getElementById method e.g.
    var cal = document.getElementById('divCalendar');


    --

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Dec 21, 2008
    #3
  4. Jeff

    Hans Kesting Guest

    >
    > Try onclick="javascript:OnClick();"


    The (client side) onclick argument always contains javascript, so you
    don't have to prefix the code with "javascript:".

    Hans Kesting
     
    Hans Kesting, Dec 22, 2008
    #4
  5. On Dec 22, 2:37 pm, Hans Kesting <> wrote:
    > > Try onclick="javascript:OnClick();"

    >
    > The (client side) onclick argument always contains javascript, so you
    > don't have to prefix the code with "javascript:".
    >
    > Hans Kesting


    I agree... the problem is of course in trailing brackets
     
    Alexey Smirnov, Dec 22, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hypo
    Replies:
    6
    Views:
    462
  2. Cold Filtered
    Replies:
    0
    Views:
    471
    Cold Filtered
    Feb 18, 2005
  3. Friso Wiskerke
    Replies:
    1
    Views:
    426
    Paul Henderson
    Jan 12, 2006
  4. JavaScript trouble

    , Jan 9, 2006, in forum: Java
    Replies:
    3
    Views:
    460
    Oliver Wong
    Jan 10, 2006
  5. whimsica
    Replies:
    1
    Views:
    398
    BigBrian
    Jun 22, 2005
Loading...

Share This Page