【发布时间】:2017-02-27 20:03:46
【问题描述】:
早安
我有一个带有按钮板的网页。它在网络不好的加油站使用,所以每次他们点击按钮向文本框添加一个数字时,它将永远加载,所以我将按钮点击更改为 javascript。
它工作得很好,但现在当我从文本框中检索值时,后面的代码得到一个空值(非空)。
这是我的代码
用于将数字添加到文本框的按钮 和文本框
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="OVKWEBAPP.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link rel="stylesheet" type="text/css" href="mainstyle.css" />
<style type="text/css">
.modal
{
position: fixed;
top: 0;
left: 0;
/*background-color: black;*/
z-index: 99;
opacity: 0.8;
filter: alpha(opacity=80);
-moz-opacity: 0.8;
min-height: 100%;
width: 100%;
}
.loading
{
font-family: Arial;
font-size: 10pt;
border: 5px solid #67CFF5;
width: 200px;
height: 100px;
display: none;
position: fixed;
background-color: White;
z-index: 999;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="txtRknr" runat="server" CssClass="txtBoxRknr" PlaceHolder="Rekening Nommer" Enabled="False" autocomplete="off" Width="175px"></asp:TextBox>
<input type="button" id="btnPad1" runat="server" value="1" class="buttonsb" onclick="input(this);"/>
<input type="button" id="btnPad2" runat="server" value="2" class="buttonsb" onclick="input(this);"/>
<asp:Button ID="btnMsg1" runat="server" Text="Gaan Voort" CssClass="buttonsa" OnClick="btnMsg1_Click" />
</form>
</body>
<script type="text/javascript">
function input(e) {
document.getElementById("<%=txtRknr.ClientID %>").value = document.getElementById("<%=txtRknr.ClientID %>").value + e.value;
}
</script>
</html>
这是我在代码隐藏文件中的代码
protected void btnMsg1_Click(object sender, EventArgs e)
{
lblError.Text = "";
//string user = txtRknr.Text;
string user = ((TextBox)FindControl("txtRknr")).Text;
if(user == "")
//if (txtRknr.Text == "")
{
lblError.Text = "ONGELDIGE REKENING NOMMER";
return;
}
}
基本上,所有这些需要做的就是从网站上的按钮板上将帐号添加到文本框中。
添加帐户后,他们将单击继续按钮,然后后面的代码检查文本框是否为空,如果不为空,则连接到数据库以检查它是否有效。
但是无论我在文本框中添加多少数字,当我从后面的代码访问它时,它仍然是空的。
【问题讨论】:
-
您为什么使用 FindControl?控件在页面内,它看起来不像在另一个控件内
-
您已禁用文本框:
Enabled="False"。
标签: javascript c# html asp.net