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);
dlAttempts.DataSource=dsAttempts;
dlAttempts.DataBind();
}
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
reloading......
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!
|