Link to home
Start Free TrialLog in
Avatar of mmalik15

asked on

how to set post parameters in javascript:__doPostBack request in

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();




Open in new window

Avatar of Aaron Jabamani
Aaron Jabamani
Flag of United Kingdom of Great Britain and Northern Ireland image

Why you want to generate a postback....pass a variable in the querystring which will tell the page that you are trying to do a post back. Then you can do appropriate logic based on the query parameter.
Avatar of Christopher Kile
Christopher Kile
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial