Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 23rd, 2008, 05:39 AM
Authorized User
Join Date: Sep 2006
Location: Belgrade, Serbia, Yugoslavia.
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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 01:49 AM.

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