0

I am Threading to Call a function and assign values to a Textbox in Asp.net. When I debug it is showing value, but in the Form it is not getting reflected.

Below is my code.

 Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddFile.Click
        Dim newthread As New Thread((AddressOf ThreadMethod))
        newthread.SetApartmentState(ApartmentState.STA)
        newthread.Start()
    End Sub

I am calling the ThreadMethod() to assing values to Textbox1. When I debug I see it gets assinged as "test". But at runtime it is showing empty. I tried the same for setting ImageUrl in Image contol and got the same issue.

Protected Sub ThreadMethod()
        TextBox1.Text = "test"
 End Sub

Please let me know if I have to do anything to make it reflect at runtime in my form

Jegan Nagarajan
  • 43
  • 1
  • 1
  • 5
  • 2
    You simply don't. Refrain from long-running tasks (namely spawning threads) in a web application. Also, in your example, doing this is utterly pointless. – Grant Thomas May 16 '13 at 12:29
  • I am doing it for a OpenFileDialog(). for which it requires me to use and it is not updating at runtime Protected Sub ThreadMethod() Dim obj As New OpenFileDialog() If (obj.ShowDialog() = DialogResult.OK) Then Image1.ImageUrl = "~/Image/Jellyfish.jpg" End If End Sub – Jegan Nagarajan May 16 '13 at 12:32
  • You can't use OpenFileDialog in ASP.NET - that is for desktop applications. Check out – mbeckish May 16 '13 at 12:36

0 Answers0