5,696,576 members and growing! (13,319 online)
Email Password   helpLost your password?
Web Development » ASP.NET Controls » General     Beginner License: The Code Project Open License (CPOL)

How to pass value from Ajax Enabled Base User Control to Client User Control and to the Parent aspx page

By T.Ashraf

How to pass value from Ajax Enabled Base User Control to Client User Control and to the Parent aspx page
C# (C# 2.0, C#), Office, Windows (Windows, WinXP, Vista), .NET CF, Ajax, ASP.NET, Design

Posted: 13 Mar 2008
Updated: 13 Mar 2008
Views: 7,704
Bookmarked: 16 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
4 votes for this Article.
Popularity: 1.46 Rating: 2.43 out of 5
2 votes, 50.0%
1
0 votes, 0.0%
2
1 vote, 25.0%
3
0 votes, 0.0%
4
1 vote, 25.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

What this project is al about is building a Ajax enabled dialog type Base User Control when the button is clicked it Popup a GridView Popup User Control, from where the user select some values and the selected values are send back to the Client page and then to the Parent aspx page.Data can be send in form of DataSet to client page and from client page to the Parent page.

Background

Please read how to pass value between user controls

http://www.codeproject.com/KB/grid/User_control.aspx

Using the code

1-Setp create a Base user Control like this.

2-Create a Client User control page drag and drop base control on to the client user control page. Client page can inherit the Base user control Client user control:Base user control

//Base Control Codes    
//Define the Delegate and Event
     
    public delegate void Ep_UserControlCommandEventHandler(object sender, AB_UserControlCommandEventArgs e);
    public event AB_UserControlCommandEventHandler AjaxGridSelectedData;
//User can set the DataSet from the Client User Control user can pass a data for the GridView of the Base control from Client User control;
//Define the DataSet property on base control
    private DataSet data;
    public DataSet Parent_DataSet
    {
        set
        {
            data = value; ;
        }
    }

//When user click on the show dialog button This is base control event
protected void Show_Click(object sender, EventArgs e)
    {
        GridView1.DataSource = data; 
        GridView1.DataBind();
        BPanel.Update();
        mdlPopup.Show();
    }
//Define the virual method this method need to be implemented in the client page to access the return data set value

  protected virtual void OnAB_AjaxGridSelectedData(AB_UserControlCommandEventArgs e)
    {
        if (AjaxGridSelectedData != null) AjaxGridSelectedData(this, e);
    }

//Pass the Selected values to the Client Page by Base Command event AB_UserControlCommandEventArgs(N_data));

After selecting the values from the control user can press the add button to return the selected values has dataset
protected void btnadd_Click(object sender, EventArgs e)

{

DataTable dt = new DataTable();

dt.Columns.Add(new DataColumn("Id", typeof(string)));

dt.Columns.Add(new DataColumn("Name", typeof(string)));

dt.Columns.Add(new DataColumn("Is_Selected", typeof(Boolean)));

ArrayList Id_List = (ArrayList)Session["CHECKED_ITEMS"];

foreach (GridViewRow Ro in GridView1.Rows)

{



bool isChecked = ((CheckBox)Ro.FindControl("Is_Selected")).Checked;

if (isChecked)

{

if (Id_List != null)

{

Id_List.Add(Ro.Cells[0].Text);

}

else

{

DataRow dra = dt.NewRow();

dra["Id"] = Ro.Cells[0].Text;

dra["Name"] = Ro.Cells[1].Text;

dra["Is_Selected"] = true;

dt.Rows.Add(dra);

}

}

}

if(Id_List!=null)

{

string Id_s ="'";

for (int i = 0; i < Id_List.Count; i++)

{

Id_s += Id_List[i].ToString() +"','";

}

DataTable MyTable = data.Tables[0];

DataRow[] test;

string Slect = "Id in (" + Id_s + ")";

Slect=Slect.Replace(",')", ")");

test = MyTable.Select(Slect);

foreach (DataRow rw in test)

{

DataRow dr = dt.NewRow();

dr["Id"]=rw["Id"];

dr["Name"]=rw["Name"];

dr["Is_Selected"]=true;

dt.Rows.Add(dr);

}



}

DataSet N_data = new DataSet();

N_data.Tables.Add(dt);

OnEp_AjaxGridSelectedData(new AB_UserControlCommandEventArgs(N_data));

mdlPopup.Hide();

}
      
//Client User control page implement the base control event

protected void Page_Load(object sender, EventArgs e)

{


AjaxGridViewBaseControl1.Parent_DataSet = Main_GridData();

AjaxGridViewBaseControl1.AjaxGridSelectedData += new AB_UserControlCommandEventHandler(OnAjaxGridSelectedData);



}

//Get value from Base
private void OnAjaxGridSelectedData(object sender, AB_UserControlCommandEventArgs e)

{


//The selected values can be displyed in client control and even return back to parent page
GridView1.DataSource = e.EpDataSet;

GridView1.DataBind();



}



4-Drag and drop the client page on the parent page.

5-Here is example how the data is displyed in the POPup Grid


Points of Interest

User controls

History

License

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

About the Author

T.Ashraf


More than 9 years of experience in programming, design, architecture and development of various commercial object oriented application using C#, Visual Basic.net, ASP.net, relational database (SQL ,Oracle, MYSQL) in Window NT/2000/XP and UNIX environment. Experienced in client-server application development, data security management, third party tools and also has very good exposure to the entire Software Development Life Cycle viz. Requirements Collection and other Project Management activities.
WWW.TANVTECH.COM
Occupation: Software Developer (Senior)
Company: TANVTECH
Location: United States United States

Other popular ASP.NET Controls articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
  (Refresh) 
-- There are no messages in this forum --

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 13 Mar 2008
Editor:
Copyright 2008 by T.Ashraf
Everything else Copyright © CodeProject, 1999-2008
Web13 | Advertise on the Code Project