在javascript和codebehind中连接div [英] connect div in both javascript and codebehind

查看:80
本文介绍了在javascript和codebehind中连接div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在javascript中连接了div标签以显示验证错误消息。如果出现错误,将显示错误消息。如果用户单击该按钮,则不应允许用户移动到下一页,因此我将检查代码隐藏中div的可见性。怎么做。

解决方案

正如Raje指出的那样,您可以通过添加 runat =从您的代码中访问DIV标签服务器属性到页面上的DIV标记:

 <  < span class =code-leadattribute> div     id   =  myDivTag      runat   =  server    class   =  someCSS >  
my div
< / div >



然后你可以从你的代码中访问标签来测试它的可见性如下:

< pre lang =c#> if (myDivTag.Style [ 显示]!= none
{
// DIV是可见的,所以做一些事情
}


I have connected a div tag in javascript to show validation error messages.If there is an error the error msg will appear. If the user clicks the button the user should not be allowed to move to next page so i am checking the visibility of div in codebehind. How to do that.

解决方案

As Raje has pointed out, you can access a DIV tag from your code behind by adding the runat="server attribute to the DIV tag on your page:

<div id="myDivTag"  runat="server" class="someCSS">
     my div
</div>


Then you can access the tag from your code behind to test it''s visibility like so:

if (myDivTag.Style["Display"] != "none")
{
     // DIV is visible, so do some stuff
}


这篇关于在javascript和codebehind中连接div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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