如何将asp.net文本框控件传递给JavaScript函数 [英] How to pass asp.net textbox control to JavaScript function

查看:55
本文介绍了如何将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 = < span class =code-keyword>选择一个时间! 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 follows

selectTime(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('&lt;%=txtTime.ClientId%&gt;'))" />



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 erorr
txtTime.ID in dot net 3.5 or 3
txtTime.ClientId in dot net 4
but ID not ClientId in dot net for


check this one

http://www.dreamtheweb.com/2013/12/pass-textbox-value-into-javascript.html


这篇关于如何将asp.net文本框控件传递给JavaScript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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