且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

aspx页面中的Javascript,包括母版页

更新时间:2023-12-01 16:14:16

var customerSubString=document.getElementById('<%=textCustomerName.ClientID%>')

It gave me null value in variable customerSubString but it works if I use complete id "ctl00_ContentPlaceHolder1_textCustomerName" in place of using ClientId Property.



我认为这意味着您是在js文件中完成的,就像我告诉您不要那样做.



I assume this means you did it in your js file, like I told you not to. It''s not being evaluated.


您有一个基本问题,与母版页无关.


You have a fundamental problem, and it has nothing to do with master pages.


Divymital写道:
Divymital wrote:

= document.getElementById("textCustomerName").value;

= document.getElementById("textCustomerName").value;



您在服务器端分配的名称不是在客户端使用的名称.该控件具有ClientID属性,您需要在服务器***问该属性并将其插入到javascript中.这意味着脚本的一部分不能存在于js文件中.我的管理方式是让我的js文件通过名为clientSideCustomerNameId之类的变量访问ID.然后,我后面的代码发出js,以创建具有正确值的变量.



The name you assign on the server side, is not the name used on the client side. The control has a ClientID property, and you need to access that on the server and insert it into your javascript. This means that bit of script cannot live in a js file. The way I manage this is for my js file to access an id via a variable called something like clientSideCustomerNameId. Then my code behind emits the js to create that variable with the right value.




感谢您的答复.

当我使用代码时:

var customerSubString = document.getElementById(''<%= textCustomerName.ClientID%>''))

它为我提供了变量customerSubString中的空值,但如果我使用完整的id"ctl00_ContentPlaceHolder1_textCustomerName"代替ClientId属性,则它可以工作.

问候,
Divya
Hi,

Thanks for your reply.

When I used code:

var customerSubString=document.getElementById(''<%=textCustomerName.ClientID%>'')

It gave me null value in variable customerSubString but it works if I use complete id "ctl00_ContentPlaceHolder1_textCustomerName" in place of using ClientId Property.

Regards,
Divya