Link to home
Start Free TrialLog in
Avatar of tia_kamakshi
tia_kamakshiFlag for United Arab Emirates

asked on

OnClick event on user control to update results on another user control

Hi Experts,

I am working on ASP.net2.0 using C#

In my aspx page, I have 2 different control.

1. Search User Control - where user can search by clicking search button
2. List User Control - where list will be displayed based on the search crieteria entered by user.


I am not able to do the following

- On click of search button on search control, call method on list user control to update the results

Please help me how to do this.

I have created a test code.

Please find my aspx and user control below

Please help me how to proceed

Many Thanks


ASPX CODE
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="callUserControlEvents.aspx.cs" Inherits="callUserControlEvents" %>

<%@ Register Src="controls/Usercontrol_List.ascx" TagName="Usercontrol_List" TagPrefix="uc1" %>
<%@ Register Src="controls/usercontrolSearch.ascx" TagName="usercontrolSearch" TagPrefix="uc2" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Test</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <uc1:Usercontrol_List ID="Usercontrol_List1" runat="server" />
        <br />
        <uc2:usercontrolSearch ID="UsercontrolSearch1" runat="server" />
    </div>
    </form>
</body>
</html>

Open in new window


ASPX CODE BEHIND
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class callUserControlEvents : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

Open in new window


SEARCH USER CONTROL
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="usercontrolSearch.ascx.cs" Inherits="controls_usercontrolSearch" %>
<asp:Button ID="btnSearch" runat="server" OnClick="btnSearch_Click" Text="Search" />

Open in new window


SEARCH USER CONTROL CODE BEHIND
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class controls_usercontrolSearch : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {

    }
}

Open in new window


LIST USER CONTROL
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Usercontrol_List.ascx.cs" Inherits="controls_Usercontrol_List" %>
<asp:Label ID="lblMessage" runat="server"></asp:Label><br />

Open in new window


LIST USER CONTROL CODE BEHIND
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class controls_Usercontrol_List : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            lblMessage.Text = "Click Event not called";
        }
    }

    public void updateLabelInList()
    {
        lblMessage.Text = "Event Called";        
    }
}

Open in new window


Please help
Avatar of Rahul Agarwal
Rahul Agarwal
Flag of India image

Avatar of tia_kamakshi

ASKER

Thanks agarwalrahul,

I have downloaded the code and understood.

But they are using xml to save data and another control is reading xml to bring list.

In my case I have no xml data. I need to take data from search control and produce list from the same data in list conrol.

Please suggest
ASKER CERTIFIED SOLUTION
Avatar of Swapnil
Swapnil
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Many Many Thanks

It works great