Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

WebPart onload Javascript event

Options
  • 06-12-2007 3:16pm
    #1
    Registered Users Posts: 2,931 ✭✭✭


    This is doing my poor little head in. I want when the web part loads, for it to fire a Javascript function

    So here is the current code
    
    	protected override void RenderWebPart(HtmlTextWriter output)
    		{
                System.Web.UI.HtmlControls.HtmlGenericControl ScriptControl = new System.Web.UI.HtmlControls.HtmlGenericControl("script");
    
                ScriptControl.Attributes.Add("type","text/javascript");
                ScriptControl.Attributes.Add("src",this.ClassResourcePath + "/ad_rotator.js");
    
                this.Controls.Add(ScriptControl);
    
                this.Attributes.Add("onload","DoSomething();");
    
    
                
    
    			RenderChildren(output);
    			output.Write(SPEncode.HtmlEncode(Text));
    		}
    
    
    

    Only thing it does not do so..Is there another way of doing it, I was thinking onmouseover, but i would prefer it not having to be user activated.

    So basically this is a question on how to do an onload without having to use onload, is there an onRender event or somthing??? Or a different way to add the attribute onload that it will fire when the webpart is displayed


Comments

  • Registered Users Posts: 1,996 ✭✭✭lynchie


    Im not too up to speed on the web side of c# but what html does it generate? I assume that "this" refers to the html doc? If so is this.attributes.add() not adding it to the <html> tag? Should the onLoad not be on the <body> tag? Can you get access to the body tag in code and attach the onLoad to it?


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Actually its a Sharepoint WebPart so not a HTML doc at all. Its a DLL thats loaded at runtime.

    I checked the HTML and there is no onload event on the web part but on on the image that is loaded first time. So I think I can use that.

    Just see how it goes now..


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Actually invoking _spBodyOnLoadFunctionNames.push("") will allow you to put your function in as a onload event.

    So that might also work


Advertisement