Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript在usercontrol上隐藏和显示div_Javascript_Asp.net_User Controls - Fatal编程技术网

如何使用javascript在usercontrol上隐藏和显示div

如何使用javascript在usercontrol上隐藏和显示div,javascript,asp.net,user-controls,Javascript,Asp.net,User Controls,我必须为que和rply开发功能,因为我已经根据我的要求创建了用户控件作为fallow,我已经添加了div,其中包含用户控件上的依赖和提交按钮的文本框,并将div显示样式保持为none,我调用显示该div的javascript回复链接 <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SuppReview.ascx.cs" Inherits="LaaFoodWebApp.SuppReview" %> <d

我必须为que和rply开发功能,因为我已经根据我的要求创建了用户控件作为fallow,我已经添加了div,其中包含用户控件上的依赖和提交按钮的文本框,并将div显示样式保持为none,我调用显示该div的javascript回复链接

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SuppReview.ascx.cs" Inherits="LaaFoodWebApp.SuppReview" %>

<div>
    <table style="width:100%;">
        <tr>
            <td rowspan="2" style="width: 15%; vertical-align: top;">
                <asp:Label ID="lblMsgType" runat="server"></asp:Label>
                <br />
                <asp:Label ID="lblMsgId" runat="server"></asp:Label>
            </td>
            <td style="width: 70%; vertical-align: top;">
                <asp:Label ID="lblMsgtBody" runat="server"></asp:Label>
            </td>
            <td style="width: 15%">
                <asp:Label ID="lblVDate" runat="server"></asp:Label>
                <br />
                By 
                <asp:Label ID="lblname" runat="server"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                <a id="toggleReply" style="color: #15ADFF" href="#">Reply</a>
            </td>
            <td>
                <asp:Label ID="lblEmail" runat="server"></asp:Label>
                <br />
                <asp:Label ID="lblPhone" runat="server"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
            <panel id="pnlreply" >
               <div id="DivReply" style="display:none">
                <table style="width:100%;">
                    <tr>
                        <td style="width: 15%">
                           Replys</td>
                        <td>
                            <asp:TextBox ID="TextBox1" runat="server" Height="50px" TextMode="MultiLine" 
                                Width="100%"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;</td>
                        <td style="text-align: right">
                            <asp:Button ID="btnSubmit" runat="server" Text="Submit" 
                                onclick="btnSubmit_Click" />
                        </td>
                    </tr>
                    </table></div></panel>
            </td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
</div>


答复
但当我根据replyes的计数多次添加这些用户控件时

for (int i = 0; i< dt.Rows.Count; i++)
{
    SuppReview SR = (SuppReview)Page.LoadControl("SuppReview.ascx");
    SR.settxt(dt.Rows[i]);
    reviews.Controls.Add(SR);
}
for(int i=0;i
在页面上

<%@ Page Title="" Language="C#" MasterPageFile="~/SupplierMasterNew.Master" AutoEventWireup="true" CodeBehind="Supp_Views.aspx.cs" Inherits="LaaFoodWebApp.Supp_Views" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
 <script type="text/javascript">
     $(function () {
         $('#toggleReply').click(function () {
             $('#DivReply').toggle('slow');
             return false;
         });
     });
      </script>     
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CPHcontent" runat="server">
    <div style="width: 100%; height: 24px; background-color: #D2EEF2; padding-top: 10px;
                font-size: large; color: #000000; text-align: left;">
        &nbsp;&nbsp;&nbsp; View</div>

    <asp:Panel ID="reviews" runat="server">

    </asp:Panel>
</asp:Content>

$(函数(){
$('#toggleReply')。单击(函数(){
$('#DivReply')。切换('slow');
返回false;
});
});
看法

单击回复链接int hide多次显示div(包含依赖和提交按钮的文本框),但对其他条目无效

如果多次添加此控件,则页面上有多个重复ID

考虑将ID更改为类

也给你的控制中的外部div一个类!e、 g.

声明一个函数:

function toggleReply(sender) {
    $(sender).parent('.wrapper').children('.DivReply').toggle('slow');
}
您的链接:

<a class="toggleReply" style="color: #15ADFF" href="javascript:void(0);" onclick="toggleReply(this);">Reply</a>