以aspx格式编写javascript代码 [英] writing javascript code in aspx form

查看:65
本文介绍了以aspx格式编写javascript代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在将表单发布到服务器之前进行客户端验证.我已经为表单编写了aspx代码,但不知道如何在同一页面上进行 javascript验证.
字段是:
1.名称
2.卷
3.提交按钮
**************************************

I want to do client side validation of a form before posting it to the server. I''ve written the aspx code for the form but don''t know how to do javascript validation with the same page.
The fields are:
1. name
2. roll
3. submit button
*********************************

<form   runat="server">
<table>
<tr>
<td>Name:</td>
<td><asp:TextBox ID="name" runat="server" /></td>
</tr>

<tr>
<td>Roll:</td>
<td><asp:TextBox ID="roll" runat="server" /></td>
</tr>

<tr>
<td><asp:ImageButton ID="ImgSubmit" runat="server" ImageUrl="~/images/submit.gif"/></td>
</tr>

</table>
</form>


******************************************
如何使用此aspx表单进行javascript验证?我也想在javascript中加入一些功能,例如:
1)加载页面时,光标必须位于名称"文本框中
2)最初必须禁用提交"按钮
3)焦点对准时更改文本框的颜色.


***********************************
How to do javascript validation with this aspx form?? Also I want to include some features with javascript like:
1) when the page loads the cursor must be at the "Name" textbox
2) initially the submit button must be disabled
3) change the color of the text box when it is focused.

How to include java script code with this form??

推荐答案

您只需将javascript放在表单上,​​并将其直接呈现到html中.然后,您可以将事件处理程序等置于控件中,框架无法识别的任何内容都将通过逐字记录传递.
You just put the javascript on the form and it''s rendered directly into your html. Then you can put event handlers etc in your controls, any thing not recognised by the framework is passed through verbatim.


尝试一下....
Try this....
<form   runat="server">
 <script type="text/javascript" language="javascript">
//put javascript here

<table>
<tr>
<td>Name:</td>
<td><asp:TextBox ID="name" runat="server" /></td>
</tr>
<tr>
<td>Roll:</td>
<td><asp:TextBox ID="roll" runat="server" /></td>
</tr>
<tr>
<td><asp:ImageButton ID="ImgSubmit" runat="server" ImageUrl="~/images/submit.gif"/></td>
</tr>
</table>
</form>


--------------
如果有解决方案,请投票
感谢和问候
kaushal16


--------------
Vote if got an solution
thanks and reuards
kaushal16


JavaScript是客户端脚本,主要用于验证.

您可以在< HEAD>下编写脚本标签

将光标放在文本框上的功能

Javascript is client side scripting mostly used for validation.

U can write a script under <HEAD> tag

Function to put cursor on textbox

function putFocus()
{
   document.getElementById("TextboxID").focus();
   return false;
}



调用html正文标签的加载上的函数



call the function on Load of html Body tag

<body onload="return putFocus()"></body>


这篇关于以aspx格式编写javascript代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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