Avatar of mmalik15
 asked on

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

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


        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

ASP.NETC#.NET Programming

Avatar of undefined
Last Comment
Christopher Kile

8/22/2022 - Mon
Aaron Jabamani

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.
Christopher Kile

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck