RE: Refreshing DataList through user control

Discussion in 'ASP .Net' started by =?Utf-8?B?Q2hyaXMgRmluaw==?=, Sep 3, 2004.

  1. 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!
     
    =?Utf-8?B?Q2hyaXMgRmluaw==?=, Sep 3, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nevyn Twyll
    Replies:
    8
    Views:
    1,889
  2. Jensen Bredal

    Self refreshing user control/custom control.

    Jensen Bredal, Dec 28, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    1,691
    Bredal Jensen
    Dec 29, 2004
  3. H5N1
    Replies:
    0
    Views:
    2,728
  4. Harlan Messinger

    Self-refreshing and non-self-refreshing controls

    Harlan Messinger, Aug 4, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    465
    =?Utf-8?B?Y2xpY2tvbg==?=
    Aug 4, 2006
  5. Harlan Messinger

    Self-refreshing and non-self-refreshing controls

    Harlan Messinger, Aug 3, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    190
    Harlan Messinger
    Aug 3, 2006
Loading...

Share This Page