473,385 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Popup window loading before itemcommand event firing

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
2 3374
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: John Richardson | last post by:
I've been bothered for some time about my DataGrid not populating my rows very quickly. I have about 10K rows loading into the grid. I create a datatable dt with 2 columns, an ID and a display. ...
4
by: Steven | last post by:
Hi there, I am having a weird problem. I have a datagrid with both an ItemCommand and a SortCommand. It was working fine until a day ago. Now, whenever I click a column to fire the...
6
by: Kenneth | last post by:
Hi, function NewWindow(mypage, myname, w, h, scroll) { var winl = (screen.width - w) / 2; var wint = (screen.height - h) / 2; winprops =...
0
by: ChrisB | last post by:
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...
2
by: Deepesh | last post by:
Good day, I have a specific case of the DataGrid in my solution which is causing the ItemCommand Event Not Firing. So I'm creating a "Skinnable" set of controls. I seperate the actual ASCX file...
2
by: Curt_C [MVP] | last post by:
I've got a Repeater and within it a LinkButton. The LinkButton has an CommandName="Test" In the Repeater's ItemCommand event I want to check for this command name but the problem I'm having is...
4
by: EvelynAnd Ethan | last post by:
Hi, ItemCommand event not firing from a dynamic user control ,WHERE A DATAGRID HAS BUTTON,when i click on the linkbutton first time the itemcommand event doesnt fire,second time event fires up ...
3
by: danc | last post by:
I have a datagrid with a checkbox and dropdown list in each row. Both set AutoPostBack to true and ItemCommand and OnSelectedIndexChanged events for these controls works fine when DataGrid is not...
7
by: anthony.turcotte | last post by:
Hi, I've looked for a solution to this problem on google, read posts in this newsgroup and I still haven't found anything that could help me. Here's the scenario. 1. User accesses...
1
by: shantanu_kush | last post by:
Hi there, I am using a DataList in a composite control. The DataList has an Custom ItemTemplate(ITemplate) which adds a Button to the DataList Item as shown in the code below : public class...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.