473,324 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

How does asp.net page know it's postback?

Hi,
I need to make a request to a asp.net page using HttpWebRequest class
and I need to trick this page into thinking it's a postback and a
button was clicked. But the page doesn't handle the click event,
despite I'm using "POST" method and sending all the form fields
(except of __VIEWSTATE, may this be the reason ?).

So the question is: on what basis does asp.net page set the ispostback
property to true or false?

Regards,
--
Rudy
Nov 19 '05 #1
12 3086
"Rudy" <rr******@poczta.onet.pl> wrote in message
news:8a**************************@posting.google.c om...
Hi,
I need to make a request to a asp.net page using HttpWebRequest class
and I need to trick this page into thinking it's a postback and a
button was clicked. But the page doesn't handle the click event,
despite I'm using "POST" method and sending all the form fields
(except of __VIEWSTATE, may this be the reason ?).

So the question is: on what basis does asp.net page set the ispostback
property to true or false?


I don't know, but I do know that you need to send ViewState. You need to
pretend to be a browser and do what a browser would have done.

John Saunders
Nov 19 '05 #2
First, check that the postback property is correct...
IMO it's rather that it uses hidden fields that you need to fill to be able
to pretend to have clicked a button (__eventargument,__eventtarget)

It would likely cleaner/easier to have the owner of this page exposing a
programmatic only interface (your code could break after a change in the
UI). It's likely you'll have also some problems with the viewstate.

Patrice

--

"Rudy" <rr******@poczta.onet.pl> a écrit dans le message de
news:8a**************************@posting.google.c om...
Hi,
I need to make a request to a asp.net page using HttpWebRequest class
and I need to trick this page into thinking it's a postback and a
button was clicked. But the page doesn't handle the click event,
despite I'm using "POST" method and sending all the form fields
(except of __VIEWSTATE, may this be the reason ?).

So the question is: on what basis does asp.net page set the ispostback
property to true or false?

Regards,
--
Rudy

Nov 19 '05 #3
based on two hidden element __eventtargent and __eventargument.
--
-Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com

"Rudy" <rr******@poczta.onet.pl> wrote in message
news:8a**************************@posting.google.c om...
Hi,
I need to make a request to a asp.net page using HttpWebRequest class
and I need to trick this page into thinking it's a postback and a
button was clicked. But the page doesn't handle the click event,
despite I'm using "POST" method and sending all the form fields
(except of __VIEWSTATE, may this be the reason ?).

So the question is: on what basis does asp.net page set the ispostback
property to true or false?

Regards,
--
Rudy

Nov 19 '05 #4
Rather than trying to break the object model, try working with it.

What I mean by that is, you don't need to make the page think it's a
PostBack when it isn't, and you don't need to make the page think a button
has been clicked when it hasn't. If you look at your requirements, what you
want is:

1. Make a Request to an ASP.Net page.
2. Make the ASP.Net page execute a Method when it is Requested in the way
you want to request it.

The fact that you have a button's OnClick event handler executing the same
code makes no difference whatsoever. Just remove the code from the event
handler and put it into a Method. Have the event handler call the Method.
Now, you can call the Method without an imaginary Click event.

All you need now is the logic that determines how and when the Method should
be fired.

I'm not sure why you're using a POST to the page, as you may think you need
it in order to set the "IsPostBack" property to true. However, assuming that
you need to send some data to the page, you can also send data via the form
fields in the page doing the POSTing, or via QueryString. The data can
include data that tells the page being called what it needs to do.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Rudy" <rr******@poczta.onet.pl> wrote in message
news:8a**************************@posting.google.c om...
Hi,
I need to make a request to a asp.net page using HttpWebRequest class
and I need to trick this page into thinking it's a postback and a
button was clicked. But the page doesn't handle the click event,
despite I'm using "POST" method and sending all the form fields
(except of __VIEWSTATE, may this be the reason ?).

So the question is: on what basis does asp.net page set the ispostback
property to true or false?

Regards,
--
Rudy

Nov 19 '05 #5
asp.net checks for a valid viewstate stored in __ViewState. if it exists,
then its a postback. if you need to postback to an aspx. page from
webclient, you should do a "GET" first, parsre the html for the hidden field
__ViewState, then post this value back, along with the name of the button
you want to emulate a click, and any field data you want to post.

