locked
java script not calling from user control RRS feed

  • Question

  • User-1471881183 posted

    im developing web form application project.

    there i have a web form called WebForm1.aspx, this has WebUserControl1.ascx

    WebUserControl1.ascx has WebUserControl2.ascx.

    In WebUserControl2.ascx below is the html tags

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="projectname.Web_Forms.WebForm1" %>
    
    <%@ Register src="../User Controls/WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <uc1:WebUserControl1 ID="WebUserControl11" runat="server" />
            <div>
            </div>
        </form>
    </body>
    </html>

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="projectname.User_Controls.WebUserControl1" %>
    <%@ Register src="WebUserControl2.ascx" tagname="WebUserControl2" tagprefix="uc1" %>
    
    <uc1:WebUserControl2 ID="WebUserControl21" runat="server" />
    
    



    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl2.ascx.cs" Inherits="projectName.User_Controls.WebUserControl2" %>
    <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
        <script src="../Scripts/LibGlobalPay/rxp-hpp.js"></script>
    <script>
    
        $(document).ready(function () {
            //alert("script start");
            if ($("#MyHidden").val() == "1") {
                $("#MyHidden").val("2");
                $.getJSON("pay.json", function (jsonFromRequestEndpoint) {
                    alert("before start sethppurl");
                   });
            }
        });
    
    
    </script>
    <div>
        <input type="submit" id="payButtonId" value="Checkout Now" onclick="return false" />
        <asp:HiddenField ID="MyHidden" runat="server" Value="1" />
    </div>
    

    now, the issue is, the above Java script function is not calling so, no alert message displays. May i know what would be the reason?

    Wednesday, November 4, 2020 11:06 PM

Answers

  • User475983607 posted

    winseealn@hotmail.com

    now, the issue is, the above Java script function is not calling so, no alert message displays. May i know what would be the reason?

    The design is not optimal.  JavaScript code should exist in the parent page not a user control.  Also Web Forms creates dynamic IDs so $("#MyHidden") is not the actual ID.

    Anyway, the first step is debugging.  Open the browser's dev tools and look for errors in the console.  Fix the errors and re-test.  Repeat until you fixed all the errors.

    Next, use the dev tools debugger to single step through the code to find logical errors.  Repeat until you fixed all the logical errors.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 4, 2020 11:35 PM