Hallo, ich habe ein eigentlich eher triviales Problem, was ich allerdings auf die schnelle durch Foren SuFu und google alleine nicht lösen kann.
Ich füge mittels Code meiner ASP.NET Seite ein selbst erstelltes UserControl hinzu.
Dieses UserControl hat mitunter auch Events. Wenn ich allerdings die Events auslöse, werden diese nicht gefeuert, PostBack passiert trotzdem.
Kurzer Code Ausschnitt:
Page:
// Load UserControl
var invitationNotification = LoadControl("Controls/Chat/Invitation.ascx");
var ucInvitation = ((Controls.Chat.Invitation) invitationNotification);
ucInvitation.Content = (Invitation) sender;
ucInvitation.HandleError += invitationNotification_HandleError;
ucInvitation.HandleResponse += invitationNotification_HandleResponse;
pInvitations.Controls.Add(invitationNotification);
this.upMain.Update();
void invitationNotification_HandleResponse(object sender, EventArgs e)
{
// dieser code wird nicht aufgerufen !!! WARUM ?
var control = (WebControl) sender;
if(pInvitations.Controls.Contains(control))
{
pInvitations.Controls.Remove(control);
upMain.Update();
}
}
UserControl:
protected void btnAccept_Click(object sender, EventArgs e)
{
Content.Reply = server.contracts.Chat.Invitation.Response.Acception;
try
{
Global.ChatManager.ResponseInvitation(Content);
if (HandleResponse != null)
HandleResponse(this, e);
}
catch (Exception ex)
{
if (HandleError != null)
HandleError(ex, e);
}
}
Das UserControl wird zu der Seite hinzugefügt, feuere ich aber das Event durch den Button Klick des Controls, wird das Event nicht gefeuert.
Hat vlt jemand eine Idee was ich falsch mache?
Danke im vorhinein.
Hallo,
vermutlich abonnierst Du beim Neuladen der Seite die Events zu spät, so dass zur Zeit, zu der der PostBack ausgeführt wird, diese noch nicht gesetzt sind.
An welcher Stelle (in welchem Page-Handler) läuft denn dieser Code, und ist da evtl. noch irgendeine Abfrage auf IsPostBack
im Spiel?
ucInvitation.HandleError += invitationNotification_HandleError;
ucInvitation.HandleResponse += invitationNotification_HandleResponse;
Gruß, MarsStein
Non quia difficilia sunt, non audemus, sed quia non audemus, difficilia sunt! - Seneca