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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:13:54+00:00 2026-05-24T13:13:54+00:00

Am I injecting this correctly? string myScriptName = EventScriptBlock; string myScript = string.Empty; //Verify

  • 0

Am I injecting this correctly?

string myScriptName = "EventScriptBlock";
string myScript = string.Empty;

//Verify script isn't already registered
if (!ClientScript.IsClientScriptBlockRegistered(myScriptName))
{
    Response.Write('b');
    myScript = "\n<script type=\"text/javascript\" language=\"Javascript\" id=\"EventScriptBlock\">\n";
    myScript += "alert('hi');";
    myScript += "\n\n </script>";

    ClientScript.RegisterClientScriptBlock(this.GetType(), myScriptName, myScript);
}

This is in my Page_Load, but I never see an alert and I have no JavaScript errors either.

  • 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-24T13:13:55+00:00Added an answer on May 24, 2026 at 1:13 pm

    You can use registerstartupscript instead of registerclientscriptblock!

    RegisterStartupScript
    When you use RegisterStartupScript, it will render your script after all the elements in the page (right before the form’s end tag). This enables the script to call or reference page elements without the possibility of it not finding them in the Page’s DOM

    RegisterClientScriptBlock
    When you use RegisterClientScriptBlock, the script is rendered right after the Viewstate tag, but before any of the page elements. Since this is a direct script (not a function that can be called, it will immediately be executed by the browser. But the browser does not find the label in the Page’s DOM at this stage and hence you should receive an “Object not found” error

    Difference between registerstartupscript and registerclientscriptblock

    protected void Page_Load(object sender, System.EventArgs e)
     {
          string myScript = "\n<script type=\"text/javascript\" language=\"Javascript\" id=\"EventScriptBlock\">\n";
            myScript += "alert('hi');";
            myScript += "\n\n </script>";
         Page.ClientScript.RegisterStartupScript(this.GetType(), "myKey", myScript, false);
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Losing my mind with this one. My button gets a commandargument of empty string
I have a Core Data model similar to this: Company Entity companyName attribute (string)
In my application I use string.Format() for the SQL like this Dim strSQL As
When indenting java code with annotations, vim insists on indenting like this: @Test public
What is the accepted practice for indenting SQL statements? How should this example be
theres single quotes using in $bio = $user->description; inserting DB like this; <? $sql
I use this method for inserting a textbox in a tablecell protected void EditAttivitaClick(object
One of the ways to implement Dependency Injection correctly is to separate object creation
Beginner here: In this answer to my question of how to insert data into
I have this function that takes some user-submitted HTML code from the database: function

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.