Hi Rob,
Of course it is possible. I prepared a simple exmaple to show you which way
to go. Please note, I used AJAX predecessor ATLAS which should (in this case)
be fine. Example consists of two pages - main where you click to select
employees from the list located in a popup window, second page is just a
mentioned popup. In order to post the code in two pieces, i used script runat
server, but ideally you could move it to code behind.
-- begin RobsmainPage.as px --
<%@ Page Language="C#" AutoEventWireup ="true"
CodeFile="RobsM ainPage.aspx.cs " Inherits="RobsM ainPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<atlas:ScriptMa nager ID="ScriptManag er" EnablePartialRe ndering="True"
runat="server" />
<atlas:UpdatePa nel ID="UpdatePanel " RenderMode="Blo ck" runat="server"
Mode="Always">
<ContentTemplat e>
<asp:PlaceHolde r runat="server" ID="container" />
<asp:Button runat="server" ID="btnRefresh " Width="0" Height="0"
OnClick="btnRef resh_Click" />
<asp:HiddenFiel d runat="server" ID="selectedEmp loyeeId" />
</ContentTemplate >
</atlas:UpdatePan el>
<asp:Button runat="server" ID="btnSelect" Text="Select Employee to
Update..." OnClientClick=" SelectEmployee( ); return false;" />
<asp:Button runat="server" ID="btnSubmit" Text="Submit Selection"
OnClick="btnSub mit_Click" />
<script type="text/javascript">
//<!--
function EployeeSelected (id)
{
var hidden = $('<%= selectedEmploye eId.ClientID %>');
if (hidden)
hidden.value = id;
var btn = $('<%= btnRefresh.Clie ntID %>');
if (btn)
{
btn.click();
}
}
function SelectEmployee( )
{
var win = window.open('Ro bsPopupPage.asp x', 'RobsPopupPage' ,
'width=450,heig ht=350');
if (!win)
{
alert('Disable popup blocker please!');
}
}
// -->
</script>
<script runat="server">
protected void Page_Load(objec t sender, EventArgs e)
{
RecereateList() ;
}
protected void btnRefresh_Clic k(object sender, EventArgs e)
{
int id;
if (int.TryParse(s electedEmployee Id.Value, out id))
{
SelectedEmploye eIds.Add(id);
AddEmployeeToLi st(id);
}
}
private void AddEmployeeToLi st(int id)
{
Label label = new Label();
label.Text = "Employee selected with id = " + id.ToString();
label.Style.Add ("display", "block");
container.Contr ols.Add(label);
}
private void RecereateList()
{
foreach (int id in SelectedEmploye eIds)
{
AddEmployeeToLi st(id);
}
}
private ArrayList SelectedEmploye eIds
{
get
{
ArrayList value = (ArrayList)View State["SelectedEmploy eeIds"];
if (value == null)
{
value = new ArrayList();
ViewState["SelectedEmploy eeIds"] = value;
}
return value;
}
}
protected void btnSubmit_Click (object sender, EventArgs e)
{
// do something with selected employee ids:
foreach (int id in SelectedEmploye eIds)
{
// whatever
}
}
</script>
</form>
</body>
</html>
-- end RobsMainPage.as px --
-- begin RobsPopupPage.a spx --
<%@ Page Language="C#" AutoEventWireup ="true"
CodeFile="RobsP opupPage.aspx.c s" Inherits="RobsP opupPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<script type="text/javascript">
//<!--
function PerformSelect(i d)
{
if (window.opener)
{
if (window.opener. EployeeSelected )
window.opener.E ployeeSelected( id);
window.close();
}
}
//-->
</script>
<script runat="server">
protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{
employees.DataS ource = GetEmployees();
employees.DataB ind();
}
}
public System.Data.Dat aTable GetEmployees()
{
System.Data.Dat aTable table =
new System.Data.Dat aTable();
System.Data.Dat aRow row = null;
table.Columns.A dd("EmployeeId" , typeof(int));
table.Columns.A dd("EmployeeNam e", typeof(string)) ;
table.Columns.A dd("EmployeeRol e", typeof(string)) ;
for (int i = 0; i < 10; i++)
{
row = table.NewRow();
row[0] = i;
row[1] = "employee " + i.ToString();
row[2] = (i % 3 == 0) ? "Manager" : "Clerk";
table.Rows.Add( row);
}
return table;
}
</script>
<asp:GridView runat="server" ID="employees" AutoGenerateCol umns="false">
<Columns>
<asp:TemplateFi eld>
<HeaderTemplate >
Name
</HeaderTemplate>
<ItemTemplate >
<a href="javascrip t:PerformSelect ('<%# Eval("EmployeeI d") %>');"><%#
Eval("EmployeeN ame")%></a>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:BoundFie ld HeaderText="Epl oyee's Role" DataField="Empl oyeeRole" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
-- end RobsPopupPage.a spx --
Hope this helps
Milosz
"Rob Meade" wrote:
"Milosz Skalecki [MCAD]" wrote ...
It's very similar situation to dynamic controls. Dynamic controls are not
part of compiled control tree, so every time you make a request and
postback
you have to recreate them yourself.
Hi Milosz,
Thats kinda what I was guessing, bit of a pain but I guess I can work around
that.
One more thing - as I mentioned the users can select additional resources to
add to the profile, this is a long list, so I'm probably going to have to
fire it up in a popup window, are you aware of any way to use AJAZ/.Net so
that my popup can talk to the updatePanel on the parent page? I'm probably
trying to run before I can walk abit here, so please excuse my ignorance,
but what I would want to do I guess is launch a popup from a link or button,
this hits the database, lists all my resources as links with a querystring
parameter of the resource id. Once clicked I would like this to then act as
the "trigger" on the parent page using the parameter from the link to run
code to add the control the parent page..
Any thoughts?
Part of me is thinking "Rob, thats such a stupid question" but obviously I
can do this with a normal postback, but I dont really want the parent page
to reload, and I dont really want to have to write a load of code that
checks to see if the parent page is just loading, or loading as a result of
the child popup click event.
Any help appreciated.
Regards
Rob