views:

1089

answers:

1

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!

+2  A: 

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.

HectorMac
This would work for next page, but how to refer the hidden field from third page in sequence? Using Page.PreviousPage.PreviousPage etc?
Alexander Prokofyev