Home All Groups Group Topic Archive Search About

Posting using httpwebrequest

Author
16 Feb 2005 7:49 AM
Pazza
Hi,

Should the form submit button click event handler fire when posting to a
aspx page using httpwebrequest.

In my tests the load event fires when POSTing back but not the button click
event handler.
I first issue a GET, extract __VIEWSTATE and then POST back __VIEWSTATE and
the form values.

I am hoping to use this technique for a screen scraper but if I can't get
the submit
buttons click event handler to fire its no use.

Thanks,
Pazza
Author
16 Feb 2005 11:13 AM
Jakob Christensen
Are you posting any value for the button when posting the form values?  My
guess is you would have to post something like "Button1=Button".  Otherwise
the asp.net framework has no way of telling that the button has been
"clicked".

HTH, Jakob.


Show quoteHide quote
"Pazza" wrote:

> Hi,
>
> Should the form submit button click event handler fire when posting to a
> aspx page using httpwebrequest.
>
> In my tests the load event fires when POSTing back but not the button click
> event handler.
> I first issue a GET, extract __VIEWSTATE and then POST back __VIEWSTATE and
> the form values.
>
> I am hoping to use this technique for a screen scraper but if I can't get
> the submit
> buttons click event handler to fire its no use.
>
> Thanks,
> Pazza
>
>
Are all your drivers up to date? click for free checkup

Author
16 Feb 2005 12:05 PM
Pazza
Yep, I'm posting Button1=Clicked, see below ...

viewState = SrcViewState 'a readonly property that gets __VIEWSTATE
postData.Append("__VIEWSTATE=")
postData.Append(viewState)
postData.Append("&Button1=Clicked")
Dim encodedPostData As String
encodedPostData = HttpUtility.UrlEncode(postData.ToString)
hrqURL = HttpWebRequest.Create(m_strURL)
hrqURL.ContentType = "application/x-www-form-urlencoded"
hrqURL.ContentLength = encodedPostData.Length
hrqURL.Method = "POST"
Dim cookies As New CookieContainer
hrqURL.CookieContainer = cookies
Dim requestWriter As New StreamWriter(hrqURL.GetRequestStream())
requestWriter.Write(EncodedPostData)
requestWriter.Close()
hrspURL = hrqURL.GetResponse()

Show quoteHide quote
"Jakob Christensen" wrote:

> Are you posting any value for the button when posting the form values?  My
> guess is you would have to post something like "Button1=Button".  Otherwise
> the asp.net framework has no way of telling that the button has been
> "clicked".
>
> HTH, Jakob.
>
>
> "Pazza" wrote:
>
> > Hi,
> >
> > Should the form submit button click event handler fire when posting to a
> > aspx page using httpwebrequest.
> >
> > In my tests the load event fires when POSTing back but not the button click
> > event handler.
> > I first issue a GET, extract __VIEWSTATE and then POST back __VIEWSTATE and
> > the form values.
> >
> > I am hoping to use this technique for a screen scraper but if I can't get
> > the submit
> > buttons click event handler to fire its no use.
> >
> > Thanks,
> > Pazza
> >
> >
Author
16 Feb 2005 2:51 PM
Jakob Christensen
I can not get it working when posting __VIEWSTATE (It results in an internal
server error).  My suggestion is that you don't try to fire the Click event
of the button.  Instead change your code to something like (assuming you
control the server code):

if (Request["Button1"] != null)
{
  // do some work
}

Or perhaps a web service is the way to go?

Regards, Jakob.


Show quoteHide quote
"Pazza" wrote:

