i call my server side method by jquery and from that method i am trying to access textboxes data. here is my sample code
[WebMethod]
public static PayPalCart CreatePayPalFields()
{
Page CurPage = HttpContext.Current.Handler as Page;
string tt = ((TextBox)CurPage.FindControl("txtBillAddress1")).Text;
}
i am getting error for accessing the control from static method and the error message is Object reference not set to an instance of an object. then i search google to find out better solution then i got a extension method which will loop through control collection and return control if found. the code is like
public static T BetterFindControl<T>(this Control root, string id) where T : Control
{
if (root != null)
{
if (root.ID == id) return root as T;
var foundControl = (T)root.FindControl(id);
if (foundControl != null) return foundControl;
foreach (Control childControl in root.Controls)
{
foundControl = (T)BetterFindControl<T>(childControl, id);
if (foundControl != null) return foundControl as T;
}
}
return null;
}
i use the above routine also from static method like
[WebMethod]
public static PayPalCart CreatePayPalFields()
{
Page CurPage = HttpContext.Current.Handler as Page;
string sData = CurPage.BetterFindControl<TextBox>("txtDeliveryFName").Text;
}
but still no luck....still getting the same error for accessing control from static method and found that the CurPage has no control. please suggest me what should i do. tell me a way out to access control from static method because method has to be static reason i am invoking that method by jquery.........need help.