EventHandler not firing on page post back

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dominosly

    EventHandler not firing on page post back

    Okay, this is a rather complicated problem, so here is the short of
    it:

    I am using a custom designed user control that simply writes out a
    plain old html submit button to the page. When the page posts back it
    will randomly (I'm talking a few out of a hundred times) not catch the
    System.EventHan dler on the submit button click.

    Here are the details:

    I have tried using a asp:button, and html input button, and a link
    with an onClick event to fire __doPostBack in the custom user control.
    All three of these seem to produce the same symptom.

    The page is definately posting back. Something in the Page_Load
    function in an if Page.IsPostBack will write to the page.

    No code in the event handler Submit_Command( object sender,
    System.EventArg s e)is being executed. This is at least as far as I
    can tell since the error is difficult to replicate. There are many
    writes to the database contained in the event handler, and none of
    them are occuring.

    On the pages that use the custom control, here is the code that
    catches the click event (SubmitOrder is a custom button id):

    private void InitializeCompo nent()
    {
    this.SubmitOrde r.Click += new
    System.EventHan dler(this.Submi tOrder_Command) ;
    this.Load += new System.EventHan dler(this.Page_ Load);

    }

    The standard __doPostBack javascript fucunction is being used, I have
    not overridden it.

    Here is the code for the custom control:

    using System;
    using System.Web.UI;
    using System.Collecti ons;
    using System.Componen tModel;
    using System.Data;

    using System.Web;
    using System.Web.Sess ionState;
    using System.Web.UI.W ebControls;


    namespace CustomControls
    {

    public class CheckOutButton: Control, IPostBackEventH andler
    {
    string _text = "Button";
    string _class = "Button";
    string _arrows = null;
    string _htmlType = "div";
    string _browserName = "IE";
    string _browserVersion = "6.0";
    string _postBackClient Handler, _buttonType, _altClass, _href,
    _javascript;
    string _commandName = "";
    string _commandArgumen t = "";
    string temp;
    int _width = 100;
    int _height = 20;
    bool _visible = true;
    bool _hasArrows = false;

    // Defines the Click event.
    public event EventHandler Click;

    public string Text
    {
    get { return _text; }
    set {
    _text = value;
    }
    }
    public string ButtonType
    {
    get { return _buttonType; }
    set { _buttonType = value; }
    }
    public int Width
    {
    get { return _width; }
    set { _width = value; }
    }
    public int Height
    {
    get { return _height; }
    set { _height = value; }
    }
    public string Class
    {
    get { return _class; }
    set { _class = value; }
    }
    public string AltClass
    {
    get { return _altClass; }
    set { _altClass = value; }
    }
    public string Href
    {
    get { return _href; }
    set { _href = value; }
    }
    public string PostBackClientH andler
    {
    get { return _postBackClient Handler; }
    set { _postBackClient Handler = value; }
    }
    public string Arrows
    {
    get { return _arrows; }
    set {
    _arrows = value;
    _hasArrows = true;
    }
    }
    public string HtmlType
    {
    get { return _htmlType; }
    set { _htmlType = value; }
    }
    public string CommandName
    {
    get { return _commandName; }
    set { _commandName = value; }
    }
    public string CommandArgument
    {
    get { return _commandArgumen t; }
    set { _commandArgumen t = value; }
    }

    public string BrowserName
    {
    get { return _browserName; }
    set { _browserName = value; }
    }
    public string BrowserVersion
    {
    get { return _browserVersion ; }
    set { _browserVersion = value; }
    }
    protected virtual void OnClick(EventAr gs e)
    {
    if (Click != null)
    {
    Click(this, e);
    }
    }
    public void RaisePostBackEv ent(string eventArgument)
    {
    OnClick(new EventArgs());
    }

    protected override void Render(HtmlText Writer output)
    {
    if(this._visibl e)
    {
    if(this._comman dArgument != "")
    _javascript = "href=\"javascr ipt:__doPostBac k('"+this.Uniqu eID+"',
    '"+this._comman dArgument+"')\" ";
    else
    _javascript = "href=\"javascr ipt:" +
    Page.GetPostBac kEventReference (this)+"\" ";

    switch(this._bu ttonType)
    {
    case "link" :
    output.Write("< a id=\"" + this.UniqueID + "\"
    "+this._javascr ipt+" class=\"" + this._altClass + "\">");
    output.Write("< " + this._htmlType + " style=\"width: "+
    this._width + "px; height: " + this._height + "px;\" class=\"" +
    this._class + "\">" + this._text);
    if(this._hasArr ows)
    output.Write("& nbsp;&nbsp;<b
    class=\"Checkou tArrows\">"+thi s._arrows+"</b>");
    output.Write("</" + this._htmlType +"></a>");
    break;
    case "submit":
    temp = "&nbsp;&nbs p;<b class=\"Checkou tArrows\">" + this._arrows
    + "<\b>";
    output.Write("< input type=\"submit\" id=\"" + this.UniqueID
    + "\" name=\"" + this.UniqueID + "\" style=\"width: "+ this._width +
    @"px; height: " + this._height + "px;\" class=\"Complet eButton\"
    visible=\"" + this.Visible + "\" value=\"" + this._text +
    "&nbsp;&nbs p;" + this._arrows + "\">");
    //output.Write("< " + this._htmlType +" style=\"width: "+
    this._width + @"px; height: " + this._height + "px;\" class=\"" +
    this._class + "\" visible=\"" + this.Visible + "\">");

    break;
    case "shell":
    output.Write("< " + this._htmlType + " style=\"width: "+
    this._width + "px; height: " + this._height + "px;\" class=\"" +
    this._class + "\">" + this._text);
    if(this._hasArr ows)
    output.Write("& nbsp;&nbsp;<b
    class=\"Checkou tArrows\">"+thi s._arrows+"</b>");
    output.Write("</" + this._htmlType + ">");
    break;
    case "hyperlink" :
    output.Write("< a id=\"" + this.UniqueID + "\" href=\"" + _href
    +"\" class=\"" + this._altClass + "\">");
    output.Write("< " + this._htmlType + " style=\"width: "+
    this._width + "px; height: " + this._height + "px;\" class=\"" +
    this._class + "\">" + this._text);
    if(this._hasArr ows)
    output.Write("& nbsp;&nbsp;<b
    class=\"Checkou tArrows\">"+thi s._arrows+"</b>");
    output.Write("</" + this._htmlType + "></a>");
    break;
    default:
    output.Write("< a id=\"" + this.UniqueID + "\"
    href=\"javascri pt:" + Page.GetPostBac kEventReference (this) +"\">");
    output.Write("< " + this._htmlType + " style=\"width: "+
    this._width + "px; height: " + this._height + "px;\" class=\"" +
    this._class + "\">" + this._text);
    output.Write("</" + this._htmlType + "></a>");
    break;
    }
    }
    }
    }
    }



    If anyone can shed any light on this, or at least give me some new
    ideas of things to try, I would greatly appriciate it. Also, if
    anyone thinks they can help, but need more information, please let me
    know.
Working...