ASP.Net - Script Function Question

Hi all.  I have the following setfocus script that runs perfect but I have one hitch.  There is a control file in my application that already has an window.onload event.  So what is happening is that onload is getting overwritten by the unload call in this function.  How can I get this function to load and not screw up my other function somehow any idea?  I cant mess with that other onload function because it is menu specific.  So I need to somehow get this code to fire as well.  I call this setfocus in my itemdatabound and it works it just causes issue to my menu onload.  As you can see there is a line calling the onload here outside the function brackets.

            protected static void SetFocus(Control control)
                  StringBuilder sb = new StringBuilder();
                  sb.Append("\r\n<script language='JavaScript'>\r\n");
                  sb.Append("function SetFocus()\r\n");
                  Control p = control.Parent;
                  while (!(p is System.Web.UI.HtmlControls.HtmlForm)) p = p.Parent;
                  sb.Append("window.onload = SetFocus;\r\n");
                  sb.Append("// -->\r\n");
                  control.Page.RegisterClientScriptBlock("SetFocus", sb.ToString());
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Instead of RegisterClientScriptBlock, did you try using RegisterStartupScript.

Also the key registered can be checked for the uniqueness.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

Compare your code with given sample in following Link

sbornstein2Author Commented:
SystemExpert what am I am comparing this with on that stuff?
sbornstein2Author Commented:
deepaknet just tried that and no dice same problem
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.