Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Page.Controls.Add error

Page.Controls.Add error

Scheduled Pinned Locked Moved ASP.NET
helpjavascripttools
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    The_Collector
    wrote on last edited by
    #1

    i dont understand the error i encounters in my ASPX file below is the syntax: Page.Controls.Add(new LiteralControl("<script language='javascript'> window.alert('my message')</script>")); I used the above syntax and it works fine in my 1st page but when i used it in the other page it gives an error: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). somebody who can help me solve this problem..... thanks in advance. :)

    xxx

    L 1 Reply Last reply
    0
    • T The_Collector

      i dont understand the error i encounters in my ASPX file below is the syntax: Page.Controls.Add(new LiteralControl("<script language='javascript'> window.alert('my message')</script>")); I used the above syntax and it works fine in my 1st page but when i used it in the other page it gives an error: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). somebody who can help me solve this problem..... thanks in advance. :)

      xxx

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The above code is working for me in the page load event. Are you calling the above code in the page load event in both pages.

      T 1 Reply Last reply
      0
      • L Lost User

        The above code is working for me in the page load event. Are you calling the above code in the page load event in both pages.

        T Offline
        T Offline
        The_Collector
        wrote on last edited by
        #3

        No, below is the code structure protected void Button1_Click(object sender, EventArgs e) {       if(......)       {          ..          ..       }       else       {          ..          Page.Controls.Add(new LiteralControl("<script language='javascript'> window.alert('My Message')</script>"));       } }

        xxx

        L 1 Reply Last reply
        0
        • T The_Collector

          No, below is the code structure protected void Button1_Click(object sender, EventArgs e) {       if(......)       {          ..          ..       }       else       {          ..          Page.Controls.Add(new LiteralControl("<script language='javascript'> window.alert('My Message')</script>"));       } }

          xxx

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          if understood correctly, you are trying to register the javascript to display an alert message at runtime . You can also try like this: Page.ClientScript.RegisterStartupScript(this.GetType(), "testkey", " window.alert('My Message')");

          T 1 Reply Last reply
          0
          • L Lost User

            if understood correctly, you are trying to register the javascript to display an alert message at runtime . You can also try like this: Page.ClientScript.RegisterStartupScript(this.GetType(), "testkey", " window.alert('My Message')");

            T Offline
            T Offline
            The_Collector
            wrote on last edited by
            #5

            Although you did not have any explanation as to why i encountered such problem, I am still very greetful that you share your knowledge... thanks a lot!!! :thumbsup:I salute   :)

            xxx

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups