Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-05-05
5
Medium Priority
?
2,743 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 2000 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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

885 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