Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Wed, 17 Sep 2008 11:40:56 +0200,    group: microsoft.public.dotnet.framework.aspnet.webcontrols        back       


Difference between Button click and IPostBackEventHandler   
Hi,

I am having an issue with replacing my home-made button control with other (standard) buttons.

In the Click event of the buttons I dynamically add some controls to this.Form.Controls. With my old 
buttoncontrol this worked fine, however replacing it with a standard Button (or also an ASPxButton 
from Developer Express) causes the following behavior:

The dynamically added controls do not show up after the page is rendered. If I recursively plot out 
the control tree to the trace, I do see the new controls in their proper place (same behavior with 
both kinds of button), however, in the end they do not get rendered to the client.

The moment at which the event fires also is identical with both buttons. Looking at the trace, both 
kinds of button fire their event at the same place:
...
aspx.page: Begin Raise PostBackEvent
-> Click event here
aspx.page: End Raise PostBackEvent
...

The implementation of my old (to be replaced) button is based on Control, implementing 
IPostBackEventHandler. In the constructor it creates a table with one row containing two cells (in 
the left an image is placed, in the right some text), and adds this table to it's Controls 
collection. The most relevant code is shown below (TR is the TableRow):

-------------------
protected override void Render(HtmlTextWriter writer) {
   TR.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(this, "Click", true) + 
";return false;";
   base.Render(writer);
}

public event EventHandler Click;

public void RaisePostBackEvent(string eventArgument) {
   if (Click != null) {
     Click(this, new EventArgs());
   }
}
-------------------

One last detail: the buttons are placed on a control that inherits from UpdatePanel (UpdateMode=always).

So, why does my custom button work (the dynamically created controls show up) but when replaced with 
a normal button not?

Any help appreciated,
Louis
date: Wed, 17 Sep 2008 11:40:56 +0200   author:   Louis Somers

Re: Difference between Button click and IPostBackEventHandler   
Since there is no answer yet, i have attached a simple repro scenario (zipped Visual Studio 
Solution). Clicking the standard button appears to have no effect, clicking the custom button works 
fine.

I would appreciate an explanation.

Cheers,
Louis
date: Mon, 22 Sep 2008 16:24:41 +0200   author:   Louis Somers

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us