Results 1 to 40 of 56

Thread: UserControl javascript: get control by id

Threaded View

  1. #11

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

    Re: UserControl javascript: get control by id

    I didn't.

    I tried adding it in the UserControl:
    Code:
    <&#37;@ Control Language="vb" AutoEventWireup="false" CodeBehind="ButtonUserControl.ascx.vb" Inherits="F1TimeTrials.ButtonUserControl" %>
    
    <script src="~/Scripts/jquery-1.4.1.js" type="text/javascript" />
    
    <script type="text/javascript">
        function buttonClicked(sender) {
            var label = $(obj).parent().parent().find('span:eq(0)');
            alert('jup');
            label[0].innerHTML += '|';
            return false;
        }
    </script>
    
    <asp:Table runat="server">
        <asp:TableRow runat="server">
            <asp:TableCell runat="server"><asp:Button runat="server" ID="button" Text="Click!" OnClientClick="return buttonClicked(this);" /></asp:TableCell>
            <asp:TableCell runat="server"><asp:Label runat="server" ID="label" Text="" /></asp:TableCell>
        </asp:TableRow>
    </asp:Table>
    When I run this and click the button, there's no alert and the page posts back (so return false is never reached I guess). Doesn't work.

    So I tried it on the page instead:
    Code:
    <%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="SliderTest.aspx.vb" Inherits="F1TimeTrials.SliderTest" %>
    
    <%@ Register Src="~/Controls/ButtonUserControl.ascx" TagName="ButtonUserControl" TagPrefix="uc" %>
    
    
    <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
        
    <script src="~/Scripts/jquery-1.4.1.js" type="text/javascript" />
    
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        <asp:ScriptManager runat="server" />
    
        <uc:ButtonUserControl runat="server" />
    
    </asp:Content>
    Now, still no alert, but the page no longer posts back. This is a little strange to me... If it doesn't post back then it has reached return false right? But why then is there no alert? And no extra |...?


    I don't get it, why is this so hard? When I search for 'multiple user controls' I get at least 5-6 results with people having the exact same issue, but all they got was a few vague hints but no real solution... I don't understand how something this fundamental can be so difficult to accomplish :s

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