简体   繁体   中英

Getting DropDownList select values from using Threads c#

I got one webform that starts a second thread, I have a DropDownList on the webform with a selected value of 1 when I start the new thread the thread function get the value using

((DropDownList)Page.FindControl("MLprice2_" + _lineRef)).SelectedItem.Value)

these works just fine, the problem comes when I change the DropDownList value for example to 5 the function on the thread using

((DropDownList)Page.FindControl("MLprice2_" + _lineRef)).SelectedItem.Value)

still gets value 1 and not 5 .

please help

If you start a second thread in the life cycle of the webpage, then probably the webpage will already have finished its life cycle before the second thread finishes processing. The webpage is prevented from being garbage collected since it is somehow referenced by the second thread (since you're updating the webpage there). But the client will probably already have received the rendered webpage, and therefore the result of the second thread will not reach the client. It will be updated on the server (in-memory), but not on the client.

I think a different approach is necessary. You have to do some extra async communication and/or page updating (ajax jumps to mind) to have the rendered page receive the signal to set the dropdownlist to 5.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM