简体   繁体   中英

ASP.Net: TabContainer: TabPanel Click Event

I am using the TabContainer in my asp.net app. It has 15 tabs (TabPanels). I would like to redirect a user to a URL when the first tab is clicked. I also need to add some querystring values to the URL.

I tried this is the code behind:

protected void TabContainer_ActiveTabIndexChanged()
        {
            if (TabContainer1.ActiveTabIndex == 0)
            {
                string redirectURL = "Case.aspx?Action=0&CaseId=" + lblCaseId.Text + "&ChildId=" + lblChildId.Text 

                Response.Redirect(redirectURL);
            }
        }

And this in the ASPX page:

<cc1:TabPanel ID="TabPanel8" runat="server" OnClientClick="TabContainer_ActiveTabIndexChanged">

However, it broke the page.

Thanks for your time.

You are doing it in a wrong way.

OnClientClick="TabContainer_ActiveTabIndexChanged"

This method is to run on JavaScript side, if you want to do in JavaScript write a function in JavaScript and write your logic there.

If you want server side use

ActiveTabChanged

And write an if condition to find which tab is active and write your logic there

If you add the event handler in your Tab Container tag. I think it will do the trick (presuming your event handler is coded properly).

It should look something like this:

<cc1:TabContainer ID="TabContainer1" runat="server"  OnActiveTabChanged="TabContainer_ActiveTabIndexChanged">

Also, you will need to eliminate the OnClientClick from your (all) individual tabs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM