Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-05-05
5
Medium Priority
?
2,735 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

670 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