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 7090833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:06:19+00:00 2026-05-28T08:06:19+00:00

I have created a static method to display a popup on my website from

  • 0

I have created a static method to display a popup on my website from both pages and usercontrols. The method does not care if there is a script manager or update panel on the page.

At the moment the method works correctly in:

  • Page Load
  • Page PreRender
  • Page Event Handlers (e.g. OnClick, OnSelectedIndexChanged, etc.)
  • UserControl Load
  • UserControl PreRender

The method fails in:

  • UserControl Event Handlers (e.g. OnClick, OnSelectedIndexChanged, etc.)

Neither of these lists are exhausted.

The strangest part is that the method will work in the load and pre render events of the user control and fail in an OnClick event.

Here is the static code:

    private static Page CurrentPage
    {
        get
        {
            try
            {
                return (Page)HttpContext.Current.Handler;
            }
            catch
            {
                return null;
            }
        }
    }

    public static void ShowMessage(String Heading, String Message, String RedirectURL, Boolean AllowHTML)
    {
        if (CurrentPage != null)
        {
            try
            {
                String Script = "ShowCtMessagePopup('" + Heading + "', '" + Message + "', " + AllowHTML.ToString().ToLower() + ", " + (String.IsNullOrWhiteSpace(URL) ? "null" : "'" + URL + "'") + ");";

                try
                {
                    ScriptManager sm = ScriptManager.GetCurrent(CurrentPage);

                    if (sm == null || sm.IsInAsyncPostBack)
                        CurrentPage.ClientScript.RegisterStartupScript(typeof(System.Web.UI.Page), "ErrorMessage", Script.ToString(), true);
                    else
                        CurrentPage.ClientScript.RegisterStartupScript(typeof(System.Web.UI.Page), "ErrorMessage", "Sys.Application.add_load(function (){" + Script.ToString() + "});", true);
                }
                catch
                {
                    //trouble finding script manager
                    CurrentPage.ClientScript.RegisterStartupScript(typeof(System.Web.UI.Page), "ErrorMessage", Script.ToString(), true);
                }
            }
            catch
            {
                //ignore failed displays for now
            }
        }
    }

Here is the Calling Code:

<asp:Button ID="btValidate" runat="server" OnClick="btValidate_Click" Text="Validate" Width="125px" CssClass="formButton" />

protected void btValidate_Click(object sender, EventArgs e)
{
    CtMessagePopup.ShowMessage("Hello", "There", null, false);
}
  • 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-28T08:06:20+00:00Added an answer on May 28, 2026 at 8:06 am

    The solution to this issue is to use the following code:

    Control Caller = this; //the user control that you are calling from
    ScriptManager.RegisterStartupScript(Caller, typeof(Caller), "Script Name", Script.ToString(), true);
    

    The Script manager has trouble adding scripts to the Page object from a user control and must have a reference to the calling user control.

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

Sidebar

Related Questions

I've created a website with ASP.NET MVC. I have a number of static pages
I have created a static library following this link . But I am facing
I have created a public static class utils.cs I want to use it in
I have created my own Attached Property like this: public static class LabelExtension {
I have created a minidump using win32 api [DllImport(DbgHelp.dll, SetLastError = true)] private static
I have a static library *.lib created using MSVC on windows. The size of
I created my own toolbar. Inside toolbar I have collection property to display custom
I have successfully created a number of UserControls with various functionality setting the DataContext
Have a small doubt with static method. Documentation says that Static method can't access
heys guys, i have a website, which contains lots of db work to display

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.