开发者

HTML Controls visible property in asp.net

开发者 https://www.devze.com 2023-04-13 05:40 出处:网络
I have a span element in my asp.net page without runat server attribute. I need to set this span\'s visibility, but the decision to make it visible has to come from c开发者_C百科ode behind. I don\'t w

I have a span element in my asp.net page without runat server attribute. I need to set this span's visibility, but the decision to make it visible has to come from c开发者_C百科ode behind. I don't want to set runat="server"


You could try something like this in your code behind, I am using jQuery but no need to really.

System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>$('#MySpan').fadeOut('slow');</SCRIPT>");

Update:

You can read an variable from the server to see if you want to render the span or not while rendering the page. jQuery Code.. ShowMySpan is an public int variable on the server

<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        if (<%: ShowMySpan %> == 0) {
            $("#MySpan").css("visibility", "hidden");
        }          
    });
</script> 


This will probably help you Using JavaScript Along with ASP.NET. Here you will be better to go through ScriptManager.

I think the way StefanE done will work. Will be easy if you use class instead of ID since the ID may be changed during runtime. Also it will be better to use hide() so you can do something like $('.MySpan').hide()

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号