Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hello,
i want to access one page label control into another page can u guide or send any snippets
Posted

You can keep seperate labels in your aspx pages and use session to pass the label value between pages.
Lets say the ID of label in page 1 is "Label1" and ID of label in page 2 is "Label2"

In Page 1 you will store the value of label1 before redirecting to Page 2.
C#
Session["LabelValue"] = Label1.text;

Response.Redirect("Page2.aspx");


In page 2 you can retrieve the value from session and assign it to label2 as shown below
C#
if (Session["LabelValue"] != null)

{

    //get the Session value

    Label2.text = Session["LabelValue"].ToString();

}
 
Share this answer
 
 
Share this answer
 
Hi,

Try with

C#
Page.PreviousPage.FindControls("YourcontrolId").Text


If your page is postback and come to the next page then above code will work. You may need to iterate through the controls if your label is not on parent hierarchy.

Hope this should work for you, You need to check condition for your control is not null. Directly calling .Text may cause ObjectReferenceException.

Thanks
-Amit Gajjar
 
Share this answer
 
Hello,

You can use Page.PreviousPage.FindControl to achieve expected result.

Please refer below code snippet for more details.

Label lbl1 = (Label)Page.PreviousPage.FindControl("serverNameText");


Please let us know if any.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900