简体   繁体   English

ASP.Net:TabContainer:TabPanel单击事件

[英]ASP.Net: TabContainer: TabPanel Click Event

I am using the TabContainer in my asp.net app. 我在asp.net应用程序中使用TabContainer。 It has 15 tabs (TabPanels). 它具有15个选项卡(TabPanels)。 I would like to redirect a user to a URL when the first tab is clicked. 单击第一个选项卡时,我想将用户重定向到URL。 I also need to add some querystring values to the URL. 我还需要向URL添加一些querystring值。

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: 而这在ASPX页面中:

<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" 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. 此方法在JavaScript端运行,如果要在JavaScript中执行,请在JavaScript中编写一个函数,然后在其中编写逻辑。

If you want server side use 如果要服务器端使用

ActiveTabChanged ActiveTabChanged

And write an if condition to find which tab is active and write your logic there 并编写一个if条件来查找哪个选项卡处于活动状态并在其中写入逻辑

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 另外,您需要从(所有)单个标签中删除OnClientClick

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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