I have got Login web code:
http://dotnetlearners.com/blogs/create-simple-login-page-in-html-using-css
The problem here when running I want to execute commands in this virtual login button or virtual checkbox, I have to declare how the event btnLogin_Click (..) runs in LogIn.aspx.cs file? The same for virtual checkboxes.
According to the front-end code you provide, you need to add a < form id= "form 1" runat= "server"> label to the outer layer of your form to ensure that your front-end control can interact with the server.
<input type="submit" class="loginbtn" value="Login" id="btnSubmit"/> The original input tag is a simple HTML control.
If you want to trigger its server click event, you need to add runat= "server" attribute to it and trigger onserverclick event, so that the HTML control can be transformed
into a server control.
If you want get the checkbox state,you could add runat="server" in this statement: <input type="checkbox" id="chbRemember" name="chbRemember"> ,then you could get the checkbox state when you login into another
page.
For more detailed code, please refer to the following code:
protected void btnSubmit_ServerClick(object sender, EventArgs e)
{
bool isRememberMe = chbRemember.Checked;// get the checkbox state
// do something you want
Response.Redirect("Registration.aspx");
}
Best Regards,
YongQing.
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Error 1 'System.Web.UI.HtmlControls.HtmlInputText' does not contain a definition for 'Text'
Error 2 'System.Web.UI.HtmlControls.HtmlInputPassword' does not contain a definition for 'Text'
According to your question, the reason why the errors show is that txtUserName and txtPassword are HTML controls.
There are two ways to get their values in the code behind:
You could use Request.Form["txtUserName"] in the code behind. Note that the content of the request is the
name value of input, which can be obtained directly by request.
You could also add a runat= "server" to the input tag of txtUserName and txtPassword, and then get the corresponding input value in the code behind through
txtUserName.Value.
Best Regards,
YongQing.
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
You said I understand the code above, I still have more questions about the login code below:
protected void btnLogin_Click(object sender, EventArgs e)
{
if (FormsAuthentication.Authenticate(txtUsername.Text, txtPassword.Text))
{
FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, false);
lblmsg.ForeColor = System.Drawing.Color.Green;
lblmsg.Text = "Logged in successfully";
}
else
{
lblmsg.ForeColor = System.Drawing.Color.Red;
lblmsg.Text = "Account and password are not valid.";
}
}
when I input User/Pass for txtUsername.Text, txtPassword.Text and I push the button Enter. The asp.net compare database where for User/Pass this data ? Compare data of SQL Server, Microsoft Access, or Windows Authentication,... I input all User/Pass of SQL
Server and Windows Authentication but it's report error: "Account and password are not valid." Do you know the operation mechanism of this statement ? "if (FormsAuthentication.Authenticate(txtUsername.Text,
txtPassword.Text)) "
According to your question, you could create a database in SqlServer and create a table to save usernames and passwords.
If you have a registration page, you could save the registered username and password into this table.
If you don't have a registration page, you could enter your data into the table manually, and then connect to the database by clicking on the login event to get the table, which matches the existence and matching of the username and password you entered.
//I define
x = if (FormsAuthentication.Authenticate(txtUsername.Text, txtPassword.Text))
According to the document you sent me, the command x must be used with the Web.config file and I run the test successfully, I have not found the command x running with sql server or the command x running with microsoft access. I want to find an example of
the command x running with sql server or the command x running with microsoft acess, maybe the command x is difficult to apply to sql server or microsoft access ?
According to your description, I found your question is not related with this thread title.
I suggest you could try to start a new thread and mark the right reply as answer, since this will help other people who faces the same error to find the answer .
Thank you.
Best Regards,
YongQing.
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
6 Points
85 Posts
What is the virtual button click event and click the virtual check box of the web form login ?
May 21, 2019 04:53 AM|dongtrien|LINK
I have got Login web code: http://dotnetlearners.com/blogs/create-simple-login-page-in-html-using-css
The problem here when running I want to execute commands in this virtual login button or virtual checkbox, I have to declare how the event btnLogin_Click (..) runs in LogIn.aspx.cs file? The same for virtual checkboxes.
[CODE]
protected void btnLogin_Click(object sender, EventArgs e)
{
//Open web Registration.aspx
Response.Redirect("Registration.aspx");
}
[/CODE]
Contributor
3710 Points
1043 Posts
Re: What is the virtual button click event and click the virtual check box of the web form login...
May 21, 2019 09:35 AM|Yongqing Yu|LINK
Hi dongtrien,
According to the front-end code you provide, you need to add a < form id= "form 1" runat= "server"> label to the outer layer of your form to ensure that your front-end control can interact with the server.
<input type="submit" class="loginbtn" value="Login" id="btnSubmit"/> The original input tag is a simple HTML control.
If you want to trigger its server click event, you need to add runat= "server" attribute to it and trigger onserverclick event, so that the HTML control can be transformed into a server control.
You can refer to the following links:
https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.htmlcontrols.htmlbutton.onserverclick?view=netframework-4.8
If you want get the checkbox state,you could add runat="server" in this statement: <input type="checkbox" id="chbRemember" name="chbRemember"> ,then you could get the checkbox state when you login into another page.
For more detailed code, please refer to the following code:
code behind:
protected void btnSubmit_ServerClick(object sender, EventArgs e) { bool isRememberMe = chbRemember.Checked;// get the checkbox state // do something you want Response.Redirect("Registration.aspx"); }
Best Regards,
YongQing.
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
6 Points
85 Posts
Re: What is the virtual button click event and click the virtual check box of the web form login...
May 22, 2019 08:25 AM|dongtrien|LINK
I understand, I want to ask you more code below:
[CODE]
if ((txtUserName.Text == "admin") && (txtPassword.Text == "admin")) //error here
{
//somthing ...
}
else
{
//somthing ...
}
[/CODE]
Error 1 'System.Web.UI.HtmlControls.HtmlInputText' does not contain a definition for 'Text'
Error 2 'System.Web.UI.HtmlControls.HtmlInputPassword' does not contain a definition for 'Text'
Contributor
3710 Points
1043 Posts
Re: What is the virtual button click event and click the virtual check box of the web form login...
May 22, 2019 10:41 AM|Yongqing Yu|LINK
Hi dongtrien,
According to your question, the reason why the errors show is that txtUserName and txtPassword are HTML controls.
There are two ways to get their values in the code behind:
Best Regards,
YongQing.
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
6 Points
85 Posts
Re: What is the virtual button click event and click the virtual check box of the web form login...
May 23, 2019 04:09 AM|dongtrien|LINK
You said I understand the code above, I still have more questions about the login code below:
when I input User/Pass for txtUsername.Text, txtPassword.Text and I push the button Enter. The asp.net compare database where for User/Pass this data ? Compare data of SQL Server, Microsoft Access, or Windows Authentication,... I input all User/Pass of SQL Server and Windows Authentication but it's report error: "Account and password are not valid." Do you know the operation mechanism of this statement ? "if (FormsAuthentication.Authenticate(txtUsername.Text, txtPassword.Text)) "
Contributor
3710 Points
1043 Posts
Re: What is the virtual button click event and click the virtual check box of the web form login...
May 23, 2019 10:12 AM|Yongqing Yu|LINK
Hi dongtrien,
According to your question, you could create a database in SqlServer and create a table to save usernames and passwords.
If you have a registration page, you could save the registered username and password into this table.
If you don't have a registration page, you could enter your data into the table manually, and then connect to the database by clicking on the login event to get the table, which matches the existence and matching of the username and password you entered.
For this function, you could refer to this link:
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/ado-net-code-examples#sqlclient
If you use the current method:
you need to store the username and password in the application's Web.config file as user credentials.
For this function, you could refer to this link:
https://docs.microsoft.com/en-us/dotnet/api/system.web.security.formsauthentication.authenticate?View=netframework-4.8
Best Regards,
YongQing.
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
6 Points
85 Posts
Re: What is the virtual button click event and click the virtual check box of the web form login...
May 27, 2019 03:00 AM|dongtrien|LINK
According to the document you sent me, the command x must be used with the Web.config file and I run the test successfully, I have not found the command x running with sql server or the command x running with microsoft access. I want to find an example of the command x running with sql server or the command x running with microsoft acess, maybe the command x is difficult to apply to sql server or microsoft access ?
Contributor
3710 Points
1043 Posts
Re: What is the virtual button click event and click the virtual check box of the web form login...
May 27, 2019 08:19 AM|Yongqing Yu|LINK
Hi dongtrien,
According to your description, I found your question is not related with this thread title.
I suggest you could try to start a new thread and mark the right reply as answer, since this will help other people who faces the same error to find the answer .
Thank you.
Best Regards,
YongQing.
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.