-- bruce (sqlwork.com)
"Rudy" <rr******@poczta.onet.pl> wrote in message
news:8a**************************@posting.google.c om...
| Hi,
| I need to make a request to a asp.net page using HttpWebRequest class
| and I need to trick this page into thinking it's a postback and a
| button was clicked. But the page doesn't handle the click event,
| despite I'm using "POST" method and sending all the form fields
| (except of __VIEWSTATE, may this be the reason ?).
|
| So the question is: on what basis does asp.net page set the ispostback
| property to true or false?
|
| Regards,
| --
| Rudy
Nov 19 '05 #6
On 2005-01-04, Patrice <no****@nowhere.com> wrote:
First, check that the postback property is correct...
IMO it's rather that it uses hidden fields that you need to fill to be able
to pretend to have clicked a button (__eventargument,__eventtarget)
ASP.NET uses __eventargument and __eventtarget only when the postback is
caused by something other than <input type="submit". I checked, that the
only hidden field sent after clicking the button, was __VIEWSTATE.

It would likely cleaner/easier to have the owner of this page exposing a
programmatic only interface (your code could break after a change in the
UI). It's likely you'll have also some problems with the viewstate.

Patrice

--
Rudy
Nov 19 '05 #7
On 2005-01-04, bruce barker <no***********@safeco.com> wrote:
asp.net checks for a valid viewstate stored in __ViewState. if it exists,
then its a postback. if you need to postback to an aspx. page from
webclient, you should do a "GET" first, parsre the html for the hidden field
__ViewState, then post this value back, along with the name of the button
you want to emulate a click, and any field data you want to post.

Yeah, I was afraid, I would have to do that :) Fortunately I have access
to the code executed during this postback and I can put it somewhere
else. Anyway, thanks for all the replies, everyone.
--
Rudy
Nov 19 '05 #8
Hi,

Wish i had the answer....I have the same problem - i can pick my data up
usiing requst.form("textbox1") say but no as textbox1.text i'd appreciate
it if you get an answer then e-mail me at jo********@hotmail.com
Also if you know how to activate a button click via posting data i'd
appreciate knowing how to do that! Thanks a lot!

"Rudy" <rr******@poczta.onet.pl> wrote in message
news:8a**************************@posting.google.c om...
Hi,
I need to make a request to a asp.net page using HttpWebRequest class
and I need to trick this page into thinking it's a postback and a
button was clicked. But the page doesn't handle the click event,
despite I'm using "POST" method and sending all the form fields
(except of __VIEWSTATE, may this be the reason ?).

So the question is: on what basis does asp.net page set the ispostback
property to true or false?

Regards,
--
Rudy

Nov 19 '05 #9
I don't have the original thread for this...but:

I believe ASP.Net can detect postback one of two ways...either via the
presence of __EventTarget or __ViewState..although the lalter is more
complicated than just simple existance check..

To simulate a button click in Javascript, use the __doPostBack function

<asp:button id="x" runat="server" />
<a href="javascript:__doPostBack('x', '');">hahah I'm sooo clever!</a>

If you only have Buttons and no LinkButtons or other controls which require
__doPostBack, you'll have to trick the page into generating the Javascript
for you (button's don't need javascript)...you can use
Page.GetPostBackClientEvent(x, ""); where x is the id of the button
control..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"John Blair" <jo********@hotmail.com> wrote in message
news:hn*************@newsfe4-gui.ntli.net...
Hi,

Wish i had the answer....I have the same problem - i can pick my data up
usiing requst.form("textbox1") say but no as textbox1.text i'd appreciate
it if you get an answer then e-mail me at jo********@hotmail.com
Also if you know how to activate a button click via posting data i'd
appreciate knowing how to do that! Thanks a lot!

"Rudy" <rr******@poczta.onet.pl> wrote in message
news:8a**************************@posting.google.c om...
Hi,
I need to make a request to a asp.net page using HttpWebRequest class
and I need to trick this page into thinking it's a postback and a
button was clicked. But the page doesn't handle the click event,
despite I'm using "POST" method and sending all the form fields
(except of __VIEWSTATE, may this be the reason ?).

So the question is: on what basis does asp.net page set the ispostback
property to true or false?

Regards,
--
Rudy


Nov 19 '05 #10
I don't know how to make the page thinks it's a postback, but as an
alternative could you call your page with a parameter then call the button
click from the page load, so:

http://www.asdsdfa.com/test.aspx?pb=true

then in the page load

if pb="true" then ButtonClickEvent(nothing,nothing)
"John Blair" <jo********@hotmail.com> wrote in message
news:hn*************@newsfe4-gui.ntli.net...
Hi,

Wish i had the answer....I have the same problem - i can pick my data up
usiing requst.form("textbox1") say but no as textbox1.text i'd appreciate
it if you get an answer then e-mail me at jo********@hotmail.com
Also if you know how to activate a button click via posting data i'd
appreciate knowing how to do that! Thanks a lot!

