Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4087098
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:48:44+00:00 2026-05-20T18:48:44+00:00

I am trying to call the __doPostback javascript function in a asp.net page from

  • 0

I am trying to call the __doPostback javascript function in a asp.net page from php using curl.

I learnt that this can be done by making a post request to the asp.net page with the appropriate parameters.

So in curl,

  1. I make a get request / just use file_get_contents to retrieve the initial page.
  2. From this, I extract the values for __VIEWSTATE and __EVENTVALIDATION.

So far everything seems ok.

Now, I understand that we need to make a post request using cURL with __VIEWSTATE and other parameters required. ( values for the fields present in the asp.net form )

I am unable to construct the CURLOPT_POSTFIELDS correctly.

For instance, I am trying this out,

$postoptions1='__EVENTTARGET='.('ctl00$ContentPlaceHolder1$gRef').'&__EVENTARGUMENT='.('$2');
$postoptions2 =  '&__VIEWSTATE='.urlencode($viewState) ;
$otherparams = '&ctl00$ContentPlaceHolder1$ddlName=Abc';

And before using setopt for CURLOPT_POSTFIELDS, I am doing,

urlencode ($postoptions1.$postoptions2.$otherparams)

This does not work. The submit results are not shown, which means, the required parameter __VIEWSTATE was not found in my post request.

If I change the order of the parameters and place __VIEWSTATE as the first parameter, the results page is shown but the other parameter values are not honoured.

I think there is some problem with the way I am encoding the parameters.

Please tell me how to construct the parameters for the post request to a asp.net page.

Thanks.

–Edited–

Here is the complete code:
$resultsPerPage=’10’;
$url = “www.example.com”; // url changed

$curl_connection = curl_init($url);
function sendCurl($curl_connection,$url,$params,$isPost=false) {

//$post_string = $params;
$post_string = http_build_query($params);
//$post_string = build_query_string($params);
//$post_string = urlencode($params); 

echo 'After Encode'.$post_string;
   $cookie="/cookie.txt";


   //set options
    curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 300);
    curl_setopt($curl_connection, CURLOPT_USERAGENT, 
      "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
    curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl_connection, CURLOPT_HEADER, 0); // don't return headers 

    curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl_connection,CURLOPT_REFERER, $url);
    if($isPost) {
        curl_setopt ($curl_connection, CURLOPT_POST, true);
        //set data to be posted
        curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
        curl_setopt($curl_connection,CURLOPT_COOKIEJAR,$cookie);

    }
    else {
    curl_setopt($curl_connection,CURLOPT_COOKIEFILE,$cookie);
    }
   $response1 = curl_exec($curl_connection);
   if($response1 === false)
    {
        echo 'Curl error: ' . curl_error($curl_connection);
    }
    else
{
    echo 'Operation completed without any errors';
}
   return $response1;
}  **// First time, get request to asp.net page  

$response1 = sendCurl($curl_connection,$url,'',false);
$viewState=getVStateContent($response1);
$eventValidation =getEventValidationContent($response1);
$simpleParams = '&__VIEWSTATE='.$viewState.'&ctl00$ContentPlaceHolder1$ddlManuf=&ctl00$ContentPlaceHolder1$ddlCrossType=&ctl00$ContentPlaceHolder1$ddlPageSize='.$resultsPerPage.'&ctl00$ContentPlaceHolder1$btnSearch=Search&ctl00_ToolkitScriptManager1_HiddenField=&__EVENTTARGET=&__EVENTARGUMENT=';
// Second post - for submitting the search form
$response2= sendCurl($curl_connection,$url,$simpleParams,true);

—-**

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:48:45+00:00Added an answer on May 20, 2026 at 6:48 pm

    What you want is http_build_query, which will format an array as proper HTTP parameters.

    Edit: To clarify what this should probably look like:

    $params = array(
        '__EVENTTARGET' => 'ctl00$ContentPlaceHolder1$gRef',
        '__EVENTARGUMENT' => '$2',
        '__VIEWSTATE' => $viewState,
        'ctl00$ContentPlaceHolder1$ddlName' => 'Abc'
    );
    
    curl_setopt($curlHandler, CURLOPT_POSTFIELDS, http_build_query($params));
    

    Also, what’s ctl00$ContentPlaceHolder1$ddlName supposed to be?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.