Alexander Prokofyev
Alexander Prokofyev

Reputation: 34515

Pass the same value of HiddenField between several ASP.NET pages

Would you explain me, please, how to pass the same value of HiddenField between several ASP.NET pages?

I think I could use RegisterHiddenField on every page in chain, but hope there is an easier solution.

Thanks!

Upvotes: 2

Views: 5703

Answers (1)

HectorMac
HectorMac

Reputation: 6143

If you are passing the HiddenField directly between a few pages, you could make the links between the pages button controls using one of Button, LinkButton, or ImageButton. Then you could use the PostBackUrl to navigate to the next page.

<asp:LinkButton ID="Button1" runat="server"
                PostBackUrl="~/TargetPage.aspx" Text="Next Page" />

To access the value from the target page:

if (Page.PreviousPage != null)
{
    string MyHiddenValue = (HiddenField)Page.PreviousPage.FindControl("MyHiddenField");
}

You should probably check whether HiddenField exists etc.

Upvotes: 4

Related Questions