Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a .aspx page
C#
Contract.aspx
in which there is a user control


<%@ Register Src="../UserControls/ManageDocument.ascx" TagName="Document" TagPrefix="uc1" %>


and the userControl has a grid. Now i want to bind the grid inside user control to save click on some condition

.ascx
partial class UserControls_ManageDocument : System.Web.UI.UserControl
{
protected void btnSave_Click(object sender, System.EventArgs e)
 {
   if (somecondions)
   {
   //bind the Parent page
    }
  }
}


What I have tried:

I am a rookie asp.net coder, please help me. I don't know if that is even possible.
Posted
Updated 22-Nov-17 7:07am

1 solution

Simple answer: Don't.

The user control should not know or care about the page that contains it. It should be entirely self-contained.

Instead, have the user control raise an event when the parent grid should be bound. The containing page can then subscribe to that event, and do whatever it needs to when the event is raised.

User control:
C#
using System;

partial class UserControls_ManageDocument : System.Web.UI.UserControl
{
    public event EventHandler BindGrid;
    
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (some conditions)
        {
            EventHandler handler = BindGrid;
            if (handler != null) handler(this, EventArgs.Empty);
        }
    }
}

Parent page:
<uc1:Document runat="server"
    OnBindGrid="BindGrid"
/>
C#
protected void BindGrid(object sender, EventArgs e)
{
    // Bind the grid here...
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900