Last post Sep 13, 2009 08:58 AM by dreams4gotten79
Sep 12, 2009 12:40 PM|dreams4gotten79|LINK
I have created an asp.net user control that have a "page_load" event handler. so used it in a page 3 times.( drag and drop .ascx file 3 times)
now when my page is shown, only one "page_load" event run and do something. i think each user control have it's own event handler and must run separately, don't think?
Sep 12, 2009 01:30 PM|fayaz_3e|LINK
user controls are used for many purposes. One of them is reusability. Means it will have same logic spanned across the pages. So only single page load for 'n' no of pages.
You can change it. You can define your very own evet handler and can handle it in your page..
Iwill explain you one of my experiences.
I had one user control consists of 2 DDL(Year and Month) and one button. This I am using in most pages. Thats why creted a usrcontrol. But on button click i need to show few records in one page. Should diaply uploaded files in another page and shoud display
log in one more page.
Same cotrol but diffrent logic...
I have created a handler in user control and handled it in all pages with different logic.
public eventhanler GoClick is defined in user control in class level...
And in button click, i raised this event..
protected void Button_Click(object sender, EventArgs e)
And in deifferent pages handled differently...
In page load
UserControlID.GoClick += new EventHandler(UserControlID_GoClick);
which creates a event handler in the page
private void UserControlID_GoClick(object sender, EventArgs e)
//Do your loic here
Sep 13, 2009 08:58 AM|dreams4gotten79|LINK
thanks a lot.