asp.net javascript问题 [英] asp.net javascript issue

查看:78
本文介绍了asp.net javascript问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是asp.net的新手,javascript,

1。你可以告诉我之间的区别是什么:

 cmtenTextBox = document.getElementById('<% = TextBox1.ClientID%>'); 



  var  tb =  document  .getElementById('  TextBox1' ); 





2。我有一个由visual studio 2008完成的应用程序,现在我打开它与vs 2012,改变了什么?我的意思是它是我的应用程序的升级?我的申请究竟发生了什么变化?感谢您的回复。

解决方案

当您在应用程序中使用母版页时,差异就会出现。

当我们在我们的网页中使用母版页时内容页面内的控件网页将控制主页面名称附加到每个控件以使其唯一。



因此,如果您尝试使用javascript getElementById找到控件('Textbox1')你无法找到控件,因为它被修改。



因此对于这种情况使用document.getElementById('<%= TextBox1.ClientID %>')因为它给你控件的更新ID。



如果你没有使用任何母版页,那么两者都没有区别。



希望这会对你有所帮助。



-SG


1 。看看 ClientID属性 [ ^ ]

并查看这些示例

ID,ClientID和UniqueID之间的区别 [ ^ ]

在ASP.NET中控制Web控件ClientID值 [ ^ ]

2 。检查这是如何工作

Visual Studio Conversion [ ^

hi guys, i am new to asp.net with javascript,
1 . Could u plz tell me what's the difference between :

cmtenTextBox = document.getElementById('<%= TextBox1.ClientID %>');

and

var tb = document.getElementById('TextBox1');



2 . i have a app done by visual studio 2008 ,and now i open it with vs 2012 , what changed? i mean is it an upgrade for my app? what exactly changed for my application? thanks for any response.

解决方案

the difference come to picture when you use Masterpage in your application.
When we use master page in our web page than control inside the content page append master page name to each and every control to make it unique.

So if you try to get find the control using javascript getElementById('Textbox1') you are unable to find the control as it get modified.

so for such scenario use document.getElementById('<%= TextBox1.ClientID %>') as it give you the updtaed Id of the control.

if you are not using any master page than in that case there is no difference in both.

Hope this helps you.

-SG


1.Take a look at ClientID Property[^]
And check these for examples
The difference between ID, ClientID and UniqueID[^]
Take Control Of Web Control ClientID Values in ASP.NET[^]
2.Check this how works
Visual Studio Conversion[^]


这篇关于asp.net javascript问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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