473,326 Members | 2,126 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,326 software developers and data experts.

Problems with firing events on user control

15
Hello,
I have the following problem, I think it is rather simple, but hard to describe:
I created a simple user control which contains a check box and an image - CheckBoxImage.
Then I createa a control which contains and visually arranges CheckBoxImage controls in a table dynamically (it can contain diffrent numbers of ImageCheckBox)- CheckBoxImageContainer.
The CheckBoxImage are added to the container dynamically.

The problem is this:
When I first populate the container it has 20 (or diffrent number) ImageCheckBoxes, but, when a user checks or unchecks a check box in a certain ImageCheckBox, or presses a button, , I need to load new 20 diffrent ImageCheckBox into the container.
I can only know that during the event handling of the CheckBox selectedChange, my response is to remove the previous 20 ImageCheckBox and adding new 20 ImageCheckBox.
The problem is, that these check boxes won't react to onselectchanged events in this request, only after another postback.
I think it is because even though I first deleted the previous ImageCheckBox, When I populate the new ones their ids UniqueID are cont_ctl21, cont_cctrl22...., cont_cctl40, and on the first postback when they are populated their UniqueIDs are cont_ctl00, cont_ctl01, so the server doesn't recognize their selectChange Event, only after the next postback it is regonized (because now their IDs match the former postback).
Is there a way to solve this, for example to restart the control count on the container?

Thank you,
and if my question was not clear I would be happy to elaborate
May 28 '07 #1
3 1391
filmar
23
May be you need to make something like this:
CheckBox c = (CheckBox)YourContainer.Controls[somenumber];
and then use variable c to make anything you need.
Good luck
May 29 '07 #2
yovalk
15
Thanks for trying to help, I already tried it, but the location in the control collection doesn't affect the uniqueID the control receives.
Here is a simplified version of my question:
This is a simpler version of my previous question,
lets say I dynamically add a control to a custom control named Cont which I built, the control is assigned the unique ID Cont_ctl00.
On the next trip to the server I add a diffrent control to Cont, that control will receive the uniqueid Cont_ctl00, and as a result it will receive all the ViewState parameters of the control from the former trip.
Is there any way to avoid this?

Thanks,
Yuval
May 29 '07 #3
I, too, experienced this same problem and have not come up with or heard of any elegant solutions, so what I did was on each postback, I save a little "page state" object, complete with the user's intentions, to a datastore. Then, I do a response.redirect back to the same page, retrieve my saved page state, and perform the intended processing. This method effectively resets the control count. If anyone has a solution to reset the control count other than having to redirect back to the same page, PLEASE let us know. :)
Jun 6 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

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: 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...
1
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...
5
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...
3
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...
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...
1
by: Ben Fidge | last post by:
I've got a User Control that renders site navigation from a database. For some reason, when using Output Caching, none of my LinkButtons fire their PostBack events. The declaration in the...
5
by: Joe | last post by:
Hi I am adding a class to a ComboBox - and all is fine except that I fill the combobox on the Form_Load Method and it causes the method private void comboBox2_SelectedIndexChanged(object...
1
by: Andrew Jocelyn | last post by:
Hi I have a Formview control in a UserControl. The server-side validation is not working, i.e. the events are not firing when a button control which causes validation is fired or even when...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.