【问题标题】:How to pass HTML parameters to ASP.NET?如何将 HTML 参数传递给 ASP.NET?
【发布时间】:2015-05-11 09:33:10
【问题描述】:

我正在使用 Bootstrap (HTML&CSS)、Microsoft Access 和 ASP.NET 制作一个 Web 服务项目。

我从 W3SCHOOLS 的引导登录表单中找到了一个代码:

 <body>
    <form method="POST" action="Login.aspx">
        <div class="container">
            <h2>Login area</h2>
             <form class="form-inline" role="form">
                <div class="form-group">
                    <label for="email">UserName:</label>
                        <input type="text" class="form-control" id="username1" name="username" placeholder="Enter UserName"/>
                </div>


    <div class="form-group">
        <label for="pwd">Password:</label>
            <input type="password" class="form-control" id="password1" name="password" placeholder="Enter password"/>
    </div>
   
    <button type="submit" onclick="SubmitForm" class="btn btn-default">Submit</button>
  </form>
    </div>

这是 C# 代码:

 protected void SubmitForm(object sender, EventArgs e)
{
   if (Page.IsValid)
    {
        string name=string.Format("{0}",Request.Form["username"]);
        string pass = string.Format("{0}", Request.Form["password"]);

        int userId;
        userId = LoginService.GetUserId(name, pass, 0, 1);

        if (userId == 0)
        {
            MessageBoxShow(Page, "UserName does not exists.");

        }
        else
        {
            MessageBoxShow(Page, "You are successfully connected.");
            Session["userId"] = userId.ToString();
            SalService.DeleteFromSal();
        }
    }

}

当我运行页面并输入用户名和密码时,页面不显示消息,我无法连接用户名。

【问题讨论】:

    标签: c# html css asp.net twitter-bootstrap


    【解决方案1】:

    设置断点并检查代码隐藏处发生的情况以及您收到的值。

    另外,请尝试使用onserverclick 而不是onclick

    【讨论】:

      【解决方案2】:
      <input id ="txt"  runat="server"  type="text">
      

      在后面

      txt.value=@Your
      

      【讨论】:

      • 我不明白我应该在后面写什么。
      【解决方案3】:

      您的 HTML 没有使用 ASP 服务器端控件进行格式化,但是您仍然可以使用它。您必须将按钮更改为提交按钮。

      <input type="submit" value="OK"/>
      

      然后如下更改你的代码。

       protected void Page_Load(object sender, EventArgs e)
      {
          if (IsPostBack)
          {
              string name=string.Format("{0}",Request.Form["username"]);
              string pass = string.Format("{0}", Request.Form["password"]);
      
              int userId;
              userId = LoginService.GetUserId(name, pass, 0, 1);
      
              if (userId == 0)
              {
                  MessageBoxShow(Page, "UserName does not exists.");
      
              }
              else
              {
                  MessageBoxShow(Page, "You are successfully connected.");
                  Session["userId"] = userId.ToString();
                  SalService.DeleteFromSal();
              }
          }
      
      }
      

      确保后面的代码适用于名为 login.aspx 的页面,并且应称为 login.aspx.cs

      应该有一个 login.aspx 页面,并且应该有一个有效的页面指令指向后面的代码。

      您还需要一个 MessageBoxShow 函数,并且应该引用 Web 服务。

      【讨论】:

        猜你喜欢
        • 2015-07-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-25
        相关资源
        最近更新 更多