puting a script in the pageload?

Last post 07-25-2008 12:52 AM by bcweed966. 4 replies.

Sort Posts:

  • puting a script in the pageload?

    07-23-2008, 2:18 PM
    • Loading...
    • bcweed966
    • Joined on 11-26-2006, 9:40 PM
    • Posts 326

    I am using a DropDown Extender control in 1 of my apps. I want it to be always visible. I found a very good post that says how to do it is like this. The problem is I dont know much javascript. I only have that DropDown Extender on 1 page and I am using a masterpage. The code sample loads a script on the Pageload and I dont know how to do this from my master page.

    Also are there going to be issues when another page that does not have the DropDown Extender loads? since its not gone find the extender.

    here is the code sample I must adapt to my app:

    <body>
        <form id="form1" runat="server">
         <script type="text/javascript">  
       
        function pageLoad()
        {
              $find('TextBox1_DropDownExtender')._dropWrapperHoverBehavior_onhover();
          $find('TextBox1_DropDownExtender').unhover = VisibleMe;
        }
       
        function VisibleMe()
        {
            $find('TextBox1_DropDownExtender')._dropWrapperHoverBehavior_onhover();
        }
     
       </script>
    ... ScriptManager and other Controls come here
    </body>
    </html>
  • Re: puting a script in the pageload?

    07-23-2008, 7:09 PM
    Answer

    You can place this code in your content page, rather than your master page.

    Then in code behind, for instance in the content page's Page_Load event handler, you can add this:

    ScriptManager1.RegisterStartupScript(Me,TypeOf(Page),"startupScript","Sys.Application.add_load(page_Load);",True)

    where ScriptManager1 is your script manager.  This should run your script on both partial and full page postbacks.

    If your script manager is in your Master Page, then you can access the master page like this (assuming that your Master Page is called MasterPage1):

    Dim myMasterPage As MasterPage1 = CType(Me.Parent, MasterPage1)

    Dim myScriptManager As ScriptManager = myMaster.FindControl("ScriptManager1"), Microsoft.Web.UI.ScriptManager)

    myScriptManager.RegisterStartupScript( ...)

    (I'm coding from memory, btw, so apologies if it isn't completely right).

    James

     

    James Ashley, Magenic Technologies
    (james.ashley.magenic@gmail.com)
  • Re: puting a script in the pageload?

    07-24-2008, 11:05 AM
    • Loading...
    • bcweed966
    • Joined on 11-26-2006, 9:40 PM
    • Posts 326

    so the actual script should be put in the content page declaration?

    <script type="text/javascript">  

       
        function pageLoad()
        {
              $find('TextBox1_DropDownExtender')._dropWrapperHoverBehavior_onhover();
          $find('TextBox1_DropDownExtender').unhover = VisibleMe;
        }
       
        function VisibleMe()
        {
            $find('TextBox1_DropDownExtender')._dropWrapperHoverBehavior_onhover();
        }
     
       </script>
  • Re: puting a script in the pageload?

    07-25-2008, 12:24 AM

    bc,

    It probably doesn't matter, since the important thing is that they are only called from the content page.  But putting them in the content page is fine.

    James

    James Ashley, Magenic Technologies
    (james.ashley.magenic@gmail.com)
  • Re: puting a script in the pageload?

    07-25-2008, 12:52 AM
    • Loading...
    • bcweed966
    • Joined on 11-26-2006, 9:40 PM
    • Posts 326

    thank you

Page 1 of 1 (5 items)
Microsoft Communities
Page view counter