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.EventHandler 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.EventArgs 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 InitializeComponent()
{
this.SubmitOrder.Click += new
System.EventHandler(this.SubmitOrder_Command);
this.Load += new System.EventHandler(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.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.SessionState;
using System.Web.UI.WebControls;
namespace CustomControls
{
public class CheckOutButton: Control, IPostBackEventHandler
{
string _text = "Button";
string _class = "Button";
string _arrows = null;
string _htmlType = "div";
string _browserName = "IE";
string _browserVersion = "6.0";
string _postBackClientHandler, _buttonType, _altClass, _href,
_javascript;
string _commandName = "";
string _commandArgument = "";
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 PostBackClientHandler
{
get { return _postBackClientHandler; }
set { _postBackClientHandler = 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 _commandArgument; }
set { _commandArgument = value; }
}
public string BrowserName
{
get { return _browserName; }
set { _browserName = value; }
}
public string BrowserVersion
{
get { return _browserVersion; }
set { _browserVersion = value; }
}
protected virtual void OnClick(EventArgs e)
{
if (Click != null)
{
Click(this, e);
}
}
public void RaisePostBackEvent(string eventArgument)
{
OnClick(new EventArgs());
}
protected override void Render(HtmlTextWriter output)
{
if(this._visible)
{
if(this._commandArgument != "")
_javascript = "href=\"javascript:__doPostBack('"+this.UniqueID+" ',
'"+this._commandArgument+"')\" ";
else
_javascript = "href=\"javascript:" +
Page.GetPostBackEventReference(this)+"\" ";
switch(this._buttonType)
{
case "link" :
output.Write("<a id=\"" + this.UniqueID + "\"
"+this._javascript+" class=\"" + this._altClass + "\">");
output.Write("<" + this._htmlType + " style=\"width: "+
this._width + "px; height: " + this._height + "px;\" class=\"" +
this._class + "\">" + this._text);
if(this._hasArrows)
output.Write(" <b
class=\"CheckoutArrows\">"+this._arrows+"</b>");
output.Write("</" + this._htmlType +"></a>");
break;
case "submit":
temp = " <b class=\"CheckoutArrows\">" + this._arrows
+ "<\b>";
output.Write("<input type=\"submit\" id=\"" + this.UniqueID
+ "\" name=\"" + this.UniqueID + "\" style=\"width: "+ this._width +
@"px; height: " + this._height + "px;\" class=\"CompleteButton\"
visible=\"" + this.Visible + "\" value=\"" + this._text +
" " + 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._hasArrows)
output.Write(" <b
class=\"CheckoutArrows\">"+this._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._hasArrows)
output.Write(" <b
class=\"CheckoutArrows\">"+this._arrows+"</b>");
output.Write("</" + this._htmlType + "></a>");
break;
default:
output.Write("<a id=\"" + this.UniqueID + "\"
href=\"javascript:" + Page.GetPostBackEventReference(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.