如何在aspx页面中多次使用相同的用户控件 [英] How to use same user control multiple times in aspx page

查看:74
本文介绍了如何在aspx页面中多次使用相同的用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在aspx页面中多次使用相同的用户控件,并在选项卡上单击加载用户控件。



我已经定义了一个用户控件(UDTControl.ascx),并在每个选项卡面板中声明了它。在选项卡上单击,基于选项卡索引我将tabname传递给ascx函数,并调用sp在表中加载数据。



How to use same user control multiple times in aspx page and load the user control on tab click.

I've defined an user control(UDTControl.ascx) and declared it in each tab panel. On tab click, based on tab index I'm passing the tabname to ascx function and the call the sp to load data in the table.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="temp.aspx.cs" Inherits="WebUI.temp" %>
   <%@ Register Src="Shared/UDTControl.ascx" TagName="UDTControl" TagPrefix="UserControl" %>
   <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

   <asp:Content ID="Content1" ContentPlaceHolderID="PublicContent" runat="server">
     <script type="text/javascript">
          function ActiveTabChanged(sender, e) {
              var ActiveIndex = sender.get_activeTabIndex();
              if (ActiveIndex == 0) {
                  UDTControlFuncAscx("abc");
              }
              if (ActiveIndex == 1) {
                  UDTControlFuncAscx("xyz");
              }
              if (ActiveIndex == 2) {
                  UDTControlFuncAscx("mno");
              }
          }
    </script>
     <asp:UpdatePanel ID="UpdatePanel1" runat="server">
       <ContentTemplate>
         <cc1:TabContainer ID="DashboardContainer" runat="server"OnClientActiveTabChanged="ActiveTabChanged" >
                <cc1:TabPanel ID="TabPanel1" runat="server" HeaderText="abc">
                    <UserControl:UDTControl ID="id1" runat="server"/>
                </cc1:TabPanel>
                <cc1:TabPanel ID="TabPanel2" runat="server" HeaderText="xyz">>
                      <UserControl:UDTControl ID="id2" runat="server"/>
                </cc1:TabPanel>
                <cc1:TabPanel ID="TabPanel3" runat="server" HeaderText="mno">>
                      <UserControl:UDTControl ID="id3" runat="server"/>
                 </cc1:TabPanel>
        </ContentTemplate>
   </asp:UpdatePanel>
   </asp:Content>







Quote:

和以下是我的ascx代码

and following is my ascx code







<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UDTControl.ascx.cs" Inherits="WebUI.Shared.UDTControl" %>
    <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
    
    <%@ Register Assembly="WebUI" TagPrefix='SFX' Namespace='WebUI.Shared' %>
     
     <script type="text/javascript">
         function DashboardFuncAscx(ActiveTab) {
             if (ActiveTab == "abc") {
             //call abc sp using page method and load data on table
             }
             if (ActiveTab == "xyz") {
                 //call xyz sp and load on table
             }
         }
     </script>
    
    <asp:UpdatePanel ID="DashboardPanel" runat="server">
        <ContentTemplate>
             <asp:Panel ID="Dashboard1" runat="server">
                 <table id="tableid" > </table>
            </asp:Panel>
        </ContentTemplate>          
    </asp:UpdatePanel>





我的尝试:



目前,我面临着上述逻辑问题。这对于第一个选项卡工作正常,但是当我点击第二个选项卡时SP被触发并且数据也被提取但结果没有显示bcz结果被加载到第一个选项卡用户控件上。



What I have tried:

Currently, I'm facing an issue with above logic. This is working fine for first tab, but when i click on second tab SP is triggered and data is also fetched but the result is not showing bcz result is loaded on the first tab user control.

推荐答案

方法ActiveTabChanged中的发件人具有类型对象。对象对.get_activeTabIndex一无所知。

您应该将发件人分配给与您的Control对应的Type,并向此元素询问.get_activeTabIndex - 我想您会现在得到正确答案......
The Sender in your Method "ActiveTabChanged" has the Type Object. An Object doesn't know anything about the ".get_activeTabIndex".
You should assign the sender to a Type which corresponds to your Control and ask this element for the ".get_activeTabIndex" - I think you will now get the right answer ...


这篇关于如何在aspx页面中多次使用相同的用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