Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > RE: Refreshing DataList through user control

Thread Tools

RE: Refreshing DataList through user control

Posts: n/a
This is what I did:

In the user control, at the bottom of the btnClick

if(refreshDL!= null) refreshDL(this, e);

At the top of the user control I added the event:

public event EventHandler refreshDL;

In the main form that contains the usercontrol I wire the delegate:
(ucInput instantiates the usercontrol)
this.ucInput.refreshDL += new System.EventHandler(this.onDLRefresh);

And in the main form I added the code to run the refresh (onDLRefresh)

public void onDLRefresh(object sender, System.EventArgs e)
dsAttempts = dba.getDataset(sqlGoesHere);

But, the problem is that the refreshDL is always null, so the event is never
fired? Appears to be losing the reference during the btn click with the page

if(refreshDL!= null) refreshDL(this, e);

Any suggestions? Is this the correct approach?

"Shailesh Jannu" wrote:

> Here is the code to do this
> Inside the user control add this statement
> --declate event handler
> public event EventHandler ButtonisClicked;
> --inside button click event
> if(ButtonisClicked!= null)
> ButtonisClicked(this, e);
> on the main page code behind in initializecomponent method
> this.uc1.ButtonisClicked+= new System.EventArgs(this.OnButtonisClicked);
> "Chris Fink" wrote:
> > I am experiencing a problem refreshing a datalist on a main page after a
> > button within a user control (within the main page) is clicked. I understand
> > the reason why the datalist is not refreshing, simply because the btn click
> > in the user control does not fire off of the main page_load event after it is
> > done executing the click. So here lies my question: how do i reference the
> > datalist (on the main page) from the user control so that I can refresh the
> > datalist in at the end of the btn click event (which is fired in the user
> > control). I have attempted to expose the datalist as a public property and
> > call it from the user control as follows, but the dl object is always null.
> >
> > MainForm main = new MainForm();
> > DataList dl =(DataList)main.dlResults;
> > DataSet ds = new DataSet();
> > ds = dba.getDataset(sql);
> > dl.DataSource=ds;
> > dl.DataBind();
> >
> > I've also tried to find the control hoping to resolve the null reference, no
> > success:
> > DataList dl = (DataList)MainForm .FindControl("dlResults");
> >
> > Any ideas on how to remedy this problem? ...and why is the reference null?
> > Perhaps the user control is just adding to the complexity of this project?
> >
> > Any help is appreciated!

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Self-refreshing and non-self-refreshing controls Harlan Messinger ASP .Net 1 08-04-2006 01:13 PM
Self-refreshing and non-self-refreshing controls Harlan Messinger ASP .Net Web Controls 0 08-03-2006 12:29 PM
GridView nested in DataList - refreshing corresponding DataList row after updating GridView row H5N1 ASP .Net 0 04-26-2006 11:41 PM
Self refreshing user control/custom control. Jensen Bredal ASP .Net 5 12-29-2004 12:10 PM
Setting up a datalist control - Item_DataBound for a datalist in a datalist Nevyn Twyll ASP .Net 8 09-09-2004 10:13 PM