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?
Instead of RegisterClientScriptBlock, did you try using RegisterStartupScript.

Also the key registered can be checked for the uniqueness.

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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.