3

I have a webform and in that webform, I am trying to access a Panel object from a static method, but couldn't access it How can I access a Panel object from static method. Why am I trying to access the object from static? Because I am using JQUERY which only accepts static methods.

I tried to store Panel in session in Page_Load() and retrieve it from static method but it didn't work.

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Arif Yilmaz
  • 121
  • 2
  • 4
  • 14

2 Answers2

6
public static void DoSomething()
{
    if (HttpContext.Current != null)
    {
        Page page = (Page)HttpContext.Current.Handler;
        TextBox TextBox1 = (TextBox)page.FindControl("TextBox1");

        TextBox TextBox2 = (TextBox)page.FindControl("TextBox2");
    }
}
A Programmer
  • 625
  • 8
  • 30
  • @A Programer how would it be with a Gridview – Ivxn Jan 05 '18 at 21:45
  • @lvxn I think you want something like this : protected void btnSave_Click(object sender, EventArgs e) { foreach (GridViewRow row in grdView.Rows) { CheckBox chkbox = row.FindControl("chkbox") as CheckBox; Label lblJurisdiction = row.FindControl("lblJurisdiction") as Label; ..and so on //Finally retrieve the data like your normal control string labelText = lblJurisdiction.Text; } } – A Programmer Mar 26 '18 at 06:18
5

You are probably using web method in the aspx page to call it from jQuery ajax(). You could not access the controls in web method rather pass the information to your web method by ajax call and return the information from web method to jQuery ajax callback and perform action on panel in javascript jQuery call back function.

Adil
  • 146,340
  • 25
  • 209
  • 204