Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 23rd, 2008, 05:39 AM
Authorized User
Join Date: Sep 2006
Posts: 37
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to VerbatimBOT Send a message via Yahoo to VerbatimBOT
Default Page.ClientScript.RegisterStartupScript & Threads

Hi all,
I would like to ask you about an issue I'm experiencing.
I have made a user control which represents a multiple dropdown list with some suboptions (http://img337.imageshack.us/img337/8284/56692765xe3.jpg).
Now, in order to save the state of these three instances on my page, I am using a hidden field for each of them, which stores all the selected IDs and when PostBack happens, I simply fire a JavaScript function which automatically selects all the checkboxes which were selected by the user previously. I hope I made this part clear enough.

Here is the code:
    protected void Page_Load(object sender, EventArgs e)
        if (Page.IsPostBack)
            string[] selectedValues = this.SelectedValues;

            // the state is being cleared, because it will be set again by the JavaScript function

            // set the state back to the selected one
            if (selectedValues.Length > 0)
                string arrayOfValues = GenerateId();
                string script = "var " + arrayOfValues + " = new Array(" + selectedValues.Length + "); ";
                for (int i = 0; i < selectedValues.Length; i++)
                    script += arrayOfValues + "[" + i + "] = " + selectedValues[i] + "; ";
                script += " setCheckedState('chk_" + this.ID + "', " + arrayOfValues + "); ";

                Page.ClientScript.RegisterStartupScript(this.GetType(), arrayOfValues,
                   script, true);
Somehow it only works for the first user control - the first one only manages to save its state. The solution I found is to put the current Thread to sleep for 20 miliseconds.
Does anyone have an explanation why is this working only with Thread.Sleep()?

I would just like add that it works fine without Thread.Sleep() method when I debug code line by line, which is the strangest thing.

Thanks in advance,

Aleksandar Dragosavac
Belgrade, Serbia
Aleksandar Dragosavac
Belgrade, Serbia

Similar Threads
Thread Thread Starter Forum Replies Last Post
Page.RegisterStartupScript shanwaj ASP.NET 2.0 Basics 4 October 6th, 2008 01:46 AM
CLR using Threads & context connection=true adi_sesha SQL Server 2005 0 March 17th, 2008 12:24 AM
Creating threads in jsp page allang Pro JSP 1 January 11th, 2006 05:37 PM
MasterPage and ClientScript jmcpeak ASP.NET 2.0 Professional 3 November 7th, 2005 02:27 PM
Problems with threads. Threads disappearing? DriesNeyrinck VB.NET 0 June 10th, 2003 08:26 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.