1
Answer

How to handle 2 User Controls in one ASPX Page

Pramod Gupta

Pramod Gupta

9y
324
1
I have 2 user controls on a web page.
id=UserControl1
id=UserControl2
UserControl1 has a button.
UserControl2 has a gridview.
I want to fill data in gridview of UserControl2 when i click button of UserControl1.
data is coming from sql server. 

Answers (1)
0
Manas Mohapatra

Manas Mohapatra

NA 29.3k 3.3m 9y
UserControl1
 
As per your comment you have a button and click of button it fires below event. Inside that method you need to create object of your second user control and call grid load method to reload your grid. See below code:
 
protected void Save_Click(object sender, EventArgs e)
{
   UserControl2 ctrlB = new UserControl2();
   ctrlB.GridLoad();
}
 
UserControl2
 
Declare a public public function which reload your grid.
 
public void GridLoad()
{
   // Implement your own logic to load grid
   gridView1.DataSource = tempList;
}