插入仅给定时间的标签名称,但给出空值 [英] Insert the time only label name given but null value given

查看:64
本文介绍了插入仅给定时间的标签名称,但给出空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< asp:Label ID =lblrunat =serverCssClass =cssLabel>



<asp:Label ID="lbl" runat="server" CssClass="cssLabel">

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
     <script type="text/javascript">
         $(document).ready(function () {
             ShowTime();
         });
         function ShowTime() {
             var dt = new Date();
             document.getElementById("C1_lbl").innerHTML = dt.toLocaleTimeString();
             window.setTimeout("ShowTime()", 1000); // Here 1000(milliseconds) means one 1 Sec
         }
</script>





out put可以给出

==================

12:45:47 PM



我可以从数据库表插入这个值

================================ =================

cmd.Parameters.Add(@ Timing,SqlDbType.NVarChar,100).Value = lbl.text;



空值可以显示



out put can given
==================
12:45:47 PM

and i can insert this value from database table
=================================================
cmd.Parameters.Add("@Timing", SqlDbType.NVarChar, 100).Value = lbl.text;

null value can show

推荐答案

(文件).ready(function(){
ShowTime();
});
函数ShowTime(){
var dt = new Date();
document.getElementById(C1_lbl)。innerHTML = dt.toLocaleTimeString();
window.setTimeout(ShowTime(),1000); //这里1000(毫秒)表示一个1秒
}
< / script >
(document).ready(function () { ShowTime(); }); function ShowTime() { var dt = new Date(); document.getElementById("C1_lbl").innerHTML = dt.toLocaleTimeString(); window.setTimeout("ShowTime()", 1000); // Here 1000(milliseconds) means one 1 Sec } </script>





out put可以给出

==================

12:45:47 PM



我可以从数据库表插入这个值

================================ =================

cmd.Parameters.Add(@ Timing,SqlDbType.NVarChar,100).Value = lbl.text;



null值可以显示



out put can given
==================
12:45:47 PM

and i can insert this value from database table
=================================================
cmd.Parameters.Add("@Timing", SqlDbType.NVarChar, 100).Value = lbl.text;

null value can show


更改脚本

document.getElementById(<% = lbl.ClientId%>)。innerHTML = dt.toLocaleTimeString();
change the script
document.getElementById("<%=lbl.ClientId %>").innerHTML = dt.toLocaleTimeString();


在javascript中,您将获得元素C1_lbl并设置其时间。在ASP HTML中你有lbl runat = server ...显然你没有正确获取id。



原因是服务器端控件的ID被破坏了它们在页面中是唯一的,无论它们之间的容器级别和母版页是什么。



尝试这个来调试:

In javascript you're getting the element C1_lbl and setting its time. In ASP HTML you have lbl runat=server...obviously you're not getting the id correctly.

The reason is that server side controls get their IDs mangled so they are unique across the page regardless of container levels and master pages between them.

Try this to debug:
var lbl = document.getElementById("C1_lbl");
console.log(lbl); // you will see null here





你应该拥有什么:



What you should have:

var lbl = document.getElementById("<%=lbl.ClientId %>");
console.log(lbl); // here you should have value

lbl.innerHTML = dt.toLocaleTimeString();





console.log是将页面中的值打印到开发人员工具控制台的方法(每个主要浏览器都有自己的可通过按F12访问开发人员工具集。





如果这有帮助,请花时间接受解决方案。谢谢。



console.log is the method for printing out values from the page into Developer tools console (each major browser has its own developer tool set accessible by pressing F12)


If this helps please take time to accept the solution. Thank you.


这篇关于插入仅给定时间的标签名称,但给出空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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