dcsimg
Results 1 to 4 of 4

Thread: How to execute a Javascript function from within an UpdatePanel?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    4,832

    How to execute a Javascript function from within an UpdatePanel?

    I have an UpdatePanel on my webform that contains a Label control (lblText6). Basically, when you click on it, a section is opened and the "toolLoadingImage" needs to be displayed. I need to insert an OnClick/OnClientClick attribute but there isn't one in the intellisense. How can I call a javascript function that will allow me to make the Image visible....or add an OnClick Event to the Panel control and then using that to call a Javascript function?

    Code:
            <asp:UpdatePanel ID="UpdatePanel6" runat="server">
                <ContentTemplate>
                    <asp:Panel ID="pHeader6" runat="server" CssClass="cpHeader">
                        <asp:Label ID="lblText6" runat="server" Text="" />
                    </asp:Panel>
                    
                    <asp:Image ID="toolLoadingImage" ImageURL="Images/Spinner-Loading.gif" Width="15%" Height="15%" style="text-align: center; vertical-align: middle" runat="server" />
    
                    <asp:Panel ID="pBody6" runat="server" CssClass="cpBody">
                        <iframe id="iFrameTool" src="Apps/ToolLists/ToolEdit.aspx" frameborder="0" width="100%" height="800px" runat="server">
                        </iframe>
                    </asp:Panel>
    
                    <ajaxToolkit:CollapsiblePanelExtender ID="CollapsiblePanelExtender6" runat="server" TargetControlID="pBody6" CollapseControlID="pHeader6" ExpandControlID="pHeader6"
                        Collapsed="true" TextLabelID="lblText6" CollapsedText="<i class='fa fa-plus'>" ExpandedText="<i class='fa fa-minus'>" CollapsedSize="0">
                    </ajaxToolkit:CollapsiblePanelExtender>
                </ContentTemplate>
            </asp:UpdatePanel>
    Thanks,
    Last edited by blakemckenna; Sep 10th, 2018 at 03:10 PM.
    Blake

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    1,912

    Re: How to execute a Javascript function from within an UpdatePanel?

    You can insert an onclick attribute to the label using jQuery or JavaScript.

    Code:
     $(document).ready(function () {
                $('#<%= lblText6.ClientID %>').attr("onclick", "alertMessage()");
            });
    
            function alertMessage() {
                alert('hello');
            }
    or using JavaScript setattribute function instead of jQuery.

    Code:
     document.getElementById('<%= lblText6.ClientID %>').setAttribute("onclick", "alertMessage()");
    - kgc
    Last edited by KGComputers; Sep 11th, 2018 at 10:27 AM.
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal |Programming | GitHub
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    4,832

    Re: How to execute a Javascript function from within an UpdatePanel?

    Do I do this in a windows.onload function?
    Blake

  4. #4
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    1,912

    Re: How to execute a Javascript function from within an UpdatePanel?

    If you are not using jQuery, yes you can.

    Code:
     window.onload = function () {
                document.getElementById('<%= lblText6.ClientID %>').setAttribute("onclick", "alertMessage()");
            }
     function alertMessage() {
                alert('hello');
            }
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal |Programming | GitHub
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width