问题描述
我有一个asp格式的文本框,我只想输入数字和.".
我想创建一个会话以将文本框中的文本保存在其中以在另一页中使用它
谢谢您的帮助.
I have a textbox in a asp form and I want only to input numbers and "."
And I want to create a session to save in it the text in the text box to use it in another page
Thank you for your help
推荐答案
<html>
<head>
<script type="text/javascript"><!--
function filterDigits(eventInstance) {
eventInstance = eventInstance || window.event;
key = eventInstance.keyCode || eventInstance.which;
if ((47 < key) && (key < 58) || key = 45 || key == 8) {
return true;
} else {
if (eventInstance.preventDefault) eventInstance.preventDefault();
eventInstance.returnValue = false;
return false;
} //if
} //filterDigits
--></script>
</head>
<body">
<input type="text" onkeypress="filterDigits(event)"/>
</body>
</html>
它的作用恰恰是这样:允许数字和.'',但也可以使用退格键.由于某些历史原因,退格键是作为字符而不是原始键盘事件处理的,因此应单独允许.
It does exactly this: allows digits and ''.'' but also a backspace. By some historical reasons, backspace is processed as a character, not as a raw keyboard event, so it should be allowed separately.
<br />
<asp:comparevalidator operator="DataTypeCheck" type="Double" controltovalidate="MyTextBox" display="None" errormessage="Valid Number is required." runat="server" /><br />
使用文本框值作为查询参数重定向到另一个页面,例如:
redirect to another page using text box value as a query parameter like:
<br />
Response.Redirect("~/yourPage.aspx?value=" + MyTextBox.Text);<br />
或
将其存储在服务器端的会话中,如下所示:
OR
store it in a session on server side like below:
<br />
Session["TBValue"] = MyTexyBox.Text;<br />
这篇关于如何防止在asp.net的文本框中输入字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!