Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4033676
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:52:35+00:00 2026-05-20T11:52:35+00:00

I have found many solution for my issue but none doesn’t work in my

  • 0

I have found many solution for my issue but none doesn’t work in my scenario.
I have created a test project to demo my concept.

Basically, there is a page that host a user control…

<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
    <uc1:WebUserControl1 ID="WebUserControl11" runat="server" />
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    <br />
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>

WebUserControl1 has a dropdownlist and two other webusercontrols (to be displayed based on the selection of dropdownlist element) inside updatepanel as below.

<%@ Register Src="WebUserControl2.ascx" TagName="WebUserControl2" TagPrefix="uc2" %>
<%@ Register Src="WebUserControl3.ascx" TagName="WebUserControl3" TagPrefix="uc3" %>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
    <asp:DropDownList ID="DropDownList1" runat="server"                
          OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
        AutoPostBack="True">
    </asp:DropDownList>
    <asp:Panel ID="pnlCreditCard" Visible="false" runat="server">
        <uc2:WebUserControl2 ID="WebUserControl21" runat="server" />
    </asp:Panel>
    <asp:Panel ID="pnlGiftCard" Visible="false" runat="server">
        <uc3:WebUserControl3 ID="WebUserControl31" runat="server" />
    </asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>

Code behind file for WebUserControl1 is …..

        public enum PaymentMethod
    {
        CreditCard = 0,
        GiftCard
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            BindPaymentMethods(Enum.GetValues(typeof(PaymentMethod)));
    }

    private void BindPaymentMethods(Array paymentMethods)
    {
        DropDownList1.DataSource = paymentMethods;
        DropDownList1.DataBind();

        if (paymentMethods.Length > 0)
        {
            DropDownList1.SelectedIndex = 0;
            UpdateCreditOrGiftCardPanelVisibility();
        }
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        UpdateCreditOrGiftCardPanelVisibility();
    }

    private void UpdateCreditOrGiftCardPanelVisibility()
    {
        if(DropDownList1.SelectedValue == Enum.GetName(typeof(PaymentMethod),PaymentMethod.CreditCard))
        {
            pnlGiftCard.Visible = false;
            pnlCreditCard.Visible = true;
        }
        else if (DropDownList1.SelectedValue == Enum.GetName(typeof(PaymentMethod), PaymentMethod.GiftCard))
        {
            pnlCreditCard.Visible = false;
            pnlGiftCard.Visible = true;
        }
    }

Now, the problem starts here…There is an external javascript file [JScript1.js] (embedded resource) which basically is used to display an alert box.

<script language="javascript" type="text/javascript">

window.onload = function() {
    alert('creditcard form');
}

WebUserControl2.ascx.cs code behind is

        protected void Page_Load(object sender, EventArgs e)
    {
        ScriptManager.RegisterClientScriptInclude(this.Page, this.Page.GetType().BaseType, "JScript1", Page.ClientScript.GetWebResourceUrl(this.Page.GetType().BaseType, "WebApplication1.JScript1.js"));
    }

Alert window doesn’t get displayed when I change the dropdownlist value. Even the script is getting registered three times (look in the firebug)
Need to use ScriptInclude instead of ScriptBlock as the original JS file is too big.

Can email the test app….

Thanks in Advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:52:36+00:00Added an answer on May 20, 2026 at 11:52 am

    After working around a bit, I found the solution.

    I registered a ScriptManagerProxy in WebUserControl2.ascx

    <asp:ScriptManagerProxy ID="ScriptManager1" runat="server" >
    <Scripts>
        <asp:ScriptReference Assembly="WebApplication1" Name="WebApplication1.JScript1.js" />
    </Scripts>
    </asp:ScriptManagerProxy>
    

    Then on the code behind of the same control, added…

            protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            ScriptManager.RegisterStartupScript(this, GetType(), "test", "doSomething();", true);
        }
    

    and the JScript1.js file looks like below.

        function doSomething() {
        alert('via dosomething control2 form');
    }
    

    Hope that helps. Though I had to litter around more in my practical scenario but this was certainly the way I got it working.

    Thanks,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen many somewhat similar questions, but nothing quite what I'm looking for.
I have a very large Form with many date fields that need to be
I have a wierd problem that i need to work out how to resolve,
for the last hour I have been trying to figure this out myself but
UPDATE: I now have a solution I'm much happier with that, whilst not solving
I have a situation where I have to load a named class. If there
I encountered the problem of having the same .jar (for my case, el-api.jar v2.1)twice
Trying a mental reset here: I tried to create a reliable, persistent stack with
I am working on a GTK+ application written in python. I obviously use PyGtk.
Hl Guys, I am busy writing a backend administrative program for a system that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.