views:

44

answers:

2

Hi

On my master page , I have "Search textbox" and "Search Button".

On My content page , I have a "User Control" which has a "GridView".It shows some data about Vendors. Also, on this User Control's Page Load, i have code written to display all vendors in GridView.

Now, when user enters Vendor Number in "Search textbox" , and hits "Search Button" , i want to handle this event inside my User Control.

How to do this ?

Please help me. Thanks in advance.

Note : i know how to handle the event in content page but not sure how to handle it inside user control placed on content page.

A: 

If you know how to handle the event in the content page, you can apply that same approach to the control. It will still be the content page that wires the control's handler to the master page's event, since the content page is the entity that knows and can access both the master page and control.

mikemanne
A: 

You just need to add logic that passes in the Search Parameters to the User Control.

On the User Control, make a public method to Bind the grid that takes in the search text

public void BindGrid{string searchText)
{
   //get datasource with the searchText used as a Where, or whatever suits your current situation
   //bind grid
}

Then, on the MasterPage, you should have something like

protected void btnSearch_Click(object sender, EventArgs e)
{
   UserControl1.BindGrid(tbSearchText.Text);
}

You just need to make sure that your UserControl doesn't bind data on the PageLoad event if IsPostBack is true. Otherwise, you'll be binding data twice.

o6tech
how on master page can i get access to control on child page ? Will try this. Thanks
Anil
Just make the Child Control public and you should be able to see if from the code-behind.
o6tech