【问题标题】:verify username existence in access database when page_loadpage_load 时验证访问数据库中是否存在用户名
【发布时间】:2015-07-24 22:35:13
【问题描述】:

我有一个标签来识别 Windows 登录用户。

<table>
        <tr><td><b>Utilizador:</b></td><td><asp:Label ID="username" runat="server"></asp:Label></td></tr>
</table> 

页面加载时我的代码落后

protected void Page_Load(object sender, EventArgs e)
{
    username.Text = "[" + HttpContext.Current.User.Identity.Name + "]"; 
}

如何警告(message.box 或标签)用户他已经存在于 access 数据库中?

(我已经插入代码)

【问题讨论】:

  • 希望我已经回答了here
  • 您想在消息框中显示警告消息而不是在标签中显示?
  • @gkrishy 在其他帖子中,文本仅在我单击按钮后出现...但目的是在字段之前 text.box ....打开页面,如果用户名已经回答消息否则字段表
  • @KikoFHM 最后一条评论很难阅读或理解。你能试着澄清一下吗?
  • @Newd 我有一个表格供用户回答,但如果该特定用户已经回答,我想说一条消息。

标签: c# asp.net ms-access pageload


【解决方案1】:

如何简单地添加标签或验证器来显示用户已经存在的消息。在后面的代码中,您可以简单地在用户已经存在时使消息可见。像这样:

<table>
  <tr>
    <td>
      <b>Utilizador:</b>
    </td>
    <td>
      <asp:Label ID="username" runat="server"></asp:Label>
    </td>
  </tr>
  <tr id="userAlreadyExistsRow" runat="server">
    <td colspan="2">
      <asp:Label ID="userAlreadyExistsLbl" runat="server" 
         Text="This user exists already" </asp:Label>
    <td>
  </tr>
</table>

protected void Page_Load(object sender, EventArgs e)
{
    username.Text = "[" + HttpContext.Current.User.Identity.Name + "]"; 

    var userAlreadyExists = true; // replace by appropriate condition
    userAlreadyExistsRow.Visible = userAlreadyExists;
}

【讨论】:

  • 你的解决方案是迄今为止我能得到的最接近的解决方案,但即便如此......不是我假装的=(当我调试标签时显示“该用户已经存在”但我从数据库中删除了我的用户名而且我仍然收到消息“此用户已存在”:/
  • 您必须在Page_Load中查询数据库,并将消息行设置为找到用户时可见。
  • 嗯,你能帮帮我吗?我该怎么做?
猜你喜欢
  • 1970-01-01
  • 2016-05-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-18
  • 1970-01-01
  • 1970-01-01
  • 2021-04-22
相关资源
最近更新 更多