Transfering web control data from one page to another

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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!
 
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
 
Back
Top