ASP.Net - Script Function Question

Posted on 2006-04-24
Medium Priority
Last Modified: 2012-06-27
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());
Question by:sbornstein2
  • 2
LVL 15

Accepted Solution

deepaknet earned 2000 total points
ID: 16532020
Instead of RegisterClientScriptBlock, did you try using RegisterStartupScript.

Also the key registered can be checked for the uniqueness.
LVL 10

Expert Comment

ID: 16533053

Compare your code with given sample in following Link



Author Comment

ID: 16534072
SystemExpert what am I am comparing this with on that stuff?

Author Comment

ID: 16534080
deepaknet just tried that and no dice same problem

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question