|
 |
aspx_beginners thread: Form 'Reset' Question
Message #1 by "Jordan, Andy" <Andy.Jordan@g...> on Mon, 4 Mar 2002 11:34:25 -0000
|
|
Hi,
As you can see I'm only up to chapter 6 so far. I've tried to make myself a
simple calculator, however I can't get the 'Reset' button on my form to
work.
Does anyone have an explanation?
Source code below: (example can be viewed online at
http://hosting.msugs.ch/pragna/calculator.aspx)
<script language="vb" runat="server">
Sub Page_Load
Dim intNumberOne As Integer
Dim intNumberTwo As Integer
If Request.Form("NumberOne") <> "" then
intNumberOne = Request.Form("NumberOne")
End If
If Request.Form("NumberTwo") <> "" then
intNumberTwo = Request.Form("NumberTwo")
End If
Select Case (Request.Form("operator"))
Case "Add"
answer.Text = intNumberOne + intNumberTwo
Case "Subtract"
answer.Text = intNumberOne - intNumberTwo
Case "Multiply"
answer.Text = intNumberOne * intNumberTwo
Case "Divide"
answer.Text = intNumberOne / intNumberTwo
End Select
End Sub
</script>
<html>
<head><title>calculator</title></head>
<body>
<form runat="server">
<h4>Calculator</h4>
Please enter numbers and operator:
<br />
<asp:textbox id="NumberOne" runat="server" />
<br />
<asp:dropdownlist id="operator" runat="server">
<asp:listitem>Add</asp:listitem>
<asp:listitem>Subtract</asp:listitem>
<asp:listitem>Multiply</asp:listitem>
<asp:listitem>Divide</asp:listitem>
</asp:dropdownlist>
<br />
<asp:textbox id="NumberTwo" runat="server" />
<br />
<input type="Submit" value="Calculate">
<input type="reset">
<br />
<br />
Answer is:
<br />
<asp:label id="answer" runat="server" />
</form>
</body>
</html>
Thanks,
Andy Jordan
Message #2 by "Carl E. Olsen" <carl-olsen@m...> on Mon, 4 Mar 2002 06:53:18 -0600
|
|
I just tried it, and it works just fine. You have to hit the "reset"
button first. If you hit the "calculate" button first, it will not
clear the form. It will only reset before the form is submitted.
Carl Olsen, MCSE
> -----Original Message-----
> From: Jordan, Andy [mailto:Andy.Jordan@g...]
> Sent: Monday, March 04, 2002 5:34 AM
> To: aspx_beginners
> Subject: [aspx_beginners] Form 'Reset' Question
>
> Hi,
>
> As you can see I'm only up to chapter 6 so far. I've tried to make
myself
> a
> simple calculator, however I can't get the 'Reset' button on my form
to
> work.
> Does anyone have an explanation?
> Source code below: (example can be viewed online at
> http://hosting.msugs.ch/pragna/calculator.aspx)
>
> <script language="vb" runat="server">
> Sub Page_Load
>
> Dim intNumberOne As Integer
> Dim intNumberTwo As Integer
>
> If Request.Form("NumberOne") <> "" then
> intNumberOne = Request.Form("NumberOne")
> End If
>
> If Request.Form("NumberTwo") <> "" then
> intNumberTwo = Request.Form("NumberTwo")
> End If
>
> Select Case (Request.Form("operator"))
> Case "Add"
> answer.Text = intNumberOne + intNumberTwo
> Case "Subtract"
> answer.Text = intNumberOne - intNumberTwo
> Case "Multiply"
> answer.Text = intNumberOne * intNumberTwo
> Case "Divide"
> answer.Text = intNumberOne / intNumberTwo
> End Select
> End Sub
> </script>
>
> <html>
> <head><title>calculator</title></head>
> <body>
>
> <form runat="server">
> <h4>Calculator</h4>
> Please enter numbers and operator:
> <br />
> <asp:textbox id="NumberOne" runat="server" />
> <br />
> <asp:dropdownlist id="operator" runat="server">
> <asp:listitem>Add</asp:listitem>
> <asp:listitem>Subtract</asp:listitem>
> <asp:listitem>Multiply</asp:listitem>
> <asp:listitem>Divide</asp:listitem>
> </asp:dropdownlist>
> <br />
> <asp:textbox id="NumberTwo" runat="server" />
> <br />
> <input type="Submit" value="Calculate">
> <input type="reset">
> <br />
> <br />
> Answer is:
> <br />
> <asp:label id="answer" runat="server" />
> </form>
> </body>
> </html>
>
> Thanks,
> Andy Jordan
>
>
>
>
> to unsubscribe send a blank email to leave-aspx_beginners-
> 818575C@p...
Message #3 by "Jordan, Andy" <Andy.Jordan@g...> on Mon, 4 Mar 2002 13:07:53 -0000
|
|
Hi Carl,
Yes, you're right. But this was not what I intended. I want the reset button
to clear the form after a calculation so I can start over. Any ideas?
Thanks,
Andy
-----Original Message-----
From: Carl E. Olsen [mailto:carl-olsen@m...]
Sent: 04 March 2002 12:53
To: aspx_beginners
Subject: [aspx_beginners] RE: Form 'Reset' Question
I just tried it, and it works just fine. You have to hit the "reset"
button first. If you hit the "calculate" button first, it will not
clear the form. It will only reset before the form is submitted.
Carl Olsen, MCSE
> -----Original Message-----
> From: Jordan, Andy [mailto:Andy.Jordan@g...]
> Sent: Monday, March 04, 2002 5:34 AM
> To: aspx_beginners
> Subject: [aspx_beginners] Form 'Reset' Question
>
> Hi,
>
> As you can see I'm only up to chapter 6 so far. I've tried to make
myself
> a
> simple calculator, however I can't get the 'Reset' button on my form
to
> work.
> Does anyone have an explanation?
> Source code below: (example can be viewed online at
> http://hosting.msugs.ch/pragna/calculator.aspx)
>
> <script language="vb" runat="server">
> Sub Page_Load
>
> Dim intNumberOne As Integer
> Dim intNumberTwo As Integer
>
> If Request.Form("NumberOne") <> "" then
> intNumberOne = Request.Form("NumberOne")
> End If
>
> If Request.Form("NumberTwo") <> "" then
> intNumberTwo = Request.Form("NumberTwo")
> End If
>
> Select Case (Request.Form("operator"))
> Case "Add"
> answer.Text = intNumberOne + intNumberTwo
> Case "Subtract"
> answer.Text = intNumberOne - intNumberTwo
> Case "Multiply"
> answer.Text = intNumberOne * intNumberTwo
> Case "Divide"
> answer.Text = intNumberOne / intNumberTwo
> End Select
> End Sub
> </script>
>
> <html>
> <head><title>calculator</title></head>
> <body>
>
> <form runat="server">
> <h4>Calculator</h4>
> Please enter numbers and operator:
> <br />
> <asp:textbox id="NumberOne" runat="server" />
> <br />
> <asp:dropdownlist id="operator" runat="server">
> <asp:listitem>Add</asp:listitem>
> <asp:listitem>Subtract</asp:listitem>
> <asp:listitem>Multiply</asp:listitem>
> <asp:listitem>Divide</asp:listitem>
> </asp:dropdownlist>
> <br />
> <asp:textbox id="NumberTwo" runat="server" />
> <br />
> <input type="Submit" value="Calculate">
> <input type="reset">
> <br />
> <br />
> Answer is:
> <br />
> <asp:label id="answer" runat="server" />
> </form>
> </body>
> </html>
>
> Thanks,
> Andy Jordan
>
>
>
>
> to unsubscribe send a blank email to leave-aspx_beginners-
> 818575C@p...
$subst('Email.Unsub').
Message #4 by "Minh T. Nguyen" <nguyentriminh@y...> on Mon, 4 Mar 2002 09:11:27 -0800
|
|
Andy,
The reason why the reset button doesn't work after the first
calculation is that the values of the two textboxes are hardcoded into
the HTML as default values when they are returned from the first
calculation (on top of being stored in the viewstate). So, if you for
instance type in new values into the textboxes and hit the "Reset"
button, it probably will reset them back to the default values (the
first calculation's values).
I think you have two solutions to this. Either turn off the
EnableViewState properties of those two textboxes, indicating that you
don't want ASP.NET to remember these values. The two textboxes should
then return empty.
The other alternative is to make the Reset button a regular
ASP.NET button with the caption "Reset" and handle the resetting of the
two textboxes manually with server-side code a la MyTextBox1.Text = "".
The downside is that hitting the reset-button will force a server
roundtrip.
Hope this helps,
Minh.
-----Original Message-----
From: Jordan, Andy [mailto:Andy.Jordan@g...]
Sent: Monday, March 04, 2002 5:08 AM
To: aspx_beginners
Subject: [aspx_beginners] RE: Form 'Reset' Question
Hi Carl,
Yes, you're right. But this was not what I intended. I want the reset
button to clear the form after a calculation so I can start over. Any
ideas? Thanks, Andy
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
Message #5 by "Jordan, Andy" <Andy.Jordan@g...> on Tue, 5 Mar 2002 09:13:51 -0000
|
|
Minh,
Thanks for you explanation - it makes sense and you are correct that hitting
'Reset' with my current code will reset them back to the default values (the
first calculation's values). I've tried to follow your first suggestion to
turn of the EnableViewState but I can't work out how to do this. Can you
help any further by telling me how I set the EnableViewState=false to
achieve this?
Thanks,
Andy
-----Original Message-----
From: Minh T. Nguyen [mailto:nguyentriminh@y...]
Sent: 04 March 2002 17:11
To: aspx_beginners
Subject: [aspx_beginners] RE: Form 'Reset' Question
Andy,
The reason why the reset button doesn't work after the first
calculation is that the values of the two textboxes are hardcoded into
the HTML as default values when they are returned from the first
calculation (on top of being stored in the viewstate). So, if you for
instance type in new values into the textboxes and hit the "Reset"
button, it probably will reset them back to the default values (the
first calculation's values).
I think you have two solutions to this. Either turn off the
EnableViewState properties of those two textboxes, indicating that you
don't want ASP.NET to remember these values. The two textboxes should
then return empty.
The other alternative is to make the Reset button a regular
ASP.NET button with the caption "Reset" and handle the resetting of the
two textboxes manually with server-side code a la MyTextBox1.Text = "".
The downside is that hitting the reset-button will force a server
roundtrip.
Hope this helps,
Minh.
-----Original Message-----
From: Jordan, Andy [mailto:Andy.Jordan@g...]
Sent: Monday, March 04, 2002 5:08 AM
To: aspx_beginners
Subject: [aspx_beginners] RE: Form 'Reset' Question
Hi Carl,
Yes, you're right. But this was not what I intended. I want the reset
button to clear the form after a calculation so I can start over. Any
ideas? Thanks, Andy
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
$subst('Email.Unsub').
Message #6 by "Minh T. Nguyen" <nguyentriminh@y...> on Tue, 5 Mar 2002 01:47:15 -0800
|
|
Andy,
As it turns out setting the EnableViewState to "false" didn't
solve your problem after all--I just tried. In case you're interested,
EnableViewState is a property of the control, so it shows up in the
property window in VS.NET. It will basically insert the
EnableViewState="False" attribute of the <asp:TextBox>-tag. I thought
that the EnableViewState basically says that the content of this control
should be remembered/stored in the viewstate, but I guess I am missing
something.
I guess you just have to manually clear the textboxes in your
Reset-method as in:
private void RestButton_Click(object sender, System.EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
}
Or maybe you want to clear it in the same method that actually
calculates the result. This way there is no need for a Reset button to
begin with.
Good luck,
Minh.
-----Original Message-----
From: Jordan, Andy [mailto:Andy.Jordan@g...]
Sent: Tuesday, March 05, 2002 1:14 AM
To: aspx_beginners
Subject: [aspx_beginners] RE: Form 'Reset' Question
Minh,
Thanks for you explanation - it makes sense and you are correct that
hitting 'Reset' with my current code will reset them back to the default
values (the first calculation's values). I've tried to follow your first
suggestion to turn of the EnableViewState but I can't work out how to do
this. Can you help any further by telling me how I set the
EnableViewState=false to achieve this?
Thanks,
Andy
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
Message #7 by "Jordan, Andy" <Andy.Jordan@g...> on Wed, 6 Mar 2002 09:16:00 -0000
|
|
Minh,
Thanks for your help on this one.
Andy
-----Original Message-----
From: Minh T. Nguyen [mailto:nguyentriminh@y...]
Sent: 05 March 2002 09:47
To: aspx_beginners
Subject: [aspx_beginners] RE: Form 'Reset' Question
Andy,
As it turns out setting the EnableViewState to "false" didn't
solve your problem after all--I just tried. In case you're interested,
EnableViewState is a property of the control, so it shows up in the
property window in VS.NET. It will basically insert the
EnableViewState="False" attribute of the <asp:TextBox>-tag. I thought
that the EnableViewState basically says that the content of this control
should be remembered/stored in the viewstate, but I guess I am missing
something.
I guess you just have to manually clear the textboxes in your
Reset-method as in:
private void RestButton_Click(object sender, System.EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
}
Or maybe you want to clear it in the same method that actually
calculates the result. This way there is no need for a Reset button to
begin with.
Good luck,
Minh.
-----Original Message-----
From: Jordan, Andy [mailto:Andy.Jordan@g...]
Sent: Tuesday, March 05, 2002 1:14 AM
To: aspx_beginners
Subject: [aspx_beginners] RE: Form 'Reset' Question
Minh,
Thanks for you explanation - it makes sense and you are correct that
hitting 'Reset' with my current code will reset them back to the default
values (the first calculation's values). I've tried to follow your first
suggestion to turn of the EnableViewState but I can't work out how to do
this. Can you help any further by telling me how I set the
EnableViewState=false to achieve this?
Thanks,
Andy
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
$subst('Email.Unsub').
Message #8 by "Peter" <petemail@r...> on Wed, 6 Mar 2002 16:33:47 -0500
|
|
|
|
 |