1

Assume I have an list or array (doesn't matter) in a aspx.cs page. How can I pass that list/array etc to send it to a master page. Then in a function use that information to pass to an .aspx page without passing the list/array to the function?

Hope this makes sense. Thank you.

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Mike Smith
  • 145
  • 1
  • 8
  • 1
    Possible duplicate of [ASP.NET: Passing data from content page to master page](https://stackoverflow.com/questions/21160132/asp-net-passing-data-from-content-page-to-master-page) – mjwills Jun 21 '17 at 22:38

3 Answers3

0

My best guess to your answer would be storing the variable in session (Session.MyVariable) and once the child page loads, access it via that way. You wouldn't necessarily be passing it from the layout page to the view but this would allow you to get whatever data to the view once it's loaded under the layout page. If that helps, not entirely sure I understand.

In the "header" of the child page

@{
    if (Session.MyVariable != null)
    {
       // do something on the webpage with this data
    }
}
Dr Archer
  • 348
  • 1
  • 3
  • 14
0

May be this link will help you https://www.codeproject.com/Articles/333650/Beginner-s-Tutorial-on-Master-Pages-in-ASP-NET

Go to the part where he describes "Changing the Master Page's Properties from Content Pages", he defined a label in site master, then he was able to change the text of this label from the content pages.

user1947393
  • 153
  • 4
  • 18
  • I have to be honest I'm still a little confused. If I had an array named arrayMaster, would I write: Session["master"] = arrayMaster; And how would I use arrayMaster later on so I could use it in a function? Thanks for the help! – Mike Smith Jun 22 '17 at 00:33
  • I hope I understood your point. If you write in page1 session["master"]=arrayMaster , and you want the value in page2, you need to use the session, just define an array in page 2 and make it equal to session["master"] (myarray=session["master"]) – user1947393 Jun 23 '17 at 01:17
-1

My best guest is to pass like a serialized XML and then parse it in master page

Jorge M
  • 95
  • 1
  • 1
  • 8