我正在使用一个简单的Asp.Net按钮,并试图在页面加载事件中将其隐藏,因此我想在执行一些客户端脚本后将其显示回去。

我已经通过document.getElementById('<%=Button1.ClientID %>').style.visibility = "visible";尝试过了,它没有显示出来。

那么如何重新启用它呢?

Page_Load:

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 Button1.Visible = False
End Sub


这是我的脚本:

<script type="text/javascript">
    // Convert divs to queue widgets when the DOM is ready
    $(function () {
        $("#uploader").plupload({
            // General settings
            runtimes: 'gears,flash,silverlight,browserplus,html5',
            url: 'Final.aspx',
            max_file_size: '10mb',
            max_file_count: 25,
            chunk_size: '1mb',
            unique_names: true,

        // Resize images on clientside if we can
        //                    resize: { width: 320, height: 240, quality: 90 },

        // Specify what files to browse for
        filters: [
        { title: "Image files", extensions: "jpg,gif,png" },
        { title: "Zip files", extensions: "zip" }
    ],

        // Flash settings
        flash_swf_url: 'js/plupload.flash.swf',

        // Silverlight settings
        silverlight_xap_url: 'js/plupload.silverlight.xap'
    });


    // Client side form validation
    $('form').submit(function (e) {
        var uploader = $('#uploader').plupload('getUploader');

        // Files in queue upload them first
        if (uploader.files.length > 0) {
            // When all files are uploaded submit form
            uploader.bind('StateChanged', function () {
                if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
                    $('form')[0].submit();
                }
            });

            uploader.start();
        }
        else
            alert('You must at least upload one file.');

        return false;
    });
    var uploader = $('#uploader').plupload('getUploader');
    uploader.bind('FileUploaded', function (up, file, res) {
        $('#showfilelist').append("<div id=" + file.id + " class='thumb'><a href='uploads/" + document.getElementById("currentDirectory").value + "/" + file.name + "' target='_blank' rel='gallery'><img src='uploads/" + document.getElementById("currentDirectory").value + "/" + file.name + "' width='50' height='50'/></a></div>");
        $('#Maintabs').tabs('enable', 1);
        document.getElementById('<%=Button1.ClientID %>').style.visibility = "visible";
    });


});

最佳答案

如果将控件的Visible属性设置为false(在服务器端),则该控件将不会呈现给客户端,因此将无任何更改样式。

如果要在服务器上隐藏它,但仍将其呈现给客户端,请设置visibility CSS属性(通过Style属性),或为元素分配将其隐藏的CSS类(通过CssClass属性)。

关于javascript - 使用JavaScript的ASP.NET按钮可见性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7998060/

10-08 23:14