swabygw
swabygw

Reputation: 913

ASP.NET UpdatePanel and Button Not Doing Full and/or Partial Postback

I know that this is a common question, but I'm sure my code is sufficiently correct and it's not working for me. I have a modal window which, when up, presents an UpdatePanel which has several Panel's within it, and on one of them, is a plain button. Clicking the button isn't providing ANY postback (partial or full). Ideally, I'd like to just do a partial postback, but I can't get any type of postback now. Here's some of my code:

For the ScriptManager:

myScriptManager.ID = "ScriptManager1"
myScriptManager.EnablePageMethods = True    
myScriptManager.EnablePartialRendering = True
MainForm.Controls.Add(myScriptManager)

For the UpdatePanel:

With BeginBroadcastPanel
    .ID = "BeginBroadcastPanel"
    .Attributes.Add("style", "display:flex;flex-direction:column;justify-contents:center;align-items:center;")
    '.UpdateMode = UpdatePanelUpdateMode.Conditional
    '.ChildrenAsTriggers = True
End With

For the Button:

With lblBroadcastPanelLoginButton   
    .ID = "lblBroadcastPanelLoginButton"
    .Text = "LOG IN"
    .Attributes.Add("style", "font-weight:bold;margin:20px;width:50%;text-align:center;cursor:pointer;font-size:20pt;background:lightgray;border-radius:4px;padding:10px 10px 10px 10px;border:0px solid darkgray;")
    '.Attributes.Add("onclick", "__doPostBack('<%=BeginBroadcastPanel.ClientID %>', null);")
    'Dim t As New AsyncPostBackTrigger
    't.ControlID = lblBroadcastPanelLoginButton.ClientID
    't.EventName = "Click"
    'BeginBroadcastPanel.Triggers.Add(t)
End With

As you can see, I've tried many different solutions, such as setting the UpdateMode, ChildrenAsTriggers, adding an AsyncPostBackTrigger. Only the Javascript kind of worked, but it'll only do a full postback (and it's my understanding that Javascript shouldn't be necessary to do the partial postback). To check if a partial postback is happening, I have a field which displays the current datetime. Any ideas what's wrong here?

EDIT: I discovered that a postback is occurring, but the textfield that was showing the datetime was not updating. If I display the datetime in a label, it shows that the datetime is increasing. Oddly enough, both IsPostBack and IsInAsyncPostBack evaluate to True with each postback. Also odd, if I increment a public integer (see example below), it only fires on the first postback but not any subsequent postbacks.

Public test As Integer
Public dttm As DateTime = DateTime.Now

Dim b As New Button
With b
    test = test + 1 
    .Text = dttm.ToString("MM/dd/yyyy HH:mm:ss") & " - " & test.ToString & " - " & Page.IsPostBack
End With
BeginBroadcastPanel.ContentTemplateContainer.Controls.Add(b)

In the code above, I'm showing both the dttm and test variables on the button. The dttm is incrementing up, but the test variable is not. Why is that?

Upvotes: 0

Views: 82

Answers (1)

swabygw
swabygw

Reputation: 913

Found the issue: the button was missing a Click handler. After adding an AddHandler, got everything going.

Upvotes: 0

Related Questions