hi there.
I’m a total Noob with programming and hopefully someone
could explain how "if then else statements" are done.
here’s the question from my tutorial:
1.Create a new page called tutorial_form.aspx
2.Insert a new textbox and a button that asks a user to enter a number between 0 and 100.
3.Add code SO THAT ONLY DURING A POSTBACK if the user entered a number below 0 it outputs, “You are naughty, your number was below 0”, if the number was above 100 it outputs “Tsk Tsk. I told you to enter a number below 100”, otherwise it outputs “Thank you for following instructions. [the number] is between 0 and 100”.
Note: You will need to convert the input from a String to an Integer and you will need to nested IF statements!
This is what I’ve done in code view:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Page Language="VB" Debug="true" %>
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
</head>
<body>
<form id="form1" runat="server">
Enter a number between 0 and 100 <asp:TextBox runat="server" id="numberbox"></asp:TextBox>
<script runat="server">
If numberbox <=0 Then
response.Write "You are naughty, your number was below 0"
else If numberbox >=100 Then
response.Write "Tsk Tsk. i told you to enter a number below 100"
else
response.Write "Thank you for following instructions. (numberbox.Text) is between 0 and 100"
end If
</script>
</form>
</body>
sorry if that’s messy =[
oh gee thx Epson,
Grrr mofo
the f numberbox <=0 Then code block has to be in the onclick event for the button.
There are two drop-down boxes just above the code editor window that display objects (form, page, button, etc) and the available events. if button isn;t one of them, then the button hasn;t been properly placed on the form. be sure to add the control from the toolbox.
numberbox may need a me.numberbox.tostring
and you may need to convert to a number. I use the cdbl or cint, but you could also use CType(variable, datatypename)