Popup window loading before itemcommand event firing

Discussion in 'ASP .Net' started by ChrisB, Apr 20, 2004.

  1. ChrisB

    ChrisB Guest

    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
    ChrisB, Apr 20, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
    Martin Dechev, Apr 21, 2004
    #2
    1. Advertising

  3. 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!
    Chris Brannon, Apr 21, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGVlcGVzaA==?=

    Datagrid ItemCommand Event Not Firing

    =?Utf-8?B?RGVlcGVzaA==?=, Oct 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    5,779
    =?Utf-8?B?RGVlcGVzaA==?=
    Oct 6, 2005
  2. EvelynAnd Ethan
    Replies:
    4
    Views:
    960
    =?Utf-8?B?Sko=?=
    Jan 9, 2006
  3. EvelynAnd Ethan
    Replies:
    0
    Views:
    389
    EvelynAnd Ethan
    Oct 17, 2005
  4. EvelynAnd Ethan
    Replies:
    0
    Views:
    535
    EvelynAnd Ethan
    Oct 17, 2005
  5. =?Utf-8?B?ZGFuYw==?=

    DataGrid ItemCommand event not firing if not first page

    =?Utf-8?B?ZGFuYw==?=, Oct 26, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    4,130
    =?Utf-8?B?ZGFuYw==?=
    Oct 26, 2005
Loading...

Share This Page