[ASP.NET 2.0] IPostBackEventHandler & RaisePostBackEvent non appelé
Bonjour à tous !
Je pensais m'engager dans un développement rapide, mais un unique point me bloque depuis hier soir...
J'ai décidé de faire un contrôle jouant le rôle de Button, ImageButton et LinkButton; avec une propriété Format permettant de savoir quel type de bouton on veut. Mon contrôle implémente donc IButtonControl et IPostBackEventHandler.
Le problème c'est que dans certaines situations les évènements du contrôle ne sont pas traité (la procédure RaisePostBackEvent n'est pas appelé) !
Voici un résumé du code source :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public class GenericButton : WebControl, IButtonControl, IPostBackEventHandler
{
public event EventHandler Click;
[...]
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
if (Page != null)
Page.VerifyRenderingInServerForm(this);
PostBackOptions postBackOptions = GetPostBackOptions();
if ((UniqueID != null) && ((postBackOptions == null) || (postBackOptions.TargetControl == this)))
writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID);
writer.AddAttribute(HtmlTextWriterAttribute.Onclick, Page.ClientScript.GetPostBackEventReference(postBackOptions, true));
[...]
base.AddAttributesToRender(writer);
}
protected virtual PostBackOptions GetPostBackOptions()
{
PostBackOptions options = new PostBackOptions(this, String.Empty);
if (!String.IsNullOrEmpty(PostBackUrl))
options.ActionUrl = HttpUtility.UrlPathEncode(ResolveClientUrl(PostBackUrl));
if ((CausesValidation && (Page != null)) && (Page.GetValidators(ValidationGroup).Count > 0))
{
options.PerformValidation = true;
options.ValidationGroup = ValidationGroup;
}
options.ClientSubmit = !UseSubmitBehavior;
return options;
}
protected virtual void OnClick(EventArgs e)
{
if (Click != null)
Click(this, e);
}
[...]
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (Page != null)
Page.RegisterRequiresRaiseEvent(this);
}
public void RaisePostBackEvent(string eventArgument)
{
if (Page != null)
Page.ClientScript.ValidateEvent(UniqueID, eventArgument);
[...]
OnClick(EventArgs.Empty);
[...]
}
[...]
} |
Le problème a été détecté dans le cas d'utilisation suivant :
- Mise en place du contrôle dans un Repeater dans un UserControl.
Dans certains projets je n'ai aucun problème. Et je n'arrive pas à déterminé ce qui peut poser problème. Vous avez des idées ??
Merci d'avance
@++
NeoMan