C
ChrisB
I'm attempting to open a new window from a LinkButton in a DataGrid.
I can set a session variable in the ItemCommand event for the
LinkButton like so:
// this is used to handle the ItemCommand event
private void itmCmd(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string itemGFNo = "";
if (e.CommandName == "EditTask")
{
if(e.CommandSource is LinkButton)
{
LinkButton lb = (LinkButton)e.CommandSource;
if (e.Item.FindControl("GFNoButton") != null)
{
itemGFNo = ((LinkButton).Item.FindControl"GFNoButton")).Text;
}
SetGFNoSession(itemGFNo); //set session var here
}
}
DataGridTaskList1.DataBind();
}
In the ItemDataBound event I can find the LinkButton and assign an
attribute like so:
private void DataGridTaskList1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.FindControl("EditTaskButton") != null)
{
((LinkButton) e.Item.FindControl
("EditTaskButton")).Attributes.Add("onclick",
"window.open('AddTaskPopup.aspx',null,'status= no, resizable= no,
scrollbars=no, toolbar=no,location=no,menubar=no ');");
}
}
The result is that on the AddTaskPopup page (in the page_load event) I
can get the session var and use it however I need to.
This works great the first time through, but each time thereafter the
session var is not set properly. Here's the sequence of events:
1) Page_Load event with datagrid fires
2) itemdatabound event fires (where I set the attribute to window.open
for AddTaskPopup)
3) I click on the LinkButton, the ItmCmd event fires setting the
session var
4) The page_load event for the popup fires, (and I set a label using
the session var I set in the ItmCmd event)
5) the popup AddTaskPopup opens up
6) I close the popup window using this code:
string strScript = "<script>";
strScript += "window.close();";
strScript += "</script>";
Response.Write(strScript);
7) The Page_Load event for the popup fires again
8) I'm returned to the original page, where I click another list
button
9) The page_load event for the original page fires
10) The ItmCmd event fires, changing the session var accordingly
11) The popup AddTaskPopup opens up again
The problem is, the session var I set in the ItmCmd event is not
updated becuase the PopUp loaded BEFORE the ItmCmd event, not AFTER!
So anything I do in the ItmCmd event has no effect on the Popup
because the Page_load event is called before my ItmCmd event ever
fires/
I think it may be a timing issue because it appeared to run correctly
a few times while debugging the code to write down the sequence of
events.
Anyone have an idea what's going on?
Thanks in advance,
Chris
I can set a session variable in the ItemCommand event for the
LinkButton like so:
// this is used to handle the ItemCommand event
private void itmCmd(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string itemGFNo = "";
if (e.CommandName == "EditTask")
{
if(e.CommandSource is LinkButton)
{
LinkButton lb = (LinkButton)e.CommandSource;
if (e.Item.FindControl("GFNoButton") != null)
{
itemGFNo = ((LinkButton).Item.FindControl"GFNoButton")).Text;
}
SetGFNoSession(itemGFNo); //set session var here
}
}
DataGridTaskList1.DataBind();
}
In the ItemDataBound event I can find the LinkButton and assign an
attribute like so:
private void DataGridTaskList1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.FindControl("EditTaskButton") != null)
{
((LinkButton) e.Item.FindControl
("EditTaskButton")).Attributes.Add("onclick",
"window.open('AddTaskPopup.aspx',null,'status= no, resizable= no,
scrollbars=no, toolbar=no,location=no,menubar=no ');");
}
}
The result is that on the AddTaskPopup page (in the page_load event) I
can get the session var and use it however I need to.
This works great the first time through, but each time thereafter the
session var is not set properly. Here's the sequence of events:
1) Page_Load event with datagrid fires
2) itemdatabound event fires (where I set the attribute to window.open
for AddTaskPopup)
3) I click on the LinkButton, the ItmCmd event fires setting the
session var
4) The page_load event for the popup fires, (and I set a label using
the session var I set in the ItmCmd event)
5) the popup AddTaskPopup opens up
6) I close the popup window using this code:
string strScript = "<script>";
strScript += "window.close();";
strScript += "</script>";
Response.Write(strScript);
7) The Page_Load event for the popup fires again
8) I'm returned to the original page, where I click another list
button
9) The page_load event for the original page fires
10) The ItmCmd event fires, changing the session var accordingly
11) The popup AddTaskPopup opens up again
The problem is, the session var I set in the ItmCmd event is not
updated becuase the PopUp loaded BEFORE the ItmCmd event, not AFTER!
So anything I do in the ItmCmd event has no effect on the Popup
because the Page_load event is called before my ItmCmd event ever
fires/
I think it may be a timing issue because it appeared to run correctly
a few times while debugging the code to write down the sequence of
events.
Anyone have an idea what's going on?
Thanks in advance,
Chris