473,597 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Events not firing in templated control

Hi. I can't figure out why a button's click event is not firing in a
templated control I've created (first time I've tried creating one).
Please can someone help? On a point of lesser importance, how can I get
the designer to realise that my control can contain markup?

This is all ASP.Net v 2.0

This is my default.aspx:

Below is the source of three files: Default.aspx, Default.aspx.cs and
TemplateContain er.cs which will demonstrate the problem.

You will notice that in the btnEdit_Click event I raise a
NotImplementedE xception - this exception is never thrown. Why is the
button losing the event wireup?

TIA
Default:aspx
============
<%@ Page Language="C#" AutoEventWireup ="true"
CodeFile="Defau lt.aspx.cs" Inherits="_Defa ult" %>
<%@ Register TagPrefix="tc" Namespace="Cont rols.Templated" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<tc:TemplatedCo ntrol ID="tc" runat="server">
<ItemTemplate >
<asp:Button ID="btnEdit" Text="Edit" runat="server"
OnClick="btnEdi t_Click" />
</ItemTemplate>
<EditItemTempla te>
<asp:Button ID="btnCancel" Text="Cancel" runat="server"
OnClick="btnCan cel_Click" />
</EditItemTemplat e>
</tc:TemplatedCon trol>

</div>
</form>
</body>
</html>
Default.aspx.cs
===========
using System;
using System.Web.UI;
using Controls.Templa ted;

public partial class _Default : Page
{
protected void Page_Load(objec t sender, EventArgs e)
{
if (!Page.IsPostBa ck)
tc.ChangeMode(T emplateMode.Rea dOnly);

}

protected void btnEdit_Click(o bject sender, EventArgs e)
{
throw new NotImplementedE xception("Not implemented");
}

protected void btnCancel_Click (object sender, EventArgs e)
{
throw new NotImplementedE xception("Not implemented");
}
}
TemplateContain er.cs
===============
using System;
using System.Web;
using System.Web.UI;

namespace Controls.Templa ted
{
public class TemplateContain er : Control, INamingContaine r
{
private TemplatedContro l parent;
public TemplateContain er(TemplatedCon trol parent)
{
this.parent = parent;
}

public string MyValue
{
get
{
return parent.MyValue;
}
}
}

public enum TemplateMode
{
Invisible,
Edit,
Insert,
ReadOnly
}

[
ParseChildren(C hildrenAsProper ties = true),
]
public class TemplatedContro l : Control, INamingContaine r
{
private ITemplate m_itemTemplate;
private ITemplate m_editTemplate;
private string m_myValue = null;
private Control m_itemTemplateC ontainer;
private Control m_editItemTempl ateContainer;
private TemplateMode m_mode;

protected override void OnDataBinding(E ventArgs e)
{
EnsureChildCont rols();
base.OnDataBind ing(e);
}

public void ChangeMode(Temp lateMode newMode)
{
m_mode = newMode;
}

[TemplateContain er(typeof(Templ ateContainer))]
public ITemplate ItemTemplate
{
get
{
return m_itemTemplate;
}
set
{
m_itemTemplate = value;
}
}

[TemplateContain er(typeof(Templ ateContainer))]
public ITemplate EditItemTemplat e
{
get
{
return m_editTemplate;
}
set
{
m_editTemplate = value;
}
}

public string MyValue
{
get
{
return m_myValue;
}
set
{
m_myValue = value;
}
}

public Control ItemTemplateCon tainer
{
get
{
return m_itemTemplateC ontainer;
}
}

public Control EditItemTemplat eContainer
{
get
{
return m_editItemTempl ateContainer;
}
}

protected override void CreateChildCont rols()
{
if (ItemTemplate != null && m_mode ==
TemplateMode.Re adOnly)
{
m_itemTemplateC ontainer = new TemplateContain er(this);
ItemTemplate.In stantiateIn(m_i temTemplateCont ainer);
Controls.Add(m_ itemTemplateCon tainer);
}
else if (EditItemTempla te != null && m_mode ==
TemplateMode.Ed it)
{
m_editItemTempl ateContainer = new
TemplateContain er(this);

EditItemTemplat e.InstantiateIn (m_editItemTemp lateContainer);
Controls.Add(m_ editItemTemplat eContainer);
}
}

}

}

Jul 14 '06 #1
0 2334

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

Similar topics

3
5657
by: Crucifix | last post by:
Hello, I'm writing a small C# app, and part of what I'm trying to do involves the dragging of PictureBox controls on a form. Unfortunately, MouseMove seems to be behaving very oddly, causing spurious MouseMove events when the cursor doesn't actually move. I've looked for a solution in the groups, and although I've come close, I haven't found a proper explanation or fix. Here is a rundown, followed by a very simple test app that...
1
7558
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a dropdown in UC1 _________________________ 1) MainPage_Load 2) User Control_1 Load
1
8153
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the first time the control is dynamically loaded, everything works fine. After that, if the control is loaded again from the page button event handler, the user controls events fail to fire on the first click NOTE: I (believe I) am rebuilding all...
5
11735
by: Ben Fidge | last post by:
I've got a problem where some buttons placed on a user control are only firing their OnClick events when the user clicks on them for the second time. I've got the situation where some common functionality (Insert/Edit/Save/Cancel) is wrapped up in a user control. This control is embedded on several other user controls. I don't know if this is relevant or not but the latter
3
2286
by: Mike | last post by:
Hi, I am adding controls dynamically in a WebForm, but none of these controls' events fire. Here is the class code I am using. I have tried so many things, but nothing works :-( namespace WebApplication1 { using System;
5
4388
by: bryanp10 | last post by:
I have a page that is almost entirely dynamically created. Textboxes and checkbox are working fine, firing events, and persistent their state. DropDownList is giving me a major headache. All my controls are created in CreateChildControls() for my custom control. Here's a snippet of code: DropDownList dd = new DropDownList(); dd.ID = "DropDown1"; if( !Page.IsPostBack )
4
1746
by: thomson | last post by:
Hi all, i do have a user control with 4 buttons, and all the events are firing properly, My problem is that i need to right an event handler in the user control, which gets fired after a specific process is done,, but the form which will host the user control has to specify what has to be done Something like this , if the event is fired it should call the event in
9
2302
by: Erik Frey | last post by:
Hi there, Just curious as to whether there's a clever way to see the events a control/object is firing off, perhaps written out to the debug console. It would be really handy to know which events a control is firing when I perform a certain action, and the order in which they are occurring. Thanks, Erik
4
2045
by: jehugaleahsa | last post by:
Hello: Is there a way to prevent one event from firing while another event is already being fired? I have a tool that extracts media from web pages and it has multiple events firing when the status of the download changes. Some of the events are used to tell the next file to download while others manager other resources. However, on occasion, one event will
0
7885
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8271
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8380
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8258
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5426
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3923
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1493
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.