Access page controls in static method
-
Hi all, I am using vs2010 with .net 4.0 and jquery AJAX to call to a static method in code behind. I was success to call it but cant get the page's control. Following is my sample code :
[WebMethod]
public static string UpdateContent()
{
Page page = HttpContext.Current.Handler as Page;
TextBox tb = (TextBox)page.FindControl("txt");
tb.Text = "some string here";
//others coding here//
if (db.UpdateTable()){return "success";}
else { return "failed"; }
}So,my question is how can i access the page's control in my static method? any tips are welcome thanks in advance cocoon
-
Hi all, I am using vs2010 with .net 4.0 and jquery AJAX to call to a static method in code behind. I was success to call it but cant get the page's control. Following is my sample code :
[WebMethod]
public static string UpdateContent()
{
Page page = HttpContext.Current.Handler as Page;
TextBox tb = (TextBox)page.FindControl("txt");
tb.Text = "some string here";
//others coding here//
if (db.UpdateTable()){return "success";}
else { return "failed"; }
}So,my question is how can i access the page's control in my static method? any tips are welcome thanks in advance cocoon
as per my knowledge, we can not access page control inside the webmethod. So you can implement your functionality in different way. Take a look URL: http://weblogs.asp.net/scottgu/archive/2006/10/22/Tip_2F00_Trick_3A00_-Cool-UI-Templating-Technique-to-use-with-ASP.NET-AJAX-for-non_2D00_UpdatePanel-scenarios.aspx[^] If your requirement is different then let me know.
Parwej Ahamad
-
as per my knowledge, we can not access page control inside the webmethod. So you can implement your functionality in different way. Take a look URL: http://weblogs.asp.net/scottgu/archive/2006/10/22/Tip_2F00_Trick_3A00_-Cool-UI-Templating-Technique-to-use-with-ASP.NET-AJAX-for-non_2D00_UpdatePanel-scenarios.aspx[^] If your requirement is different then let me know.
Parwej Ahamad
-
as per my knowledge, we can not access page control inside the webmethod. So you can implement your functionality in different way. Take a look URL: http://weblogs.asp.net/scottgu/archive/2006/10/22/Tip_2F00_Trick_3A00_-Cool-UI-Templating-Technique-to-use-with-ASP.NET-AJAX-for-non_2D00_UpdatePanel-scenarios.aspx[^] If your requirement is different then let me know.
Parwej Ahamad
Dear Parwej AHamand, My requirement is bit different in what the article provided. In my situation, i need to pass 1 parameters to code behind (ideally is to
.aspx.cs
. Currently i am using webmethod.) and then do some checking with assist by most of the page's controls. For example, pass parameter "Save" to.aspx.cs
, then get 10 textbox's value in that page to do verification. hope u are understand my concern. Thanks in advance cocoon