开发者

Handling MasterPage event in User Control of Content page

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 conten开发者_Go百科t page but not sure how to handle it inside user control placed on content page.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