I’m a bit stuck with a problem. I feel like the solution should be fairly straight forward but I’m completely out of ideas for some reason.
Here’s the problem. I’ve got a user control with a couple of buttons. Think of them as ‘On’ and ‘Off’. When either button is clicked an async method is called. If the method is successful an event is fired. Within the event I want to update the enabled property of the two buttons so that only a single button is clickable at any one time. The problem is that any changes I make to the properties are not shown on screen because the postback is already complete. I tried wrapping the buttons in an UpdatePanel but I get an “Update method can only be called on UpdatePanel with ID ‘xxxx’ before Render’ error. I understand why the problem occurs but I can’t think of a solution. Help!
Ideally what I’d like to do is simply call a method within the event that will update the UI, but I don’t know if that’s possible.
EDIT
Here’s some example code. I can’t post the exact code, but this explains the problem:
Partial Class ExampleUserControl
Inherits Inherits System.Web.UI.UserControl
Private WithEvents obj As MyObj
Private Sub btnOn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOn.Click
obj = New MyObj()
obj.On() ' Calls OnEvent on success
End Sub
Private Sub btnOff_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOff.Click
obj = New MyObj()
obj.Off() ' Calls OffEvent on success
End Sub
Private Sub On() Handles obj.OnEvent
btnOn.Enabled = False
btnOff.Enabled = True
'updatePanel.Update() This throws an exception
End Sub
Private Sub Off() Handles obj.OffEvent
btnOn.Enabled = True
btnOff.Enabled = False
'updatePanel.Update() This throws an exception
End Sub
End Class
You can’t just “push” html to the browser, updatepanel or not. You can only react to a “pull” from the browser.
So you need to have the update panel refresh itself every x seconds. Then you can check the server side status and update the panel accordingly.
See for instance: http://ajax.net-tutorials.com/controls/timer-control/
Don’t forget to switch off the timer when the action is done.