Hi,
I'm using a WebDialogWindow on which I create a lot of buttons dynamically (with their click event handler).
The problem is, that the click events doesn't fire.
Any ideas?
Bodo
Hello,
Can you show your code related to the WebDialogWindow? This information will be needed to better understand your project set-up and to be able to research what may be happening here.
Thanks!
here's my code:
Private Sub btnEmailMitarbeiterZuordnen_Click(sender As Object, e As System.EventArgs) Handles btnEmailMitarbeiterZuordnen.Click
Try
Me.wdwZuweisen.WindowState = Infragistics.Web.UI.LayoutControls.DialogWindowState.Normal
For Each User As clsUser In clsDataManager.getInterneUser
Dim MitarbeiterButton As New Button With {.CommandName = User.systemuserid.ToString,.Text = User.fullname,.Width =New Unit("180px"),.Height =New Unit("28px"),.CssClass ="MitarbeiterZuweisenButton"}
AddHandler MitarbeiterButton.Click, AddressOf MitarbeiterZuordnen
Me.divInterneMitarbeiter.Controls.Add(MitarbeiterButton)
Next
Catch ex As Exception
Fehler(ex)
End Try
End Sub
Private Sub MitarbeiterZuordnen(sender As System.Object, e As System.EventArgs)
Dim MitarbeiterButton As Button = CType(sender, Button)
If MitarbeiterButton IsNot Nothing Then
If clsCrmDataManager.ObjektAnUserZuweisen(clsEnums.enumObjectTypecode.Email, Me.hfAktuelleEmailId.Value, Me.hfQueueItemId.Value, MitarbeiterButton.CommandName, clsEnums.enumQueueTypeCode.privateQueue) = True Then
End If
<ig:WebDialogWindow ID="wdwZuweisen" runat="server" Height="700px" Width="830px" InitialLocation="Centered" Modal="true" WindowState="Hidden" >
<Header CaptionAlignment="Left" CaptionText="Zuweisen">
<CloseBox Visible="True" />
</Header>
<ContentPane>
<Template>
<div id="divInterneMitarbeiter" runat="server">
</div>
</Template>
</ContentPane>
</ig:WebDialogWindow>
Hi Viktor,
thanks for your detailed explanation. It helps me a lot.
Hi Bodojaeger,
It looks like that your application has a button (MitarbeiterZuordnen) and within server button-click event dynamic child controls with their own server events are added to dialog. If that is the case, then none of server events of child controls will be raised and of course those child controls will not reappear in dialog after postback. That is not related to WebDialogWindow or any other control, but to rules of asp.net. Sever is not able to persist dynamic controls. Exactly the same should happen if you add those child controls to any container, for example, asp:Panel.
The functionality of asp.net, related to viewstate and server events, is based on analizing values within response. Server expects that those client-values match with values generated while previous request. If while that validation process, the server within response is not able to identify data related to a control, then data (viewstate and flags for events) are ignored.
It means that in order to "persist" dynamic controls (their viewstates and server events) application must consistantly add exactly same controls in each session after those controls were once created. Also those child controls must use exactly the same unique ids in each session.
I suggest you to move all "create child controls" codes in a global single method in oprder to ensure same child controls, same IDs, event handlers, etc. That method/function can be used within button click handler and each time within Page.OnLoad after button was once clicked. You also will need to create a hidden field which will contain a flag about button click. That flag can be set within first button click and checked within OnLoad.
If you do not want to recreate child controls in each session after create-button-click, but you want to fill dialog only single time and get server events attached to dynamic children, then that is possible as well. However, in this case you can forget about handlers, which you attached to child controls, but you should manually process fields in Request.Form. They will contain all information which you need, including all child-control-event-flags. So, if you find those flags, then you may manually invoke server-event-handlers.If you are not familiar with architecture of asp.net related to Request.Form, then it can very hard and confusing to implement, especially within VB.