Solved

ASP.NET - C# - Pass Custom Object Between Page and Pop Up Page

Posted on 2009-05-05
5
2,677 Views
Last Modified: 2013-11-07
I am working on a data entry application.  I am using a FormView which is DataBound to an ObjectDataSource.  The ObjectDataSource returns a custom object.

For one of the fields, I need to use a PopUp window, which will contain controls to allow users to select from a list of values.

I am looking for a good mechanism for passing a complex object back AND forth betwen the base page and the PopUp window.  Additionally, I do NOT want to use Session (My production envioronment is set up as a Web Farm, and Session is not shared between web servers).

For those fimiliar with MOSS 2007 (SharePoint), MOSS offers similiar functionality with the People Picker control.  I believe the PeoplePicker uses a hidden input field to store a serialized copy of a DataSet for passing between pages.  
Could anyone help me code that out?

Some example Pseduo-Code below.  Stepping through it, DataEntryPage.aspx, hosts MyCustomControl.  MyCustomControl receives an instance of a List<int> (although this could modified to a more complex object later on).  MyCustomControl has an Edit button.  When clicked, EditPopUpWindow.aspx needs to open, receive a copy of MyCustomControl.IDs, perform some processing on it (in code-behind) and then present in on the GUI.  We can assume EditPopupWindow.aspx contains controls to allow users to modify IDs.  Finally, when the EditPopupWindow.aspx's Save button is clicked, I need to pass the Updated IDs back to MyCustomControl and initiate a post back so MyCustomControl can re-DataBind.

Thanks in Advance!!!!!

PJ


///////////////////////////////////////////////////////
public class MyDataObject
{
public string Title{get;set;}

private List<int> m_IDs = new List<int>();
public List<int> IDs{ get{ return m_IDs; } }
}


///////////////////////////////////////////////////////
public class ProviderForObjectDataSource
{

public List<MyDataObject> Select()
{
//Retrieve MyDataObjects from persistant storage
return new List<MyDataObject>();
}

public void Insert(MyDataObject newDataObject)
{
//Add newDataObject to persitant storage
}

}

///////////////////////////////////////////////////////
//DataEntryPage.aspx
///////////////////////////////////////////////////////
<%@Page Language="C#" CodeBehind="DataEntryPage.aspx.cs" %>
<%-- Register uc1:MyCustomControl --%>
<html>
<body>
<form id="form1" runat="server">
<asp:FormView id="FormView1" runat="server" DataSourceID="MyObjectDataSource" DefaultMode="Insert" >
<InsertItemTemplate>
Title: <asp:TextBox id="TitleTextBox" runat="server" Text='<%# Bind("Title") %>' />
IDs:   <uc1:MyCustomControl id="MyCustomControl1" runat="server" IDs='<%# Bind("IDs")%>'
</InsertItemTemplate>
</asp:FormView>
<asp:ObjectDataSource id="MyObjectDataSource" runat="server"
      SelectMethod="Select" InsertMethod="Insert"
      TypeName="ProviderForObjectDataSource"
      DataObjectTypeName="MyDataObject" />

</form>
</body>
</html>
///////////////////////////////////////////////////////
//MyCustomControl.ascx
///////////////////////////////////////////////////////
<%@Control Language="C#" CodeBehind="MyCsutomControl.ascx.cs" %>

<%-- IDRepeator DataSource set in codebehind --%>
IDs: <asp:Repeator ID="IDRepeator" runat="server" />

<asp:Button ID="OpenEditPopUpWindowButton" runat="server" OnClick="OpenEditPopUpWindowButton_Click"  />
///////////////////////////////////////////////////////
//MyCustomControl.ascx.cs
///////////////////////////////////////////////////////
public partial class MyCustomControl : System.Web.UI.UserControl
{

private List<int> m_IDs = new List<int>();

public List<int> IDs
{
      get{ return m_IDs; }
      set{
            m_IDs = value;
            IDRepeator.DataSource = m_IDs;
            IDRepeator.DataBind();
      }
}

protected void OpenEditPopUpWindowButton_Click(object sender, EventArgs e)
{
//HOW DO I OPEN EditPopUpWindow AND PASS IT this.IDs?
//CAN'T USE Sesssion AND QueryString PROBABLY WONT BE FEASIBLE
}

}
///////////////////////////////////////////////////////
EditPopUpWindow.aspx
///////////////////////////////////////////////////////
<%@Page Langugage="C#" CodeBehind="EditPopUpWindow.aspx.cs" %>

<%-- Controls For Working with IDs --%>
<asp:Button ID="Save" runat="Server" OnClick="Save_Click" />
///////////////////////////////////////////////////////
EditPopUpWindow.aspx.cs
///////////////////////////////////////////////////////
public partial class EditPopUpWindow : System.Web.UI.Page
{
private List<int> m_IDs = new List<int>();

protected void Page_Load(Object sender, EventArgs e)
{
//I NEED IDs TO BE POPULATED AT THIS POINT, OR A LATER
//ASP.NET LIFECYCLE EVENT, SO I CAN DO SOME PROCESSING ON IT
//BEFORE BINDING IT TO THE UI.
}

protected void OpenEditPopUpWindowButton_Click(object sender, EventArgs e)
{
//HOW DO I PASS IDs BACK TO MyCustomControl AND FORCE MyCustomControl TO
//DO A POSTBACK, SO IT CAN UPDATE IT'S GUI WITH THE NEW IDs?
}

public List<int> IDs
{
      get{ return m_IDs; }
      set{
            m_IDs = value;
            IDRepeator.DataSource = m_IDs;
            IDRepeator.DataBind();
      }
}
}
///////////////////////////////////////////////////////




0
Comment
Question by:ppittle
  • 3
  • 2
5 Comments
 
LVL 9

Expert Comment

by:tetorvik
ID: 24311570
Would it be an alternative to not open a real popup window, but opening a ASP.NET Ajax modal popup instead.
Then there would be no need to pass the objects between pages.
See a sample implementation where a gridview is extended with editing form.
http://mattberseth.com/blog/2008/04/masterdetail_with_the_gridview.html
(The scenario is a bit different, but I think the same approach could fit also to your scenario)

0
 
LVL 8

Author Comment

by:ppittle
ID: 24326240
Tetorvik,

I reviewed that example, it makes use of AJAX, specifically the Ajax Toolkit add-on, which requires .NET 3.5.  I'm restricted to using .NET 2.0.  

Any other ideas that would fit this constraint?
0
 
LVL 9

Accepted Solution

by:
tetorvik earned 500 total points
ID: 24329208
There is also a toolkit version available for .NET 2.0, which contains modal popup
http://www.codeplex.com/AjaxControlToolkit/Release/ProjectReleases.aspx?ReleaseId=11121

see also an alternative implementation using jQuery instead of Ajax Toolkit.
http://mattberseth.com/blog/2008/06/masterdetail_with_the_gridview_1.html
0
 
LVL 8

Author Comment

by:ppittle
ID: 24330459
The jQuery tutorial looks interesting, let me take a look at it and get back to you.
0
 
LVL 8

Author Closing Comment

by:ppittle
ID: 31578150
Ended up going with the Modal Popup using the AJAX Extensions for ASP.NET 2.0 and the AjaxToolkit.  Worked great!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question