473,608 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3107
"Rudy" <rr******@poczt a.onet.pl> wrote in message
news:8a******** *************** ***@posting.goo gle.com...
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 (__eventargumen t,__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******@poczt a.onet.pl> a écrit dans le message de
news:8a******** *************** ***@posting.goo gle.com...
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******@poczt a.onet.pl> wrote in message
news:8a******** *************** ***@posting.goo gle.com...
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******@poczt a.onet.pl> wrote in message
news:8a******** *************** ***@posting.goo gle.com...
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******@poczt a.onet.pl> wrote in message
news:8a******** *************** ***@posting.goo gle.com...
| 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 (__eventargumen t,__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("te xtbox1") say but no as textbox1.text i'd appreciate
it if you get an answer then e-mail me at jo********@hotm ail.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******@poczt a.onet.pl> wrote in message
news:8a******** *************** ***@posting.goo gle.com...
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..al though 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="javascrip t:__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)...y ou can use
Page.GetPostBac kClientEvent(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********@hot mail.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("te xtbox1") say but no as textbox1.text i'd appreciate
it if you get an answer then e-mail me at jo********@hotm ail.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******@poczt a.onet.pl> wrote in message
news:8a******** *************** ***@posting.goo gle.com...
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

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

Similar topics

1
2582
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 button that initiates the submit. during submit, 2 events *should fire, 1 from the textbox and 1 from the image button. The image button event always fire but the textbox textchange event does not. Anyone has any ideas? Notes: During postback, I...
7
5719
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 the user controls to do a postback but not the rest of the page. Is this possible? it seems like it should be. If it is, please explain how I can do it. Thanks. -- moondaddy@nospam.com
4
1559
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 postback or is it random?
6
2915
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 set up my pages for access directly via localhost (not using the WebMatrix server). My login page loads, and any validation controls on the page work fine, so I know it's recognizing the ASP.Net code there, however, when I try to log on, the...
1
1170
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 added to the base page's control collection during the Init event of the base page. I expose this form object to any given derived page through a public property. And this works, more or less; from the derived page, I can instantiate textboxes,...
7
1796
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 is returned blank. I have a JavaScript routine displaying a session countdown in the browser statusbar that continues counting without resetting as it normally would after a postback. An error icon is displayed in the browser statusbar after the...
3
8697
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: System.Convert.FromBase64String(String s) +0
9
2736
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 affecting this. But I'm stuck. My handler is in C# code and the code looks right. But absolutely nothing happens when I click the button. protected void Button1_Click(object sender, EventArgs e)
3
1046
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
8063
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8148
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8338
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6013
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5475
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3962
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4024
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1594
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.