Page view counter

asp net onload event problem

Last post 03-20-2008 9:19 AM by motoBeast. 4 replies.

Sort Posts:

  • asp net onload event problem

    03-18-2008, 6:54 PM
    • Loading...
    • motoBeast
    • Joined on 02-29-2008, 5:43 PM
    • Posts 2
    • Points 0
    i don't know if this problem should be here but here it is:

    i have a asp.net site and with a masterpage and many content pages. i
    have a problem using Google Maps JavaScript API. in content page i use
    <body onload="load()" onunload="GUnload()"> and it use to work. The
    problem is that i had to put javascript functions in masterpage and
    used <body id="mBody" onload="javascript:preloader();". Now the google
    maps API doesn't work because of the 2 onload events(in masterpage and
    contentpage). How to solve this? I looked up for solutions:

    Set your masterpage body tag to:

    <body id="mBody" runat="server">

    Then add this on any page that uses the master and wants to access the
    body tag:

    public void Page_Load(Object sender, EventArgs e)
    {
    //Inject onload and unload
    HtmlGenericControl body =
    (HtmlGenericControl)Master.FindControl("mBody");
    body.Attributes.Add("onload", "Function1()");
    body.Attributes.Add("onunload", "Function2()");

    }

    but this just work if there is any onload event already in masterpage.

    also tried to put onload event of google map in a table like this <table onload="load()"....but doesnt work. 

    can someone get a solution please?

    thanks in advance

  • Re: asp net onload event problem

    03-18-2008, 7:18 PM
    • NavaidAkhtar
    • Joined on 01-14-2008, 5:53 PM
    • Islamabad - Pakistan
    • Posts 171
    • Points 1,099

    Hmm

    You can use you Child Page onload too.

    <script type="text/javascript" >Sys.Application.add_load(your function);</script>

    You have to use this line in the content page. similarly you can also use add_UnLoad, and so on...

    Regards,
    Naveed Akhtar

    Microsoft Certified Professional Developer
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    Please remember to click “Mark as Answer”, if it is solution to your Problem
  • Re: asp net onload event problem

    03-18-2008, 7:20 PM
    • Loading...
    • koese
    • Joined on 03-26-2003, 4:37 AM
    • Melbourne, AU
    • Posts 80
    • Points 352

    try both the onLoan events on the mater page and avoide on content page

     <BODY onLoad="javascript:alert('First Action');alert('Second Action');">

    koese
  • Re: asp net onload event problem

    03-18-2008, 10:22 PM
    Answer
    • Loading...
    • MorningZ
    • Joined on 07-22-2002, 2:39 PM
    • Fort Lauderdale, FL
    • Posts 1,815
    • Points 8,834

    That will only work is MS Ajax is installed

     

    I'd recommend using JavaScript to attach the load events, see this excellent js function to use:

    http://simonwillison.net/2004/May/26/addLoadEvent/

     

    "If you make it idiot proof, they'll build a better idiot"
  • Re: asp net onload event problem

    03-20-2008, 9:19 AM
    • Loading...
    • motoBeast
    • Joined on 02-29-2008, 5:43 PM
    • Posts 2
    • Points 0

    koese:

    try both the onLoan events on the mater page and avoide on content page

     <BODY onLoad="javascript:alert('First Action');alert('Second Action');">

     

     

     

    i already tried that but if i do that it walways shows a javascript error in the masterpage, i don't know why...it says it has an objecto required but i dont know what object. i can't debug it.

Page 1 of 1 (5 items)