views:

164

answers:

3

There is a webpage at this URL:

http://www.vankampen.com/Products/529Portfolios

This webpage opens with default option "With Sales Charge". There is a link "Without Sales Charge" on this webpage. When we click on this link then webpage displays options related with "Without Sales Charge".

I want to open the "http://www.vankampen.com/Products/529Portfolios" URL with "Without Sales Charge" option instead of default "With Sales Charge" option.

On mouse over of "Without Sales Charge" it shows following function being invoked: javascript:__doPostBack('ctl00$ctl00$ctl00$m_mainContent$m_secondaryContent$m_mainContent$list529Funds$ctrl1$withoutSalesCharge','')

Can someone suggest me if it is possible to open the webpage with "Without Sales Charge" option instead of "With Sales Charge" option?

Thanks,

A: 

I take it you don't control www.vankampen.com but want to "deep link" to a page with the correct settings applied?

If the only way you can get to that layout is through the form submission, then you'd need to attempt to do post to the server - however, ASP.NET will generally refuse a postback from a different site - the viewstates etc will fail validation.

If you do have access to the code of www.vankampen.com, then you could look at providing a mechanism to provide direct links to those pages, or all a get rather than a post.

Zhaph - Ben Duguid
I don't have the source code of www.vankampen.com
Then I don't think there's anything you can do about it - ASP.NET is designed to reject postbacks from different domains.
Zhaph - Ben Duguid
A: 

Make "With Sales Charge" and "Without Sales Charge" accessible through querystring.

Then u can simply do something like

With sales Charge

http://www.vankampen.com/Products/529Portfolios?settings=CS

or

Without sales Charge

http://www.vankampen.com/Products/529Portfolios?settings=NCS

nils_gate
I don't have the source code of www.vankampen.com, I am just using it in my program to get the data displayed by this page.That is why I asked if there is any way to open the desired page at first attempt without postback.
+1  A: 

I would say it depends on what exactly you are trying to do.

I'm afraid you cannot avoid a post back, unless they support some query string variable or have a way of setting a "preference" in a cookie or otherwise. That you'd have to figure out by yourself.

Otherwise, it's a standard capture/replay technique. You will have to mimic user actions in some form and fashion. Which means sending initial GET request to extract all form field and then creating a POST to simulate the post back.

Doing this inside a regular browser would be challenging, I suppose. I don't remember if javascript allows to set headers and all. I guess you could use MS active objects... However, if your goal is to extract data in some .net code, you can do it relatively easy.

There are plenty of samples on how to use HttpWebRequest or WebClient for screen scraping, including simulating logins and such. I would use HttpWebRequest. Send a GET request, get data, preserve cookies, extract form fields, create a POST request, recreate headers (including proper referrer), form proper post body, reassign cookies, and you should be set.

To see what needs to be sent, I suggest using a Fiddler (with IE). Run it, then browse to the page, click on a link. The Filder will show you all traffic and all necessary information on both the initial request and subsequential post back.

Ruslan