Results 1 to 40 of 56

Thread: UserControl javascript: get control by id

Threaded View

  1. #26

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: UserControl javascript: get control by id

    Sorry, I dunno why I wrote that, it's correct in my code:
    asp Code:
    1. <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="ButtonUserControl.ascx.vb" Inherits="F1TimeTrials.ButtonUserControl" %>
    2.  
    3. <script type="text/javascript">
    4.     function buttonClicked(sender) {
    5.         var label = $(sender).parent().parent().find('span:eq(0)');
    6.         alert('jup');
    7.         label[0].innerHTML += '|';
    8.         return false;
    9.     }
    10. </script>
    11.  
    12. <asp:Table runat="server">
    13.     <asp:TableRow runat="server">
    14.         <asp:TableCell runat="server"><asp:Button runat="server" ID="button" Text="Click!" OnClientClick="return buttonClicked(this);" /></asp:TableCell>
    15.         <asp:TableCell runat="server"><asp:Label runat="server" ID="label" Text="" /></asp:TableCell>
    16.     </asp:TableRow>
    17. </asp:Table>
    Still nothing. No alerts, no post-backs, no | characters.

    I tried debugging with Firebug but unless I'm doing it wrong even that isn't working. I just go to the sripts tab, find the piece of javascript, put a breakpoint beside it, but it doesn't hit when I click the buttons.

    It does hit suddenly when I refresh the page. Then I also get the option like Run, Step Into, Step Over, etc, but whatever I do (step into, over, out) it just seems to skip the entire code in the function. The breakpoint is on the function declaration ("function buttonClicked(sender)").

    EDIT
    And when I put an alert on the very first line of the function it does show, so the function is getting called OK.

    EDIT2
    When I try this javascript, only 'hit' is shown:
    javascript Code:
    1. <script type="text/javascript">
    2.     function buttonClicked(sender) {
    3.         alert('hit');
    4.         alert($(sender));
    5.  
    6.         var label = $(sender).parent().parent().find('span:eq(0)');
    7.         alert('jup');
    8.         label[0].innerHTML += '|';
    9.         return false;
    10.     }
    11. </script>

    EDIT3
    When I alert just 'sender' it shows me something like object HTMLElement so it's not null.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width