why does this code return an empty Alert window?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil

    why does this code return an empty Alert window?

    Hi,

    This code produces an empty Alert window. No error.
    How to get the value into the Alert window?

    Thanks
    Phil

    aspx file (content page):
    ------------------------
    <asp:Content ID="Content1" ContentPlaceHol derID="ContentP laceHolder1"
    Runat="Server">
    asp:Label ID="Label1" runat="server"> </asp:Label>

    <asp:Button ID="Button1" runat="server" OnClientClick=" test()" />
    <script language="javas cript" type="text/javascript">
    function test()
    {
    var x = document.getEle mentById('<%=la bel1.ClientID%> ').innerText;
    alert(x)
    }
    </script>
    </asp:Content>


    code-behind:
    -----------
    Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
    System.EventArg s) Handles Button1.Click
    Label1.Text = "Alle velden moeten ingevuld zijn"
    End sub


  • David Wier

    #2
    Re: why does this code return an empty Alert window?

    The label has no text. I tried it - copied and pasted, exactly, except for
    adding a "<" bracket in froont of the label, and adding a text property to
    it. It worked just fine for me, then.

    --
    David Wier
    MVP/ASPInsider




    "Phil" <ssdfvtgsd@fff. dfwrote in message
    news:u2ikgHcYHH A.588@TK2MSFTNG P06.phx.gbl...
    Hi,
    >
    This code produces an empty Alert window. No error.
    How to get the value into the Alert window?
    >
    Thanks
    Phil
    >
    aspx file (content page):
    ------------------------
    <asp:Content ID="Content1" ContentPlaceHol derID="ContentP laceHolder1"
    Runat="Server">
    asp:Label ID="Label1" runat="server"> </asp:Label>
    >
    <asp:Button ID="Button1" runat="server" OnClientClick=" test()" />
    <script language="javas cript" type="text/javascript">
    function test()
    {
    var x = document.getEle mentById('<%=la bel1.ClientID%> ').innerText;
    alert(x)
    }
    </script>
    </asp:Content>
    >
    >
    code-behind:
    -----------
    Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
    System.EventArg s) Handles Button1.Click
    Label1.Text = "Alle velden moeten ingevuld zijn"
    End sub
    >
    >

    Comment

    • Jan

      #3
      Re: why does this code return an empty Alert window?

      Hi David. Thanks for repying, but i really don't understand what you mean.
      Can you tell me what i have to change in my code?
      Thanks


      "David Wier" <david_wier@noS pamhotmail.coms chreef in bericht
      news:%23VoH2NcY HHA.588@TK2MSFT NGP06.phx.gbl.. .
      The label has no text. I tried it - copied and pasted, exactly, except for
      adding a "<" bracket in froont of the label, and adding a text property to
      it. It worked just fine for me, then.
      >
      --
      David Wier
      MVP/ASPInsider


      >
      >
      "Phil" <ssdfvtgsd@fff. dfwrote in message
      news:u2ikgHcYHH A.588@TK2MSFTNG P06.phx.gbl...
      >Hi,
      >>
      >This code produces an empty Alert window. No error.
      >How to get the value into the Alert window?
      >>
      >Thanks
      >Phil
      >>
      >aspx file (content page):
      >------------------------
      ><asp:Content ID="Content1" ContentPlaceHol derID="ContentP laceHolder1"
      >Runat="Server" >
      > asp:Label ID="Label1" runat="server"> </asp:Label>
      >>
      ><asp:Button ID="Button1" runat="server" OnClientClick=" test()" />
      > <script language="javas cript" type="text/javascript">
      > function test()
      > {
      > var x = document.getEle mentById('<%=la bel1.ClientID%> ').innerText;
      > alert(x)
      > }
      ></script>
      ></asp:Content>
      >>
      >>
      >code-behind:
      >-----------
      >Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
      >System.EventAr gs) Handles Button1.Click
      >Label1.Text = "Alle velden moeten ingevuld zijn"
      >End sub
      >>
      >>
      >
      >

      Comment

      • David Wier

        #4
        Re: why does this code return an empty Alert window?

        <asp:Label ID="Label1" Text="My Text is Here" runat="server"> </asp:Label>

        --
        David Wier
        MVP/ASPInsider




        "Jan" <uuvtgsd@fff.ty wrote in message
        news:u7uW4WcYHH A.408@TK2MSFTNG P04.phx.gbl...
        Hi David. Thanks for repying, but i really don't understand what you mean.
        Can you tell me what i have to change in my code?
        Thanks
        >
        >
        "David Wier" <david_wier@noS pamhotmail.coms chreef in bericht
        news:%23VoH2NcY HHA.588@TK2MSFT NGP06.phx.gbl.. .
        The label has no text. I tried it - copied and pasted, exactly, except
        for
        adding a "<" bracket in froont of the label, and adding a text property
        to
        it. It worked just fine for me, then.

        --
        David Wier
        MVP/ASPInsider




        "Phil" <ssdfvtgsd@fff. dfwrote in message
        news:u2ikgHcYHH A.588@TK2MSFTNG P06.phx.gbl...
        Hi,
        >
        This code produces an empty Alert window. No error.
        How to get the value into the Alert window?
        >
        Thanks
        Phil
        >
        aspx file (content page):
        ------------------------
        <asp:Content ID="Content1" ContentPlaceHol derID="ContentP laceHolder1"
        Runat="Server">
        asp:Label ID="Label1" runat="server"> </asp:Label>
        >
        <asp:Button ID="Button1" runat="server" OnClientClick=" test()" />
        <script language="javas cript" type="text/javascript">
        function test()
        {
        var x = document.getEle mentById('<%=la bel1.ClientID%> ').innerText;
        alert(x)
        }
        </script>
        </asp:Content>
        >
        >
        code-behind:
        -----------
        Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
        System.EventArg s) Handles Button1.Click
        Label1.Text = "Alle velden moeten ingevuld zijn"
        End sub
        >
        >
        >
        >

        Comment

        • Mark Rae

          #5
          Re: why does this code return an empty Alert window?

          "Jan" <uuvtgsd@fff.ty wrote in message
          news:u7uW4WcYHH A.408@TK2MSFTNG P04.phx.gbl...
          Can you tell me what i have to change in my code?
          <asp:Label ID="Label1" runat="server" Text="Hello world!" />


          Comment

          • Phil

            #6
            Re: why does this code return an empty Alert window?

            Ok, thanks, but could you tell me why it doesn't work programmaticall y like
            this:

            Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
            System.EventArg s) Handles Button1.Click Label1.Text = "Hello World"
            End sub

            "Mark Rae" <mark@markNOSPA Mrae.comschreef in bericht
            news:OWwB54cYHH A.3656@TK2MSFTN GP05.phx.gbl...
            "Jan" <uuvtgsd@fff.ty wrote in message
            news:u7uW4WcYHH A.408@TK2MSFTNG P04.phx.gbl...
            >
            >Can you tell me what i have to change in my code?
            >
            <asp:Label ID="Label1" runat="server" Text="Hello world!" />
            >

            Comment

            • Phil

              #7
              Re: why does this code return an empty Alert window?

              It's because the ClientClick will be executed first, and at that moment, the
              value is not yet put into 'text' of the label

              "Phil" <uuvtgsd@fff.ty schreef in bericht
              news:%23tQK19cY HHA.4008@TK2MSF TNGP05.phx.gbl. ..
              Ok, thanks, but could you tell me why it doesn't work programmaticall y
              like this:
              >
              Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
              System.EventArg s) Handles Button1.Click Label1.Text = "Hello World"
              End sub
              >
              "Mark Rae" <mark@markNOSPA Mrae.comschreef in bericht
              news:OWwB54cYHH A.3656@TK2MSFTN GP05.phx.gbl...
              >"Jan" <uuvtgsd@fff.ty wrote in message
              >news:u7uW4WcYH HA.408@TK2MSFTN GP04.phx.gbl...
              >>
              >>Can you tell me what i have to change in my code?
              >>
              ><asp:Label ID="Label1" runat="server" Text="Hello world!" />
              >>
              >
              >

              Comment

              Working...