或許你需要更改您的代碼是這樣的:爲遵循
更改代碼
private static void GetDetails(HiddenField field)
{
txtAccreditation.Text = field.Value ;
}
,並調用它
Page page = (Page)HttpContext.Current.Handler;
HiddenField hdnUserID = (HiddenField)page.FindControl("hdnUserID");
YourClassName.GetDetails(hdnUserId);
我不明白的是爲什麼你會稱它爲通過靜態操作。
我會假設你多創造一些類似下面的代碼:
private static string GetDetails(HiddenField field)
{
return field.Value ;
}
這將導致下面的代碼:此代碼將不會出現在靜態函數內部。
Page page = (Page)HttpContext.Current.Handler;
HiddenField hdnUserID = (HiddenField)page.FindControl("hdnUserID");
txtAccreditation.Text = YourClassName.GetDetails(hdnUserId);
這意味着你可以實際使用的代碼在其他地方
只是想什麼:http://stackoverflow.com/questions/241339/when-to-use-static-classes-in-c-尖銳; – Schuere