-2

Inside static method am notable to get hidden field values:

private static void GetDetails()
{
    Page page = (Page)HttpContext.Current.Handler;
    HiddenField hdnUserID = (HiddenField)page.FindControl("hdnUserID");
    txtAccreditation.Text = hdnUserID.Value ; //  here hdnUserID.Value is null why ?? 
}
Jannik
  • 2,310
  • 6
  • 32
  • 61
Muthu
  • 165
  • 4
  • 18
  • Just thinking about something: http://stackoverflow.com/questions/241339/when-to-use-static-classes-in-c-sharp; – Schuere Oct 06 '15 at 06:26

2 Answers2

0

try like this

  Page page = (Page)HttpContext.Current.Handler;
  TextBox TextBox1 = (TextBox)page.FindControl("TextBox1");

  TextBox TextBox2 = (TextBox)page.FindControl("TextBox2");
Amit Soni
  • 3,216
  • 6
  • 31
  • 50
0

perhaps you need to change your code to something like this:

Change your code as followed

private static void GetDetails(HiddenField field)
{     
   txtAccreditation.Text = field.Value ;
}

and call it like this

Page page = (Page)HttpContext.Current.Handler;
HiddenField hdnUserID = (HiddenField)page.FindControl("hdnUserID");
YourClassName.GetDetails(hdnUserId);

What I do not understand is why would you call it through a static operation.

I would assume you create something more like the following code:

private static string GetDetails(HiddenField field)
{     
   return field.Value ;
}

This would result in the following code: This code will not be present inside the static function.

Page page = (Page)HttpContext.Current.Handler;
HiddenField hdnUserID = (HiddenField)page.FindControl("hdnUserID");
txtAccreditation.Text = YourClassName.GetDetails(hdnUserId);

meaning you could actually use the code everywhere else

Schuere
  • 1,579
  • 19
  • 33