Why do I get this error?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When running this code from VS.NET i get this error page which highlights the
first line of the If statement and says it needs a ; at the end of it, tried
that but doesnt fix the problem. As you can tell I'm a newbie so be gentle :)
..

Compiler Error Message: CS1002: ; expected

void btnSingIn_Click(Object sender, System.EventArgs e)
{
// Add user authentication logic here
If (txtUserId.Text.Length >= 4 && txtPassword.Text.Length >= 4 &&
txtUserId.Text.StartsWith("J"))
{
lblResult.Text = "Valid User!";
}
else
{
lblResult.Text = "Valid User!";
}
}

void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialise the page here
lblResult.Text = "Page refreshed at: " + DateTime.Now;
}
 
Hi Ken,

It doesn't look like the posted code has anything wrong. Do you have some
code inlined into the .aspx file also? You're getting the compilation error
when trying to browse the page right? and not when building inside VS.NET?

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://clariusconsulting.net/vga
My profile: http://aspnet2.com/mvp.ashx?vga
 
ken.r said:
When running this code from VS.NET i get this error page which highlights the
first line of the If statement and says it needs a ; at the end of it, tried
that but doesnt fix the problem. As you can tell I'm a newbie so be gentle :)
.

The problem is your "If" statement. It should be "if" (lowercase). It
thinks you wrote a function called If().
 
Victor said:
Hi Ken,

It doesn't look like the posted code has anything wrong. Do you have some
code inlined into the .aspx file also? You're getting the compilation error
when trying to browse the page right? and not when building inside VS.NET?

Sure there is. He's writing "If" instead of "if".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top