Answered by:
What is the virtual button click event and click the virtual check box of the web form login ?

Question
-
User-663551687 posted
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.protected void btnLogin_Click(object sender, EventArgs e)
{
//Open web Registration.aspx
Response.Redirect("Registration.aspx");
}Tuesday, May 21, 2019 4:53 AM
Answers
-
User665608656 posted
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.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, May 27, 2019 8:19 AM
All replies
-
User665608656 posted
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:<form id="form1" runat="server"> <div class="logincontent"> <div class="loginheading"> Login </div> <label for="txtUserName"> Username:</label> <input type="text" id="txtUserName" name="txtUserName" /> <label for="txtPassword"> Password:</label> <input type="password" id="txtPassword" name="txtPassword" /> <div class="loginremember"> <input type="checkbox" id="chbRemember" name="chbRemember" runat="server" /><label class="check" for="chbRemember">Remember me next time</label> <input type="submit" class="loginbtn" value="Login" id="btnSubmit" runat="server" onserverclick="btnSubmit_ServerClick" /> </div> </div> </form>
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.
Tuesday, May 21, 2019 9:35 AM -
User-663551687 posted
I understand, I want to ask you more code below:
if ((txtUserName.Text == "admin") && (txtPassword.Text == "admin")) //error here
{
//somthing ...
}
else
{
//somthing ...
}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'Wednesday, May 22, 2019 8:25 AM -
User665608656 posted
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:
- 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.
Wednesday, May 22, 2019 10:41 AM -
User-663551687 posted
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)) "
Thursday, May 23, 2019 4:09 AM -
User665608656 posted
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#sqlclientIf you use the current method:
dongtrien
if (FormsAuthentication.Authenticate(txtUsername.Text, txtPassword.Text))
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:
Best Regards,
YongQing.
Thursday, May 23, 2019 10:12 AM -
User-663551687 posted
//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 ?
Monday, May 27, 2019 3:00 AM -
User665608656 posted
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.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, May 27, 2019 8:19 AM