tags:

views:

79

answers:

1

I have this exact issue

ASP.net can’t update page from event handler

and it's been answered! My only problem is I don't really understand the solution. How does one Invoke the control when setting the property.

I have a label control but there doesn't seem to be an Invoke property/method on it.

I tried this...

PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(Label1);
        PropertyDescriptor myProperty = properties.Find("Text", false);
        myProperty.SetValue(Label1, "my value");

but that seemed to be the same as

label1.text = "my value"

which didn't work

A: 

Normally you'd Invoke a control like this:

this.label1.Invoke(new MethodInvoker(delegate
    {
        this.label1.Test = "my value";
    }));  

Unfortunately there seems to be no Invoke method on a WebControls.Label.

One way around this is to write web method which returns a string in web service and set it to Label.Text, I found an example here.

ParmesanCodice
the label control doesn't seem to have an InvokeRequired method. I get the error: 'System.Web.UI.WebControls.Label' does not contain a definition for 'InvokeRequired'
Rob
@Rob, sorry didn't realise that the WebControls.Label doesn't support that. Added some links that might help you with a workaround.
ParmesanCodice
@ParmesanCodice thanks for the links, i'll hav a look at that.
Rob