Search code examples
jqueryasp.netpage-init

how do i get the value of HiddenField in page_init?


I have set HiddenField value from jQuery and i want to use this HiddenField value in page_init event, but each time i get blank value. what would be the issue.

$('#hfKitchenID').val(kitchenid);

protected void Page_Init(object sender, EventArgs e)
{
    string value = hfKitchenID.Value;
}

Solution

  • You cannot get the value of the hidden field on Page_init because the value of the hidden field is save in ViewState, and ViewState is not accessible on Page_Init.

    In the page life cycle the LoadViewState Event occurs just after the Init Event.