Transfering web control data from one page to another

G

Guest

I used the following code to transfer some web control data from Page1.aspx
to Page2.aspx.
It is successful to get the TextBox.Text over, but the DropDownList data
failed to appear in Page2. I wonder what went wrong?

Page1.aspx.cs
-----------------
public object Dept
{
get
{
return ddlDept.DataSource;
}
}

public string Rcp
{
get
{
return tbRcp.Text;
}
}

Page2.aspx.cs
-----------------
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack )
{
Page1 srcPage = (Page1) Context.Handler;
ddlDept.DataSource = srcPage.Dept;
ddlDept.DataBind();
tbRcp.Text = srcPage.Rcp;
}
}

Thanks in advance,
Ben
 
S

Scott Mitchell [MVP]

I'm not 100% sure if this is the reason why you're having problems, but
the DataSource is not persisted in view state, like the Text property
is. That is, it does not survive postbacks. I would imagine this would
work if you set the DataSource and then immediately did a
Server.Transfer(), but I'm wagering you're doing a Server.Transfer()
after postback, no?

Just a shot in the dark... hth!

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 
G

Guest

Yes, you're right !

Following your pointer, I changed the code to set the DataSource and then
immediately Server.Transfer("Page2.aspx") and then it works.

So to obtain the DataSource from the source page, the only way is to
Server.Transfer after setting the DataSource?

Many Thanks,
Ben
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top