c# - Textbox (and other controls) - "Object not set to an instance...." -


i realize common error , i've followed many fixes problem offered online have yet find solution.

i developed winform app gets json external website. click button control , app goes through json serialiser method , posts results textbox , appends textarea.

 public void renderdata(string buttontext)     {          if (buttontext == "start")         {             equationdata deserializeddata = getdata("http://test.ethorstat.com/test.ashx");              var processed = new processequation();             int result = processed.calculate(deserializeddata);              string res = deserializeddata.parm1 + "  " + deserializeddata.op + "  " + deserializeddata.parm2 +                 " = " + result;             textboxresult.text = res;              equation.append("  " + deserializeddata.parm1 + "  " + deserializeddata.op + "  " + deserializeddata.parm2 +                 " = " + result + '\n');             textarearesults.value = equation.tostring();         }     } 

this worked fine was. requirements have changed in app has poll data every second. therefore created wcf web service called jquery script run every second.

the problem controls - textbox , textboxarea - generate {"object reference not set instance of object."}. assumption these controls aren't being loaded i'm calling method jquery's ajax function (?).

$(document).ready(function () {  //while ($('#ethorbutton').text != "stop") { if ($('#ethorbutton').click) {     $.ajax({     url: 'service/ethorservice.svc/getupdate',     method: 'get',     datatype: 'json',     success: function(){         alert("success");     },     error: function (err) {         alert(err);     }  }) //delay(1000);  }  

});

my controls show in intellisense and, of course, on default.aspx when run it. how can fix this?

edit

i solved 'object not set...' problem instantiating new textbox:

 public partial class _default : page {     public static stringbuilder equation = new stringbuilder();     public textbox textboxtest = new textbox(); 

when debug , step through value set, textbox renders textbox empty. how fix that?

make method static , add annotation [webmethod] , return list of results.

[system.web.services.webmethod(enablesession=true)] public static list<string> renderdata(string buttontext) {        // return result here } 

pass parameter data:{buttontext:yourvalue} $.ajax call. , change success function , assign values control on client side via javascript.

success : function(msg){       if(msg.d!=null){              $('#<%=textboxresult.clientid%>').val(msg.d[0]); } } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -