how to set post parameters in javascript:__doPostBack request in asp.net

mmalik15
mmalik15 used Ask the Experts™
on
I am trying to replicate __doPostBack request on this website

http://www.ihi.org/knowledge/pages/ViewAll.aspx?FilterField1=IHI_x0020_Content_x0020_Type&FilterValue1=Measures&Filter1ChainingOperator=And&Targ

 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 = "http://www.ihi.org/knowledge/pages/ViewAll.aspx?FilterField1=IHI_x0020_Content_x0020_Type&FilterValue1=Measures&Filter1ChainingOperator=And&Targ";

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

        loPostData.Close();

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

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

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

        string lcHtml = loResponseStream.ReadToEnd();

        loWebResponse.Close();

        loResponseStream.Close();

    }

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Aaron JabamaniTechnical Architect

Commented:
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.
Senior Software Analyst
Commented:
I don't know about the whole request, but your VIEWSTATE parameter is scragged.

This

"&__VIEWSTATE" + HttpUtility.UrlEncode("valueofviewstatewhichIseefromfirebug");

should be this


"&__VIEWSTATE=" + HttpUtility.UrlEncode("valueofviewstatewhichIseefromfirebug");

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial