JavaScript/ASP.NET中的问题 [英] Problems in JavaScript/ASP.NET

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

问题描述

我是ASP的新手,正在开发一个需要用户向系统注册的Web应用程序.在registration.aspx中,我有ASP控件.

我的问题是使用JavaScript访问ASP控件.假设要验证文本输入,我需要编写如下内容:

I am new in ASP and developing an web application that requires user to register to the system. In registration.aspx, I have ASP controls.

My problem is to access the ASP controls using JavaScript. Suppose for validating a text input i need to write something like this:

document.getElementbyId("myControl").value="Something";



但是对于ASP控件,我没有这样的属性(例如值,selectedindex等).如果我将这些代码放入需要执行代码时回发页面的C#中.因此,作为一种用途,我从来不希望页面在对页面中的任何控件进行更改时都会回发.

我尝试使用MSDN建议的ClientID属性.但是ClientID属性仅在ASP.NET 4上可用,而在ASP.NET 3.5中不可用.

我正在使用ASP.NET 3.5.我该怎么做.你能帮我吗?在此先谢谢您.



But for ASP controls I don''t get such attributes (like value, selectedindex etc.). If I put these codes into C# that requires post back pages while executing code. So, as a use I never expect pages to post back every while I make changes to any of the controls in pages.

I tried to use ClientID property as suggested by MSDN. But ClientID property is only available at ASP.NET 4 but not in ASP.NET 3.5.

I am using ASP.NET 3.5. How can I do these things. Can you please help me out? Thanks in advance.

推荐答案

您可以使用ClientID属性.您可以做的一件事是检查渲染页面的源,并查看由ASP.NET生成的控件的ID与出现在您的javascript函数中的ID是相同的.

You can use ClientID property. One thing you can do is check your rendered page''s source and see the control''s ID generated by ASP.NET and the one appearing in your javascript function are the same.

document.getElementById('<%= myControl.ClientID %>').value="something";


您是否为控件提供了"runat = server"属性?如果没有,那就给它.
试用简单的脚本

Have you give "runat=server" property to your controls ? if not then give it.
try out simple script

<script language="JavaScript">
   function CallMe()
     {
          alert("Yes..first POP up from javascript");
          return false;
     }
 </script>
 </head>
 <body> Welcome to javascript example!
        <input type="submit" id="sub1" runat="server" onclick="return CallMe();">
 </body>


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

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