Server.Transfer() question

vargf

Member
Joined
Feb 15, 2006
Messages
13
Programming Experience
Beginner
I find Already the answer I give thanks to my freand.

Now How can I put the answer to the second page

this is the code:

MainPage.aspx


VB.NET:
ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load
Try' start of a try block
Dim MyError AsNew Exception("This is the error I am throwing") 'create the exception with my message
Throw MyError ' Throw the error. Execution will stop and jump to a catch
For counter AsInteger = 0 To 100 ' this is a long loop but should never run
txtDiplaymasage.Text = counter.ToString
Next
Catch ex As Exception
txtDiplaymasage.Text = ex.Message ' display the error message in the message txtbox
EndTry' end of the try block
EndSub
ProtectedFunction Multiply(ByVal Value1 AsDouble, ByVal Value2 AsDouble) AsDouble
txtInput1.Text = Value1
txtInput2.Text = Value2
Server.Transfer("Result.aspx") ' the answer goes in this page
Try
Return (Value1 * Value2) ' do the math
Catch ex As Exception ' if there is an issue report it
txtDiplaymasage.Text = ex.Message
EndTry
EndFunction
ProtectedFunction Divition(ByVal Value1 AsDouble, ByVal Value2 AsDouble) AsDouble
txtInput1.Text = Value1
txtInput2.Text = Value2
Server.Transfer("Result.aspx") 'The aswer goes in this page
Try
Return (Value1 / Value2) ' do the math
Catch ex As Exception ' if there is an issue report it
txtDiplaymasage.Text = ex.Message
EndTry
 
EndFunction
ProtectedFunction Addition(ByVal Value1 AsDouble, ByVal Value2 AsDouble) AsDouble
txtInput1.Text = Value1
txtInput2.Text = Value2
Server.Transfer("Result.aspx") ' The answer goes in this page 
Try
Return (Value1 + Value2) ' do the math
Catch ex As Exception ' if there is an issue report it
txtDiplaymasage.Text = ex.Message
EndTry
 
EndFunction
ProtectedFunction Substraction(ByVal Value1 AsDouble, ByVal Value2 AsDouble) AsDouble
txtInput1.Text = Value1
txtInput2.Text = Value2
Server.Transfer("Result.aspx") ' The answer goes in this page
Try
Return (Value1 - Value2) ' do the math
Catch ex As Exception ' if there is an issue report it
txtDiplaymasage.Text = ex.Message
EndTry
EndFunction
ProtectedFunction GetNumber(ByVal Value AsString) AsDouble
Try
Return Convert.ToDouble(Value) ' convert
Catch ex As Exception
txtDiplaymasage.Text = ex.Message 'Display the message
Throw ex 'Rethrow the exception
EndTry
EndFunction
ProtectedSub btnMultiplicationCalculation_Click(ByVal sender AsObject, ByVal e As System.EventArgs) 
Handles btnMultiplicationCalculation.Click
Try' Do the math
txtDiplaymasage.Text = Multiply(GetNumber(txtInput1.Text), GetNumber(txtInput2.Text))
Catch ex As Exception
txtInput1.Text = "Please try again"' Show that there was an error
EndTry
 
EndSub
ProtectedSub btnDivitionCalculation_Click(ByVal sender AsObject, ByVal e As System.EventArgs) 
Handles btnDivitionCalculation.Click
Try' Do the math
txtDiplaymasage.Text = Divition(GetNumber(txtInput1.Text), GetNumber(txtInput2.Text))
Catch ex As Exception
txtInput1.Text = "Please try again"' Show that there was an error
EndTry
 
EndSub
ProtectedSub btnAdditionCalculation_Click(ByVal sender AsObject, ByVal e As System.EventArgs) 
Handles btnAdditionCalculation.Click
Try' Do the math
txtDiplaymasage.Text = Addition(GetNumber(txtInput1.Text), GetNumber(txtInput2.Text))
Catch ex As Exception
txtInput1.Text = "Please try again"' Show that there was an error
EndTry
EndSub
 
ProtectedSub btnSubstractionCalculation_Click(ByVal sender AsObject, ByVal e As System.EventArgs) 
Handles btnSubstractionCalculation.Click
Try' Do the math
txtDiplaymasage.Text = Substraction(GetNumber(txtInput1.Text), GetNumber(txtInput2.Text))
Catch ex As Exception
txtInput1.Text = "Please try again"' Show that there was an error
EndTry
 
