473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.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("&nbsp;&nbsp;<b
class=\"CheckoutArrows\">"+this._arrows+"</b>");
output.Write("</" + this._htmlType +"></a>");
break;
case "submit":
temp = "&nbsp;&nbsp;<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 +
"&nbsp;&nbsp;" + 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("&nbsp;&nbsp;<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("&nbsp;&nbsp;<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.
Nov 15 '05 #1
0 2315

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
3
by: Jeffrey A. Voigt | last post by:
Can someone take a quick glace at my code and tell me why my AutoPostBackHandler function does not get fired off at all? What I'm trying to do is get all of the Buttons and DropDownList controls...
3
by: Tim Thomas | last post by:
Hi, I am very new to .NET and am in the process of building my first web application. I will briefly describe what i am trying to achieve: I have a system where suppliers register their...
1
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What...
1
by: Alessandro Rossi | last post by:
Hi, I am having this problem: I have developed a composite component which has 2 components: a textbox and a button. I need to add an eventhandler to a button click. I have added the eventhandler,...
2
by: TPS | last post by:
I have some dynamic controls (LinkButton) that I am adding to my pages. When the link button is clicked, I am getting an ID from the LinkButton.CommandArguement value. I am then using that ID...
2
by: ~~~ .NET Ed ~~~ | last post by:
I have a problem (don't we all?). I have a web form with multiple modules, some of these modules have an ASP.NET (server run) button. OK, now I have UserControlX which has one such button (say...
3
by: Jay | last post by:
I am on the 2.0 framework and have run the c:\windows\microsoft.net \framework\v1.1.4322\aspnet_regiis.exe -c and had no success. About half of the buttons on my webforms are firing and the other...
1
by: mark4asp | last post by:
How can I stop a post back from firing when there is no need for it to? I have a GridView pager template (shown below): There are 3 commands: ddlPager_SelectedIndexChanged - move the page to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.