lblFirstName.Text = firstName; lblLastName.Text = lastName;should be changed to
lblFirstName.Text = firstName.Text; lblLastName.Text = lastName.Text;>I am trying to do a "cross-page posting", where the values of the controls on the first page, which calls the second page, will be able to be displayed by label controls on the 2nd page. I keep getting a namespace error that says I "...cannot implicitly convert a textbox to string type". I am not sure what I need to do at this point.
><asp:Button ID="btnSubmit" runat="server" Text="Submit" PostBackUrl="~/ShowContactData.aspx" /> >>
>using System; >using System.Collections.Generic; >using System.Linq; >using System.Web; >using System.Web.UI; >using System.Web.UI.WebControls; > >namespace Program2 >{ > public partial class ShowContactData : System.Web.UI.Page > { > protected void Page_Load(object sender, EventArgs e) > { > if (PreviousPage != null) > { > // Create an instance of the previous page's controls. > TextBox firstName = null; > TextBox lastName = null; > > // Fill variables with the values in the previous page using FindControl() of PreviousPage. > firstName = (TextBox)this.PreviousPage.FindControl("txtFirstName"); > lastName = (TextBox)this.PreviousPage.FindControl("txtLastName"); > > // Bind the labels using values in textboxes. > lblFirstName.Text = firstName; > lblLastName.Text = lastName; > } > } > } > >} >>
> <asp:Label ID="lblFirstName" runat="server"></asp:Label> > <br /> > <asp:Label ID="lblLastName" runat="server"></asp:Label> >