> Yep, I'm posting Button1=Clicked, see below ...
>
> viewState = SrcViewState 'a readonly property that gets __VIEWSTATE
> postData.Append("__VIEWSTATE=")
> postData.Append(viewState)
> postData.Append("&Button1=Clicked")
> Dim encodedPostData As String
> encodedPostData = HttpUtility.UrlEncode(postData.ToString)
> hrqURL = HttpWebRequest.Create(m_strURL)
> hrqURL.ContentType = "application/x-www-form-urlencoded"
> hrqURL.ContentLength = encodedPostData.Length
> hrqURL.Method = "POST"
> Dim cookies As New CookieContainer
> hrqURL.CookieContainer = cookies
> Dim requestWriter As New StreamWriter(hrqURL.GetRequestStream())
> requestWriter.Write(EncodedPostData)
> requestWriter.Close()
> hrspURL = hrqURL.GetResponse()
>
> "Jakob Christensen" wrote:
>
> > Are you posting any value for the button when posting the form values?  My
> > guess is you would have to post something like "Button1=Button".  Otherwise
> > the asp.net framework has no way of telling that the button has been
> > "clicked".
> >
> > HTH, Jakob.
> >
> >
> > "Pazza" wrote:
> >
> > > Hi,
> > >
> > > Should the form submit button click event handler fire when posting to a
> > > aspx page using httpwebrequest.
> > >
> > > In my tests the load event fires when POSTing back but not the button click
> > > event handler.
> > > I first issue a GET, extract __VIEWSTATE and then POST back __VIEWSTATE and
> > > the form values.
> > >
> > > I am hoping to use this technique for a screen scraper but if I can't get
> > > the submit
> > > buttons click event handler to fire its no use.
> > >
> > > Thanks,
> > > Pazza
> > >
> > >
Author
17 Feb 2005 7:09 AM
Pazza
Thanks again Jakob,

Scraping is my only option as I have no control over the source application
and it doesn't provide any webservice(s).

I would still like to known if the buttons click event should fire, is there
anyone out there you can help please ?


Show quoteHide quote
"Jakob Christensen" wrote:

> I can not get it working when posting __VIEWSTATE (It results in an internal
> server error).  My suggestion is that you don't try to fire the Click event
> of the button.  Instead change your code to something like (assuming you
> control the server code):
>
> if (Request["Button1"] != null)
> {
>   // do some work
> }
>
> Or perhaps a web service is the way to go?
>
> Regards, Jakob.
>
>
> "Pazza" wrote:
>
> > Yep, I'm posting Button1=Clicked, see below ...
> >
> > viewState = SrcViewState 'a readonly property that gets __VIEWSTATE
> > postData.Append("__VIEWSTATE=")
> > postData.Append(viewState)
> > postData.Append("&Button1=Clicked")
> > Dim encodedPostData As String
> > encodedPostData = HttpUtility.UrlEncode(postData.ToString)
> > hrqURL = HttpWebRequest.Create(m_strURL)
> > hrqURL.ContentType = "application/x-www-form-urlencoded"
> > hrqURL.ContentLength = encodedPostData.Length
> > hrqURL.Method = "POST"
> > Dim cookies As New CookieContainer
> > hrqURL.CookieContainer = cookies
> > Dim requestWriter As New StreamWriter(hrqURL.GetRequestStream())
> > requestWriter.Write(EncodedPostData)
> > requestWriter.Close()
> > hrspURL = hrqURL.GetResponse()
> >
> > "Jakob Christensen" wrote:
> >
> > > Are you posting any value for the button when posting the form values?  My
> > > guess is you would have to post something like "Button1=Button".  Otherwise
> > > the asp.net framework has no way of telling that the button has been
> > > "clicked".
> > >
> > > HTH, Jakob.
> > >
> > >
> > > "Pazza" wrote:
> > >
> > > > Hi,
> > > >
> > > > Should the form submit button click event handler fire when posting to a
> > > > aspx page using httpwebrequest.
> > > >
> > > > In my tests the load event fires when POSTing back but not the button click
> > > > event handler.
> > > > I first issue a GET, extract __VIEWSTATE and then POST back __VIEWSTATE and
> > > > the form values.
> > > >
> > > > I am hoping to use this technique for a screen scraper but if I can't get
> > > > the submit
> > > > buttons click event handler to fire its no use.
> > > >
> > > > Thanks,
> > > > Pazza
> > > >
> > > >

Bookmark and Share