"Rudy" <rr******@poczta.onet.pl> wrote in message
news:8a**************************@posting.google.c om...
Hi,
I need to make a request to a asp.net page using HttpWebRequest class
and I need to trick this page into thinking it's a postback and a
button was clicked. But the page doesn't handle the click event,
despite I'm using "POST" method and sending all the form fields
(except of __VIEWSTATE, may this be the reason ?).

So the question is: on what basis does asp.net page set the ispostback
property to true or false?

Regards,
--
Rudy


Nov 19 '05 #11
Yup,

basically detecting postback is at code level as follows:

<Browsable(False),
DesignerSerializationVisibility(DesignerSerializat ionVisibility.Hidden)> _
Public ReadOnly Property IsPostBack As Boolean
Get
If (Me._requestValueCollection Is Nothing) Then
Return False
End If
Return Not Me._fPageLayoutChanged
End Get
End Property

The first one comes if there is a request value collection (form post
collection), if that's missing then it's not postback straight away. The
other one is detected if data coming from ViewState contains same hash code
as on previous request (first value in Page's ViewState is this hash code,
page's type hash code), that is if the hash code doesn't match then it is
not a postback (though there would be exception about invalid view state
before that :-) )

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:el**************@TK2MSFTNGP12.phx.gbl...
I don't have the original thread for this...but:

I believe ASP.Net can detect postback one of two ways...either via the
presence of __EventTarget or __ViewState..although the lalter is more
complicated than just simple existance check..

To simulate a button click in Javascript, use the __doPostBack function

<asp:button id="x" runat="server" />
<a href="javascript:__doPostBack('x', '');">hahah I'm sooo clever!</a>

If you only have Buttons and no LinkButtons or other controls which
require
__doPostBack, you'll have to trick the page into generating the Javascript
for you (button's don't need javascript)...you can use
Page.GetPostBackClientEvent(x, ""); where x is the id of the button
control..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"John Blair" <jo********@hotmail.com> wrote in message
news:hn*************@newsfe4-gui.ntli.net...
Hi,

Wish i had the answer....I have the same problem - i can pick my data up
usiing requst.form("textbox1") say but no as textbox1.text i'd
appreciate
it if you get an answer then e-mail me at jo********@hotmail.com
Also if you know how to activate a button click via posting data i'd
appreciate knowing how to do that! Thanks a lot!

"Rudy" <rr******@poczta.onet.pl> wrote in message
news:8a**************************@posting.google.c om...
> Hi,
> I need to make a request to a asp.net page using HttpWebRequest class
> and I need to trick this page into thinking it's a postback and a
> button was clicked. But the page doesn't handle the click event,
> despite I'm using "POST" method and sending all the form fields
> (except of __VIEWSTATE, may this be the reason ?).
>
> So the question is: on what basis does asp.net page set the ispostback
> property to true or false?
>
> Regards,
> --
> Rudy



Nov 19 '05 #12

Thanks for the feedback - but i want to cause the event to activate as
part of the POST i.e. without changing the target aspx page (as i don't
control the source code there). I'm beginning to think this is not
possible as none of the examples ive come across using HTTPWebrequest
tackle this. Thanks again.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Duwayne | last post by:
I am having a lot of trouble with an ascx page that has a textbox that *should fire a textchange event when the text changes. The main aspx page dynamically loads the ascx page and has a image...
7
by: moondaddy | last post by:
I'm building a page in vb.net with several user controls on it. I'm using user controls instead of a frames page since I've seen this recommended many times in this user group. I want just one of...
4
by: ryu | last post by:
I have a aspx page that loads a ascx file ie Web Control. My question is when does the postback of the web control occur? Is it when it is called via LoadControl? Or after the calling page's...
6
by: Brian Miller | last post by:
I've been constructing an ASP.Net application using the 1.1 framework, and have been using Web Matrix for development purposes. Now that my application is near completion, I wanted to see if I can...
1
by: seven | last post by:
I'm playing with page inheritence but I am currently stumped by postback, on a page derived from a base class. In my base page/class I have defined an HTMLForm object. It is instantiated and...
7
by: morrisdn13 | last post by:
I have encountered a very strange problem that makes it look like the page is not recreated in entirety after a postback when I turn on smartnavigation. If I click on a server control, the page...
3
by: Nathan Sokalski | last post by:
I am recieving the following error on the second postback of a page I have written: The state information is invalid for this page and might be corrupted Stack Trace: ...
9
by: Jonathan Wood | last post by:
Does anyone know of any reason a button on a master page would have no effect? I have a complex HTML page that I'm converting to ASP.NET, and acknowledge I could have something odd that is...
3
by: lander | last post by:
How does asp.net know to set the Page.IsPostBack property exactly??? Would somebody detail this, thanks very much...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.