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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:15:00+00:00 2026-06-01T11:15:00+00:00

Any clues why the button click event doesn’t insert script succesfully? Here is the

  • 0

Any clues why the button click event doesn’t insert script succesfully?

Here is the really straightforward code.

C#:

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e){
        ClientScript.RegisterStartupScript(Page.GetType(), "scriptalert", "<script type=\"text/javascript\">alert('testLOAD');</script>;", false);
        btnAdd.Click += new EventHandler(btnAdd_Clicked);
}

protected void btnAdd_Clicked(Object sender,System.EventArgs e){
    ClientScript.RegisterStartupScript(Page.GetType(), "scriptfunc", "<script type=\"text/javascript\">func();</script>;", false);
}

}

HTML:

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript">
alert("testSCRIPT");

function func() {
    alert("testFUNC");
}
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:ScriptManager ID="ToolkitScriptManager1" runat="server" />
    <div id="View" style="height: 50%; width:20%; ">
        blahblahblah
    </div>
    <div id="Addd" style="height: 50%; width:100%;">
        <asp:UpdatePanel ID="UpdateAdd" runat="server">
            <ContentTemplate>
                <asp:Button ID="btnAdd" runat="server" Text="Add" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
</asp:Content>

On page load I get two alerts firing, namely “testLOAD” and “testSCRIPT”, but when I press the button nothing happens (there is supposed to be a third alert)… Checked in debugger, the event is called and runs, but when I view page source nothing was inserted.

I have a suspicion that the problem might lie elsewhere, since copy-pasting this into a new page without a master page (i.e. without ASP:Content tags) works. I haven’t had any problems with other script insertions though, so why this one?

  • 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-06-01T11:15:02+00:00Added an answer on June 1, 2026 at 11:15 am

    I found what was wrong ^.^

    There was a stray semicolon inside the script i was inserting, which made it break :/

    ClientScript.RegisterStartupScript(Page.GetType(), "scriptfunc", "<script type=\"text/javascript\">func();</script>;", false);
    

    Such a silly error caused so much frustration… sorry guys!

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

Sidebar

Related Questions

I have the following code: <script type=text/javascript> $(document).ready(function() { $(#Save).click(function() { $.post(url, { data:
I did a click event that transforms my <span>text</span> into <input type="button" id="buttonclick"> and
Any help would be appreciated, I'm trying to convert the code below to C#,
Any idea why this code: extern C __declspec(dllexport) void Transform(double x[], double y[], int
I'm playing with XNA. When I click the left mouse button, I record the
i m building a little script to animate a list. Here is my html
Are there any existing examples of code where it is possible to do something
I am trying to figure out how to click a button on a web
Here is a code for my web form control <asp:TextBox runat=server ID=txtUsername></asp:TextBox> <asp:RequiredFieldValidator ID=RequiredFieldValidator1
I'm trying to play a random sound FX on a button click using the

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.