asp.net - How to access Page Controls value from C# webmethod -


i'm using c# asp.net web form application. using asp grid view control pages. once add ajax method c# web method capture data in web page. in c# web method can't capture grid view records. it's shows null always. how can records in web method.

this code:

[webmethod] public bool validategrid(string rowindex, string cellindex) {     homedefault pagemethods = new homedefault();    pagemethods.validategridviewcontrols(convert.toint32(rowindex), convert.toint32(cellindex));    return true;  }   private void validategridviewcontrols(int rowindex, int cellindex) {     foreach (gridviewrow row in grvprogram.rows)     {      } } 

in case grvprogram.rows alaways null.

please me sort out issue,

there 2 issues going experience current implementation:

1) zaki pointed out in comments, [webmethod] should

public static bool validategrid(string rowindex, string cellindex)

2) suspicion homedefault pagemethods = new homedefault(); aspx page code-behind class. when asp.net creates homedefault class, not call new homedefault(). in fact, lots of crazy magical things class have access httpcontext, postback information if exists. why when call

yourpage.grvprogram.property

grvprogram null. because constructor of class not make it, asp.net makes through other methods initializecomponent, etc. do not call methods yourself, may have unintended side effects or dependencies in .net or iis pipeline.

how solve then?

look @ how grvprogram control made. must put data in there somewhere, , create rows using data. instead of comparing user input control, compare data used populate control.

yes, more work in sense have refactor logic retrieving , populating control, safer , faster because not relying on state of entire code-behind class data validation.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -