By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,677 Members | 1,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,677 IT Pros & Developers. It's quick & easy.

Popup window loading before itemcommand event firing

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi, Chris,

It will be way simpler if you pass the info in the query string instead of
doing a roundtrip to the server to store it in the session. Apart from the
round-trip, you can't be sure which code will be executed first - the
LinkButton OnItemCommand or the AddTaskPopup.aspx Page_Load.

Hope this helps
Martin
"ChrisB" <cb******@ramquest.com> wrote in message
news:46**************************@posting.google.c om...
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


Nov 18 '05 #2

P: n/a
Martin,

Thanks for your reply. I was able to pass the value I needed with a
query string in the ItemDataBound event. I worry that if I wasn't able
to get the data I needed at the time the ItemDataBound event fired, I'd
still be in trouble.

Thanks again,
Chris

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.