Passing values between webpages

J

jez123456

Hi Experts

I’m trying to pass a value from one webform to another using ASP.Net with vb
code behind. I have a c# example which work ok but I cannot get the vb
version working.

This is the working c# code. Basically I have WebForm1

protected void Button1_Click(object sender, EventArgs e)
{
Server.Transfer("anotherwebform.aspx");
}

public string Name
{
get
{
return TextBox1.Text;
}
}

public string EMail
{
get
{
return TextBox2.Text;
}
}

Then the values get passed to anotherwebform.aspx

public partial class anotherwebform : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//create instance of source web form
WebForm1 wf1;
//get reference to current handler instance
wf1 = (WebForm1)Context.Handler;
Label1.Text = wf1.Name;
Label2.Text = wf1.EMail;

}
}

My vb version has WebForm2

Partial Class WebForm2
Inherits System.Web.UI.Page


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Server.Transfer("anotherwebform2.aspx")
End Sub


Public ReadOnly Property Name() As String
Get
Return TextBox1.Text
End Get
End Property

Public ReadOnly Property EMail() As String
Get
Return TextBox2.Text
End Get
End Property

End Class

Then the values get passed to anotherwebform2.aspx

Partial Class anotherwebform2
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

'create instance of source web form
Dim wf1 As WebForm2
'get reference to current handler instance
wf1 = DirectCast(Context.Handler, WebForm2)
Label1.Text = wf1.Name
Label2.Text = wf1.EMail

End Sub
End Class

I get the error Type 'WebForm2' is not defined. Any ideas why. Am I doing
this correctly?


Thanks
 
C

Cor Ligthert[MVP]

Jez,

This looks very much as if you are looking to some windows form code, in
that case it is like that.

In Asp.Net a form is in fact a webpage. Webpages are stateless. Which means
for you that the data ends as soon as all methods in a post are done.

To transer data from one webpage are different methods.

I use for that the Session (in fact like it was in classic Asp) all other
methods have seldom advantage above this session method.

You create a session simple by filling it.

Session.Item("MyItem") = "someting"

In the other page (form) you can then simple do

Dim MyItem as string = Session.Item("myItem")

Cor
 

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

Similar Threads


Top