c# - Make an object reference of an existing Literal in the aspx -


how can make object reference of literal have declared in aspx page. use ltlcontents.text = ..... need make reference of ltlcontents can use in static method same way use .text attribute.

i tried literal ltl = ... new me, it's different usual object referencing, comes front-end.

update: want use ltlcontents object in static method this: ltlcontents.text = valuefromsomefunction, compiler gives me following error: an object reference required non-static field, method, or property _default.ltlcontents.

you need reference control or page control sitting in. page must running though actual lifecycle. example webmethod cannot access control.

however, can access control static method, seems want:

public static void setcontroltext(string controlid, string text)  {     page page = httpcontext.current.handler page;    if (page != null)    {       control ctrl = findcontrolrecursive(page, controlid);       if(ctrl != null)       {           itextcontrol txt = ctrl itextcontrol;           if(txt != null)               txt.text = text;       }    } }  public static control findcontrolrecursive(control root, string id) {     if (root.id == id) return root;     foreach (control c in root.controls)     {         control t = findcontrolrecursive(c, id);         if (t != null) return t;     }     return null; } 

now works everywhere during lifefycle of page:

setcontroltext("ltlcontents", "hello world"); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -