本文介绍了如何将asp.net文本框控件传递给JavaScript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 Hello Friends, 我有一个名为timepicker.js的javascript文件,用于Time Pick,其中包含一个名为selectTime的函数。这个函数有两个参数ctrl1和ctrl2,如下所示 selectTime(ctrl1,ctrl2){} 从aspx页面我传递了2个图像和文本框值。当我从弹出窗口中选择时间时,选择正确的时间并显示到文本框中,但它在页面上显示对象必需的错误。我将文本框值传递为 document.getElementById('<%= txtTime.ClientId%>')。代码工作正常,但我想删除此对象所需的错误。代码如下所示: - < script src = timepicker.js 类型 = text / javascript > ; < / script > < asp:textbox id = txtTime runat = server cssclass = TextBox value = 12:00 pm width = 88px xmlns:asp = #unknown > < ; / asp:textbox > < img src = timepicker.gif id = 选择 alt = 选择一个时间! onclick = selectTime(this,document.getElementById('& lt;%= txtTime.ClientId%& gt;')) / > 有没有其他方法可以将文本框传递给函数而不会出错? 如果我使用html输入类型然后它的工作没有任何错误,但我不想使用html控件。如果有人帮助我,请帮助我..提前谢谢你。解决方案 ygulve写道: document.getElementById('<%= txtTime.ClientId%>') 做一个你的页面的viewource。找到它的文本框的ID值。让我们说它是ctl00_txtTime然后使用: document.getElementById('ctl00_txtTime')用于获取文本框对象。 当您在dotnet中使用客户端ID时3.5确定是一个错误 txtTime.ID在点网3.5或3中 txtTime.ClientId在点网4 但ID不是网络中的ClientId 检查这个 http://www.dreamtheweb.com/2013/12/pass-textbox-value-into-javascript.html Hello Friends,I have one javascript file called timepicker.js, which is used for Time Pick and which includes one function called "selectTime". This function have two parameters ctrl1 and ctrl2, this looks like followsselectTime(ctrl1,ctrl2){}From aspx page i am passing 2 values of image and textbox. When I am selected time from popup its selecting correct time and showing into textbox but it is giving "Object Required error" on the page. I am passing the textbox value as document.getElementById('<%=txtTime.ClientId%>'). Code is working fine but I want to remove this object required error. The code is looks like follows: - <script src="timepicker.js" type="text/javascript"></script><asp:textbox id="txtTime" runat="server" cssclass="TextBox" value="12:00 pm" width="88px" xmlns:asp="#unknown"></asp:textbox><img src="timepicker.gif" id="pick" alt="Pick a Time!" onclick="selectTime(this,document.getElementById('<%=txtTime.ClientId%>'))" />Is there any other way to pass textbox to function without error? If I use html input type then its working without any error, but I dont want to use html control. Please it'll be very helpful for me if anyone help me.. Thank you in advance. 解决方案 ygulve wrote:document.getElementById('<%=txtTime.ClientId%>')"Do a viewsource of your page. Find the ID value of the textbox in it. Lets say it is "ctl00_txtTime" then use:document.getElementById('ctl00_txtTime') for getting the textbox object.when you use client Id in dotnet 3.5 sure was an erorrtxtTime.ID in dot net 3.5 or 3 txtTime.ClientId in dot net 4but ID not ClientId in dot net forcheck this onehttp://www.dreamtheweb.com/2013/12/pass-textbox-value-into-javascript.html 这篇关于如何将asp.net文本框控件传递给JavaScript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-18 22:34