想要让可视性与控制的客户端真的,不可见从服务器端 [英] Want to make the visibility true from client side of the control which made invisible from server side

查看:86
本文介绍了想要让可视性与控制的客户端真的,不可见从服务器端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页的文本框。其可视性设置为从服务器侧假。现在我想通过使用Java脚本,使它从客户端可见。 (任何回发或部分回发不能在这种情况下实现的。)

I have a text box in a page. Whose visibility is set false from the server side. Now I want to make it visible from client side by using java-script. (Any post back or partial post back can not be implemented in this case.)

<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>ControlVisibilityClientSide</title>
            <script type="text/javascript">
                function toggleVisibility(controlId)
                {
                    var control = document.getElementById(controlId);
                    if(control.style.visibility == "visible" || control.style.visibility == "")
                        control.style.visibility = "hidden";
                    else
                        control.style.visibility = "visible";
                }
            </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <input type="button" ID="btnShowHide" value="Show/Hide" onclick="toggleVisibility('TextBox1');" />
            </div>
        </form>
    </body>
</html>

这是工作的罚款。

但是当我使用

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TextBox1.Visible = false;
    }
}

以上code是不工作的。

The above code is not working at all.

任何一个可以请帮我从这个问题或任何建议将AP preciated。

Can any one please help me out from this problem or any suggestion will be appreciated.

推荐答案

如果您设置控制的visible = false 也不会在客户端渲染,但是有一个棘手的解决方案,这将完成同样的事情。

If you set the control visible=false it will not render at client side, But there is a tricky solution, that will accomplish the same thing.

在你的页面加载,你在哪里设置可见=假,您可以在风格设置为显示:无

In your page load, where you are set Visible=false, you can set the style to display:none

protected void Page_Load(object sender, EventArgs e)
{
   TextBox1.Attributes.Add("style", "display:none");
}

这将使在客户端的控制,但用户看不到,然后你可以在看到JavaScript函数控制设置风格Diplay:块,等等。 ..

document.getElementById('<%=TextBox2.ClientID %>').style.display = 'block';

这篇关于想要让可视性与控制的客户端真的,不可见从服务器端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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