简体   繁体   English

如何从VB.NET背后的代码控制可见性

[英]How to control the visibility from code behind VB.NET

I'm having a problem: I have a RadComboBox on Client Side if the user select a value that coming from the DB I'm showing tr and RadDateTimePicker with the current date and time. 我遇到了一个问题:如果用户选择一个来自数据库的值,则我在客户端具有RadComboBox,我正在显示tr和RadDateTimePicker以及当前日期和时间。 The thing is after I'm saving the form I'm disabling all the controls on the form the problem is after I'm saving the tr is disappearing but I have all the rest of the controls. 问题是在保存表单之后,我在表单上禁用了所有控件,问题是在保存tr之后,问题消失了,但是我拥有所有其余控件。 How can I prevent that from happened????? 我怎样才能防止这种情况发生? (the initial behavior is not to show the tr unless the user selecting a value from the RadComboBox) (除非用户从RadComboBox中选择一个值,否则初始行为是不显示tr)

ASPX code: ASPX代码:

<tr>
    <td class="GeneralFontShape" style="height:15px; vertical-align:top; border: 0px solid red;">
        Status:
    </td>
    <td class="GeneralFontShape" style="height:15px; border: 0px solid red; vertical-align:top;">
        <telerik:RadComboBox runat="server" ID="rcbStatus" Width="250px" CheckBoxes="False" TabIndex="10" Enabled="True" EmptyMessage="Select Status" OnClientSelectedIndexChanged="StatusCheck"></telerik:RadComboBox>        
    </td>

<tr id="EndingTime" style="visibility:hidden;">
     <td class="GeneralFontShape" style="height:15px; vertical-align:top; border: 0px solid red;" >
       <div id="divEndingTime" runat="server" visible="true"> Ending Time:</div> 
    </td>
    <td class="GeneralFontShape"  style="height:15px; border: 0px solid red; vertical-align:top;">
    <div id="divrdtpEndingTime" runat="server" visible="true">
       <telerik:RadDateTimePicker ID="rdtpEndingTime" runat="server" AutoPostBack="False" Visible="true"
            DateInput-Width="170px" onkeypress="return isNumberKey(event)" Width="250px" Culture="en-US">
            <TimeView ID="TimeView2" runat="server" CellSpacing="-1"></TimeView>
            <TimePopupButton HoverImageUrl="" ImageUrl="" />
            <Calendar ID="Calendar1" runat="server" EnableKeyboardNavigation="true" >
                <SpecialDays>
                    <telerik:RadCalendarDay Repeatable="Today" Date="" ItemStyle-BackColor="lightblue"></telerik:RadCalendarDay>
                </SpecialDays>                                       
            </Calendar>
            <DateInput ID="DateInput3" runat="server" ToolTip="Date input" LabelWidth="60px">                                        
                <EnabledStyle Width="150px" />                                        
            </DateInput>
            <DatePopupButton HoverImageUrl="" ImageUrl="" />
        </telerik:RadDateTimePicker> 
        </div>
    </td>
</tr> 

JS Code: JS代码:

    function StatusCheck(sender, args) {
    var status = $find("<%= rcbStatus.ClientID %>");
    var datePickerEndingTime = $find("<%= rdtpEndingTime.ClientID %>");
//  var EndingTime = datePickerEndingTime.get_selectedDate();
    var item = status.get_text();
    if (item == "Close") {
        document.getElementById('EndingTime').style.visibility = 'visible'
        datePickerEndingTime.set_visible(true);
        var nowDate = new Date();
        datePickerEndingTime.set_selectedDate(nowDate)
    } else {
        document.getElementById('EndingTime').style.visibility = 'hidden'
        datePickerEndingTime.set_visible(false);
    }
}

use a style sheet class to make the TR visible or invisible and in your javascript change this behavior as below: 使用样式表类使TR可见或不可见,并在您的javascript中更改此行为,如下所示:

Your style sheet class: 您的样式表类:

  .hidden { display: none !important; visibility: hidden !important; } 

Your TR element: 您的TR元素:

 <tr id="EndingTime" class="hidden"> 

Your JQuery code: (you need jquery to use the code below) 您的JQuery代码:(您需要使用jquery才能使用下面的代码)

 function StatusCheck(sender, args) { ..... if (item == "Close") { $("#EndingTime").removeClass("hidden"); .... }else { $("#EndingTime").addClass("hidden"); .... } } 

and you can do the same thing for the rest of your elements as well. 您也可以为其余元素做同样的事情。

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

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