Problem calling Anchors

Discussion in 'ASP .Net' started by Lars Netzel, Jul 4, 2005.

  1. Lars Netzel

    Lars Netzel Guest

    I have manually written an achor in the HTML mode like this:

    <a name="expenses"></a>

    Then at a button_click() I have this code in the code behind:
    Page.Controls.Add(New LiteralControl("<script language = ""javascript"">"))

    Page.Controls.Add(New LiteralControl("document.location.hash=""expenses"""))

    Page.Controls.Add(New LiteralControl("</script>"))

    ----------------------------------------------------

    This normaly works fine but not on this page cause I have added some own
    javascript with errortexts that comes from <%... %> links... so I get the
    following error message when clicking the button.

    The Controls collection cannot be modified because the control contains code
    blocks (i.e. <% ... %>).
    Description: An unhandled exception occurred during the execution of the
    current web request. Please review the stack trace for more information
    about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: The Controls collection cannot
    be modified because the control contains code blocks (i.e. <% ... %>).

    Source Error:

    Line 680: btnAddnewLodging.Enabled = False
    Line 681:
    Line 682: Page.Controls.Add(New LiteralControl("<script language =
    ""javascript"">"))
    Line 683: Page.Controls.Add(New
    LiteralControl("document.location.hash=""lodging"""))
    Line 684: Page.Controls.Add(New LiteralControl("</script>"))


    ------------------

    This of course is bad and I need to find another way of adding the
    "#expenses" to the URL.. and why is the javascript I wrote considered to be
    part of the control i'm adding?

    Please help

    Best Regards/

    Lars Neztel
    Lars Netzel, Jul 4, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris M

    Bookmark Anchors and VB.NET

    Chris M, Oct 24, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    815
  2. =?Utf-8?B?UGF1bCBL?=

    Identifying calls from anchors

    =?Utf-8?B?UGF1bCBL?=, Jun 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    324
    =?Utf-8?B?UGF1bCBL?=
    Jun 18, 2004
  3. Lars Netzel

    What about Anchors (#) and ASP.NET?

    Lars Netzel, Jul 26, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    505
    Justin Beckwith
    Jul 27, 2004
  4. richard

    two anchors, one link problem

    richard, May 19, 2008, in forum: HTML
    Replies:
    1
    Views:
    513
  5. richard
    Replies:
    11
    Views:
    740
    Neredbojias
    Dec 29, 2008
Loading...

Share This Page