AddWithValue method on ASP.NET

时间:2018-04-18 18:14:49

标签: c# asp.net

I am using AddStringWithValue method in ASP.NET using C#

My HTML code is

<form class="login-modal-content animate" action="">   
    <asp:Login ID = "Login" runat = "server" OnAuthenticate="ValidateUser"></asp:Login>        
    <div class="input">
        <div>
            <input type="text" id="email" style="margin:8px 2px 5px 2px;" placeholder="Email"/>
        </div>
        <div>
            <input type="password" id="password" style="margin:5px 2px 8px 2px;" placeholder="**********"/>
        </div>
    </div>
    <button type="submit" style="display:none"></button>
    <f style="padding-left: 4px">Not yet registered? <f style="color:rgb(176,224,230); cursor:pointer" onclick="document.getElementById('Sign_Up_Form').style.display='block';document.getElementById('Login_Form').style.display='none';">Sign Up</f></f>
</form>

My C# code for the method is:

cmd.Parameters.AddWithValue("@email", Login.email);
cmd.Parameters.AddWithValue("@password", Login.password);

The problem is, it is giving red underline under email and password. Shouldn't we identify them with Id? Please tell me how to identify them..

I am sorry, I still don't know how to format my codes here..

edit:

The error message is

Compiler Error Message: CS1061: 'System.Web.UI.WebControls.Login' does not contain a definition for 'email' and no extension method 'email' accepting a first argument of type 'System.Web.UI.WebControls.Login' could be found (are you missing a using directive or an assembly reference?)

The HTML is in masterpage.master and c# code is in masterpage.master.cs

1 个答案:

答案 0 :(得分:0)

我假设您要将客户端输入值发送到您的sql语句,或类似的东西? 您必须执行post请求才能将值传入c#后端。 尝试使用此post中的内容。

另一种可能的方式(我更喜欢)而不是这个方法是创建一个JSON对象,您可以通过c#HttpPost轻松发布和访问。 我建议为此目的使用ApiController。

祝你好运;)