Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
it shows two error

The name 'Textbox3' does not exist in the current context

The name 'Textbox2" does not exist in the current context


C#
con = new SqlConnection("Data Source=MAC-20;Initial Catalog=prakash;User ID=sa;Password=sql@2012");
        cmd = new SqlCommand("select count(*) from signin where username = '" + TextBox2.Text +   "' + and password = '" +  Textbox3.Text + "'",con);
        cmd.Parameters.AddWithValue("@username",TextBox2.Text);
        cmd.Parameters.AddWithValue("@password",Textbox3.Text);
         da = new SqlDataAdapter(cmd);
         dt = new DataTable();
         da.Fill(dt);

         if (dt.Rows.Count > 0)
         {
             Response.Redirect("home.aspx");
         }
         else
         {
             ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>");
         }
Posted
Comments
Gihan Liyanage 18-Aug-14 4:45am    
Your Text boxes may be outside the scope. Did you use panel or any other criteria for place text boxes ?
Gihan Liyanage 18-Aug-14 4:46am    
Can we see the full Code. From creating Text boxes ?
Member 10918596 18-Aug-14 5:38am    
<table class="auto-style18">

<tr>
<td class="auto-style19" align="right">Login</td>
<td class="auto-style23">
</td>
<td class="auto-style20">
</td>
</tr>
<tr>
<td class="auto-style19" align="right">username</td>
<td class="auto-style23">
<asp:TextBox ID="TextBox2" runat="server" OnTextChanged="TextBox2_TextChanged" placeholder="E-mail" Height="25px" >
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2" ErrorMessage="*">
</td>
<td class="auto-style20">
 </td>
</tr>
<tr>
<td class="auto-style16" align="right">password</td>
<td class="auto-style24">
<asp:TextBox ID="TextBox3" runat="server" placeholder="password" TextMode="Password" Height="25px">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox3" ErrorMessage="*">
</td>
<td class="auto-style17">
 </td>
</tr>
<tr>
<td class="auto-style15"></td>
<td class="auto-style25"></td>
<td> </td>
</tr>
<tr>
<td class="auto-style21" align="right">
<asp:Button ID="Button1" runat="server" Text="Login" BackColor="#CC9900" CssClass="style16" Width="61px" />
</td>
<td class="auto-style26">
<asp:Button ID="Button2" runat="server" Text="Reset" style="margin-left: 15px" BackColor="#CC9900" CssClass="style16" Width="62px" />
<asp:Label ID="Label9" runat="server" Text="Register">
</td>
<td class="auto-style22">
</td>
</tr>
</table>
ClimerChinna 18-Aug-14 7:47am    
check solution 3

:sigh:

The number of problems here is really quite amazing: you should think yourself lucky that it doesn't compile - because if this got out into the "real world" your chances of a Christmas bonus this year would be unbelievably small.

Let's start the the Big One: SQL Injection.
When you leave yourself open to SQL Injection on your login page for a website, you let anyone, anywhere in the world, do anything they like to your database without even having to log in. And I'm serious: that code lets me log in as you without knowing your password, change your password so I know it and you don't, or just delete your entire database. All without logging in.

Never, ever, concatenate strings to form an SQL command. Always use parametrized queries, or someone will come along, and take advantage of it...

Then there is the second big one: Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]

Third, why are you reinventing the wheel and trying to implement website login yourself? Use the built in facilities, and you don't leave the erst of your site wide open as well... Start here: Introduction to membership[^]

And then you should find all your other problems starting to melt away...
 
Share this answer
 
place closing tag for textbox

<asp:TextBox ID="TextBox2" runat="server" OnTextChanged="TextBox2_TextChanged" placeholder="E-mail" Height="25px" >
</asp:TextBox>


<asp:TextBox ID="TextBox3" runat="server" placeholder="password" TextMode="Password" Height="25px"> </asp:TextBox>


<asp:Label ID="Label9" runat="server" Text="Register"></asp:Label>
 
Share this answer
 
v4
Comments
Ashi0891 18-Aug-14 7:59am    
Bingo!!
ClimerChinna 18-Aug-14 8:02am    
what, have you executed it
if you got the answer then accept solution
Ashi0891 18-Aug-14 8:07am    
It wasnt my question. Though your solution can be the answer but I think if the closing tags were missing it would have given error at first place.
Snesh Prajapati 18-Aug-14 9:22am    
Is your code working now or not ?
Can you once verify with Id of your textboxes.

Your .axpx file and .aspx.cs file having textBox3 spelling different.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900