Register Client Scripts wont add javascript to page (C# Web App)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dixonjm
    New Member
    • Jun 2007
    • 32

    #1

    Register Client Scripts wont add javascript to page (C# Web App)

    Hi,

    In my page load event i have:-

    RegisterClientS cripts();
    if (!Page.IsClient ScriptBlockRegi stered("BannerS cript"))
    if (!IsPostBack)
    {
    _userLink.Attri butes.Add("oncl ick", string.Format(" ShowPopupWindow ('UserWindow'); "));
    }

    My RegisterClientS cripts consists of:-

    private void RegisterClientS cripts()
    {
    string jscriptFunction s = @"<script type='text/javascript'>
    <!--
    function ShowPopupWindow ( windowName )
    {
    top.OpenWindowB yName( windowName );
    }
    //-->
    </script>";

    // Register the script block

    ClientScript.Re gisterClientScr iptBlock(this.G etType(), "BannerScri pt", jscriptFunction s);
    }

    I have a ASP Hyperlink in the html:-


    <asp:HyperLin k ID="_userLink" runat="server" NavigateUrl="#" ImageUrl="~/images/User.gif" ToolTip="User Management" >User</asp:HyperLink>

    When I run my program I get a javascript error - Object expected. When I view source the Javascript code doesn't appear.

    I know this will be something really simple - but I just cant see it - you know how it is.

    Any ideas will be appreciated

    Thanks
    Janet
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Do you declare windowName anywhere? Does the error message give you a line number?

    Comment

    • dixonjm
      New Member
      • Jun 2007
      • 32

      #3
      I have found the problem - I hadn't wrapped the table in the hml into a form - this has definately sovled the problem.

      Many thanks anyway - Thats the first time I have posted a request in a forum & I dont suppose I explained it very clearly.

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by dixonjm
        I have found the problem - I hadn't wrapped the table in the hml into a form - this has definately sovled the problem.

        Many thanks anyway - Thats the first time I have posted a request in a forum & I dont suppose I explained it very clearly.
        Glad you have found your answer, thank you for posting the solution for others to see!

        Comment

        Working...