开发者

Determine which tab an action was called from?

开发者 https://www.devze.com 2023-01-13 15:53 出处:网络
I\'m editing some code which wasn\'t written by myself but someone who\'s no longer here. The page I\'m editing had three tabs, each tab contains a diffrentgrid view which is populated by a search bo

I'm editing some code which wasn't written by myself but someone who's no longer here.

The page I'm editing had three tabs, each tab contains a diffrent grid view which is populated by a search box with in the tab. Each row in the grid view has a check box. When a print button is pressed all records with a tick in the check box should be printed off. Then page then reloads but some of the content is missing due to the way the page has been coded.

This is becuase some of the code is only called when the tab is clicked not on postback. Is there anyway that I change the following code so that it's called after postback?

These are the functions that are causing the most problem.. I need them to be loaded for the correct tab on postback.. I can't do it for all three as the code takes forever to run in that case.

AddActionsToGridView(gvGlobal); AddCheckboxes开发者_如何学PythonToGridView(gvGlobal);

    {
        if (tabconConsignments.ActiveTabIndex == 0)
       {
            dtGlobalIDConsignments = fGenerateTableSQL(astrPalletIDs, DateFrom, DateTo, ddlReqColDel.SelectedValue, "GlobalID", "", "");

            //Global ID Tab
            gvGlobal.DataSource = dtGlobalIDConsignments;
            gvGlobal.DataBind();

            //Actions
            AddActionsToGridView(gvGlobal);
            AddCheckboxesToGridView(gvGlobal);

       }
      else if (tabconConsignments.ActiveTabIndex == 1)
       {

            dtCreatedDateConsignments = fGenerateTableSQL(astrPalletIDs, DateFrom, DateTo, ddlReqColDel.SelectedValue, "CreatedDate", "", "");

            //Created Date Tab
            gvCreationDate.DataSource = dtCreatedDateConsignments;
            gvCreationDate.DataBind();
            tbCreationDateSearch.Text = "";

            //Actions
            AddActionsToGridView(gvCreationDate);
            AddCheckboxesToGridView(gvCreationDate);

        }
        else if (tabconConsignments.ActiveTabIndex == 2)
        {
                dtAccountsConsignments = fGenerateTableSQL(astrPalletIDs, DateFrom, DateTo, ddlReqColDel.SelectedValue, "Account", "", "");

                //Account Tab
                gvAccount.DataSource = dtAccountsConsignments;
                gvAccount.DataBind();

                AddActionsToGridView(gvAccount);
                AddCheckboxesToGridView(gvAccount);
            }

Please let me know if you want me to post any more code or any more info it's been a hard one for me to get my head around so I might of missed something out. Thank you for any help you can provide.


Hard to say if I'm answering your question because the thread title seems a bit different than the content. Are you just trying to move your code to a place that gets called during a postback instead of during the tab click event? If so, just move it to the page load event and specify that you want it to run only during a postback like so:

protected void Page_Load(object sender, EventArgs e)
{
    if(this.Page.IsPostBack)
    {
        switch (tabconConsignments.ActiveTabIndex)
        {
            case 0:
                // Do your stuff here.
                break;
            case 1:
                // Do your stuff here.
                break;
            case 2:
                // Do your stuff here.
                break;
            default:
                // Do your stuff here.
                break;
        }
    }
}


I would imagine something like this

    protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
                SetTabGrids(();
        }
        protected void btnPrint_Click(object sender, EventArgs e)
        {
            //Code
            SetTabGrids();
        }
        protected void tabconConsignments_TabIndexChanged(object sender, EventArgs e)
        {
            //Code
            SetTabGrids();
        }

        private void SetTabGrids()
        {
            switch(tabconConsignments.ActiveTabIndex)
                case 0: //Global ID Tab
                    dtGlobalIDConsignments = fGenerateTableSQL(astrPalletIDs, DateFrom, DateTo, ddlReqColDel.SelectedValue, "GlobalID", "", "");
                    gvGlobal.DataSource = dtGlobalIDConsignments;
                    gvGlobal.DataBind();
                    AddActionsToGridView(gvGlobal);
                    AddCheckboxesToGridView(gvGlobal);
                    break;
                case 1: //Created Date Tab
                    dtCreatedDateConsignments = fGenerateTableSQL(astrPalletIDs, DateFrom, DateTo, ddlReqColDel.SelectedValue, "CreatedDate", "", "");
                    gvCreationDate.DataSource = dtCreatedDateConsignments;
                    gvCreationDate.DataBind();
                    tbCreationDateSearch.Text = "";
                    AddActionsToGridView(gvCreationDate);
                    AddCheckboxesToGridView(gvCreationDate);
                    break;
                case 2:
                    dtAccountsConsignments = fGenerateTableSQL(astrPalletIDs, DateFrom, DateTo, ddlReqColDel.SelectedValue, "Account", "", "");
                    gvAccount.DataSource = dtAccountsConsignments;
                    gvAccount.DataBind();
                    AddActionsToGridView(gvAccount);
                    AddCheckboxesToGridView(gvAccount);
                    break;
            } 
        }

When the page loads for the first time, perform the grid binding by calling the SetTabGrids() method. After that, make sure to call SetTabGrids when you're dealing with your PostBack for PrintButtonClick and TabIndexChange.

0

上一篇:

:下一篇

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号