EndSub
HTML Part
HTML:
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>control webpage</title>
<linkrel="Stylesheet"type="text/css"href="StyleSheet.css"/>
</head>
<body>
<formid="form2"runat="server"/>
<div>
 
<asp:TextBoxID="txtInput1"runat="server"Style="z-index: 100; left: 186px; position: absolute;
top: 177px"Width="103px"></asp:TextBox>
  
<asp:TextBoxID="txtDiplaymasage"runat="server"Style="z-index: 101; left: 100px;
position: absolute; top: 115px"Width="324px"></asp:TextBox>
 
<asp:ButtonID="btnMultiplicationCalculation"runat="server"Style="z-index: 102; left: 
120px;
position: absolute; top: 271px"Text="Multiply"PostBackUrl="~/Result.aspx"/>
<asp:TextBoxID="txtInput2"runat="server"Style="z-index: 103; left: 188px; position: 
absolute;
top: 221px"Width="103px"></asp:TextBox>
<asp:CompareValidatorID="txtInputValidation2"runat="server"ControlToValidate="txtInput2"
ErrorMessage="Do not Divede by Zero"ForeColor="#FF8080"Style="z-index: 104;
left: 318px; position: absolute; top: 224px"></asp:CompareValidator><asp:ButtonID=
"btnSubstractionCalculation"
runat="server"Style="z-index: 
105; left: 346px;
position: absolute; top: 272px"Text="Subtract"PostBackUrl="~/Result.aspx"/>
<asp:ButtonID="btnAdditionCalculation"runat="server"Style="z-index: 106; left: 278px;
position: absolute; top: 272px"Text="Add"PostBackUrl="~/Result.aspx"/>
<asp:ButtonID="btnDivitionCalculation"runat="server"Style="z-index: 107; left: 201px;
position: absolute; top: 271px"Text="Divide"PostBackUrl="~/Result.aspx"/>
<asp:LabelID="Label1"runat="server"Style="z-index: 109; left: 261px; position: absolute;
top: 326px"></asp:Label>
 
</div>
 
</body>
</html>
Result.aspx
VB.NET:
Dim Label1 As TextBox
 
ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load
 
 
If IsPostBack Then
 
Label1 = CType(PreviousPage.FindControl("Label1"), TextBox)
lblResult.Text = Label1.Text
 
End If
EndSub
Html part
HTML:
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Welcome</title>
<linkrel="stylesheet"type="text/css"href="StyleSheet.css"/>
</head>
<body>
<formid="form1"runat="server"method="get"action="Mainpage.aspx">
<div>
<center><h1>
Math
<asp:LabelID="lblResult"runat="server"Style="z-index: 100; left: 245px; position: absolute;
top: 231px"Width="180px"></asp:Label>
Center</h1></center>
</div>
</form>
</body>
</html>
But I get the following error when I arrive to the Result.aspx page
Server Error in '/VargasIP2' Application.

Control 'txtInput1' of type 'TextBox' must be placed inside a form tag with runat=server.

[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Description: An unhandled exception occurred during the execution of the current web request. [/FONT]

[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Please review the stack trace for more information about the error and where it originated in the code. [/FONT]

[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Exception Details: System.Web.HttpException: Control 'txtInput1' of type 'TextBox' [/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]must be placed inside a form tag with runat=server.[/FONT]

[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:

[HttpException (0x80004005): Control 'txtInput1' of type 'TextBox' must be placed inside a form tag with runat=server.] System.Web.UI.Page.VerifyRenderingInServerForm(Control control) +301 System.Web.UI.WebControls.TextBox.AddAttributesToRender(HtmlTextWriter writer) +119 System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter writer) +36
System.Web.UI.WebControls.TextBox.Render(HtmlTextWriter writer) +32
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +74 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +291
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +49
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +234 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +53
System.Web.UI.Control.Render(HtmlTextWriter writer) +31
System.Web.UI.Page.Render(HtmlTextWriter writer) +39
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +74 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +291
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +49
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,
Boolean includeStagesAfterAsyncPoint) +5537

Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
[/FONT]

I'm new int ASP.Net 2.0 and I need help to lern more and finish my Program.
 
Last edited by a moderator:
Hi,

I think for your first HTML code, there isn't a closing tag for "Form". There should be a </Form> somewhere at the end.
 
Back
Top