TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
emilkh
NA
5
0
a problem with web user control events
Sep 22 2004 5:42 PM
*** SOS *** I have a Web User Control that has an asp table. The table is basically a menu and I want to populate the items on the menu from my webform. I have a method in my .ascx file that creates the cells and imagebuttons. public void AddMenuItem(string commandName, string commandArg) { TableRow tr = Table1.Rows[0]; TableCell td = new TableCell(); ImageButton ib = new ImageButton(); ib.ID = commandName + commandArg;//Just an ID ib.Command += new CommandEventHandler( this.ImageButtonClick ); ib.CommandName = commandName; ib.CommandArgument = commandArg; td.Controls.Add(ib); tr.Cells.Add(td); } From the WebForm that hosts the user control I do the following. private void WebForm1_PreRender(object sender, System.EventArgs e)//this does not work { hdr1.AddMenuItem("One", "1"); hdr1.AddMenuItem("Two", "2"); hdr1.AddMenuItem("Three", "3"); } I have declared the delegte and the event in my user control and I have an event handler in my webform private void Page_Load(object sender, System.EventArgs e) { //hdr1 is my user control hdr1.OnMyClick += new MyEventDelegate(hdr1_OnMyClick); // //rest of the code } Problem is that no event is being raised when I click on the image buttons. But if I move the following lines inside my .ascx file, it works just fine. private void Page_Load(object sender, System.EventArgs e)//this works { //This is the load method of my user control TableRow tr = new TableRow(); tr.BorderWidth = 0; Table1.Rows.Add(tr); AddMenuItem("One","1"); AddMenuItem("Two","2"); AddMenuItem("Three","3"); } I do not want to make the user control inteligent and I want to populate it from the web control. Can somebody tell me what the problem is. Any help is highly appreciated.
Reply
Answers (
0
)
ASP.NET with C#
.Net remoting problem