【发布时间】:2014-01-08 17:58:05
【问题描述】:
我首先尝试检查用户是否没有输入用户 ID 或密码,如果任何一个文本框为空白或为空,那么我想显示消息框,如果他们同时输入用户 ID 和密码,那么我想执行一些其他代码。我遇到的代码问题是消息根本没有显示,但好处是它不执行其他代码。因此,如果两个文本框都为空,我希望看到消息框出现。我不确定为什么消息框没有显示,即使我在其他函数中使用了相同的代码并且它有效。谢谢 这是我的 ASPX 按钮代码
<asp:Panel ID="Panel1" runat="server" BorderStyle="Groove" Height="109px" Visible="false"
Width="870px" BackColor="#FFFFE1">
<asp:Label ID="Label2" runat="server" Text="DIGITAL SIGNATURE" Font-Bold="True"
ForeColor="#FF3300"></asp:Label>
<br />
<br />
<asp:Label ID="lblUID" runat="server" Text="User ID:"></asp:Label>
<asp:TextBox ID="txtUID" runat="server" Height="22px" Width="145px"></asp:TextBox>
<asp:Label ID="lblPass" runat="server" Text="Password:"></asp:Label>
<asp:TextBox ID="txtPass" runat="server" Height="23px" TextMode="Password" style="margin-top: 0px"></asp:TextBox>
<br />
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" Width="183px"
onclick="btnSubmit_Click"
OnClientClick="return confirm('Are you sure you want to submit?');"
Font-Bold="False" Font-Size="Medium" Height="30px"
style="margin-right: 1px" />
<br />
</asp:Panel>
后面的代码:
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (txtUID.Text.Length == 0 || txtPass.Text.Length == 0)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please type your User ID and Password correctly and click Submit button again. Thanks", true);
}
else
{
//execute some code here
}
}
【问题讨论】:
-
您是否尝试通过在 if 语句中设置断点来查看脚本是否实际运行?