c# - HttpWebRequest - Post with __EVENTTARGET and __EVENTARGUMENT -


i want read content website using asp.net gridview contorl pagination. now, pagination done post method asp.net grid using __dopostback required parameters.

i tried read pagination data using httpwebrequest following code throws "500 internal server error."

  public string getpagedata(int page)     {         var request = (httpwebrequest)webrequest.create("http://localhost:61141/default.aspx");         string postdata = "__eventtarget=ctl00$maincontent$gridview1&__eventargument=page$"+ page;           request.method = "post";         var bt = system.text.encoding.ascii.getbytes(postdata);         request.contentlength = bt.length;         request.contenttype = "application/x-www-form-urlencoded";         request.useragent = " mozilla/4.0 (compatible; msie 6; windows nt 5) ";         request.keepalive = false;         request.allowwritestreambuffering = true;          string strresult;         stream stream = request.getrequeststream();         stream.write(bt, 0, bt.length);         stream.close();          var response = request.getresponse();         var sr = new streamreader(response.getresponsestream(), true);         strresult = sr.readtoend();          return strresult;     } 

please suggest workaround on it. in advanced.

webforms pagination relies on javascript intended performed within web browser, not via custom call have here. why not set web api endpoint or other rest-enabled endpoint in web application? has added benefit can return results xml or json, removes need screen scraping , makes client side processing easier.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -