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("<!--\r\n");
                  sb.Append("function SetFocus()\r\n");
                  sb.Append("{\r\n");
                  sb.Append("\tdocument.");
 
                  Control p = control.Parent;
                  while (!(p is System.Web.UI.HtmlControls.HtmlForm)) p = p.Parent;
 
                  sb.Append(p.ClientID);
                  sb.Append("['");
                  sb.Append(control.UniqueID);
                  sb.Append("'].focus();\r\n");
                  sb.Append(p.ClientID);
                  sb.Append("['");
                  sb.Append(control.UniqueID);
                  sb.Append("'].select();\r\n");
                  sb.Append("}\r\n");
                  sb.Append("window.onload = SetFocus;\r\n");
                  sb.Append("// -->\r\n");
                  sb.Append("</script>");
 
                  control.Page.RegisterClientScriptBlock("SetFocus", sb.ToString());
            }
sbornstein2Asked:
Who is Participating?
 
deepaknetCommented:
Instead of RegisterClientScriptBlock, did you try using RegisterStartupScript.

Also the key registered can be checked for the uniqueness.
0
 
SystemExpertCommented:
Hi,

Compare your code with given sample in following Link

http://www.codeproject.com/aspnet/EWSWebPt2.asp

Thanks
0
 
sbornstein2Author Commented:
SystemExpert what am I am comparing this with on that stuff?
0
 
sbornstein2Author Commented:
deepaknet just tried that and no dice same problem
0
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.