troubleshooting Question

how to set post parameters in javascript:__doPostBack request in

Avatar of mmalik15
mmalik15 asked on
.NET ProgrammingC#ASP.NET
2 Comments1 Solution1321 ViewsLast Modified:
I am trying to replicate __doPostBack request on this website

 But no matter what I try passing in post parameters I always get the first page. Any ideas why this could be happening

 protected void ScrapPage()

        string str = "MSOWebPartPage_PostbackSource=&MSOTlPn_SelectedWpId=&MSOTlPn_View=0&MSOTlPn_ShowSettings=False&MSOGallery_SelectedLibrary=&MSOGallery_FilterString=&MSOTlPn_Button=none";

        string lcUrl = "";

        HttpWebRequest loHttp = (HttpWebRequest)WebRequest.Create(lcUrl);

        // *** Send any POST data

        string lcPostData = str + "&__EVENTTARGET" + HttpUtility.UrlEncode("ctl00$m$g_06bd18ef_887b_4e8f_a9ba_e08b261f48b2$ctl00$a_oGrid") + "&__EVENTARGUMENT" + HttpUtility.UrlEncode("Page$2") + "&__REQUESTDIGEST" + HttpUtility.UrlEncode("0x6AF8F97ECFDC4FAE85C00617D9C48FB116D7973B07D545634FCA1EBFF3C3C848A3AEBD78AE99CCECC1EB4AB57E1E28633587A9C7A4FCFD2E7E9DD94373FF9495,23 May 2012 12:52:55 -0000&MSOSPWebPartManager_DisplayModeName=Browse&MSOSPWebPartManager_ExitingDesignMode=false&MSOWebPartPage_Shared=&MSOLayout_LayoutChanges=&MSOLayout_InDesignMode=&_wpSelected=&_wzSelected=&MSOSPWebPartManager_OldDisplayModeName=Browse&MSOSPWebPartManager_StartWebPartEditingName=false&MSOSPWebPartManager_EndWebPartEditing=false&") + "&__VIEWSTATE" + HttpUtility.UrlEncode("valueofviewstatewhichIseefromfirebug");

        loHttp.Method = "POST";

        byte[] lbPostBuffer = System.Text.Encoding.GetEncoding(1252).GetBytes(lcPostData);

        loHttp.ContentLength = lbPostBuffer.Length;

        Stream loPostData = loHttp.GetRequestStream();

        loPostData.Write(lbPostBuffer, 0, lbPostBuffer.Length);


        HttpWebResponse loWebResponse = (HttpWebResponse)loHttp.GetResponse();

        Encoding enc = System.Text.Encoding.GetEncoding(1252);

        StreamReader loResponseStream = new StreamReader(loWebResponse.GetResponseStream(), enc);

        string lcHtml = loResponseStream.ReadToEnd();



Christopher Kile
Senior Software Analyst

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros