CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

MS SQL 2008 on ASP.NET Hosting



Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 10/10/2003 2:37:01 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 5 Views: 79 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
6 Items, 1 Pages 1 |< << Go >> >|
Zapper888
Asp.Net User
How can I detect the cause of postback from within my server control?10/10/2003 2:37:01 PM

0/0

Hello,

I have a server control that does not cause postback, raise click events, etc...

When the form is posted (i.e. Page.IsPostBack = True), my server control needs to dynamically determine which control caused the postback.

If the user were forced to click on a button, this would be easy enough...but the postback could be fired by the user pressing Enter within a textbox, pressing a button, or interacting with any other control that causes postback.

Thanks in advance for any advice!
Andy Smith
Asp.Net User
Re: How can I detect the cause of postback from within my server control?10/10/2003 4:51:52 PM

0/0

Well, the bottom line is that Page does not expose an easy "ControlThatCausedPostBack" property. In fact, it's not really possible for the page to know for sure, because it's possible for somebody to write a control that dynamicly tells the page "Control Foo caused the postback".

At any rate, if we knew what you were trying to do, we might be able to help you accomplish the goal in another way.
Zapper888
Asp.Net User
Re: How can I detect the cause of postback from within my server control?10/10/2003 5:41:15 PM

0/0

It doesn't have to be an easy method...and if a control tells the page that "Control Foo caused postback", I would accept Foo as the control that caused postback.

Basically, I have created a server control that needs to adapt to general form senarios that include having a few emulated forms (i.e. more than one form on a page: A login form, a search form, and an inquiry form.)

Each form has a button or two, but postback could be caused by a button or a user pressing Enter in a text field. In any case, my control needs to know which emulated form caused postback so it can take the appropriate action.

Some pages will have a few emulated forms like this, others won't...but the control needs to adapt. Right now it adapts perfectly...but doesn't know which control caused postback (only that postback occured.)
Zapper888
Asp.Net User
Re: How can I detect the cause of postback from within my server control?10/10/2003 6:12:51 PM

0/0

To clarify...when I say "emulated forms" I mean that it looks like there are several forms on the page (when in fact, there is only one <form runat=server></form>) The emulated forms are any related group of fields and a button or two. But all of these emulated forms need to be accessible from the server-side simultaneously (i.e. no hiding areas, disabling, etc.)

So, in the upper right of the page is a UserID & Password field with a Login button. Slightly lower on the left side of the page is a search field and a search button. In the center of the page is an inquiry form.

Other pages may have the search and login areas, but not the inquiry form...and I don't want to hard code the names or IDs of the buttons, because these may change at any time.
Andy Smith
Asp.Net User
Re: How can I detect the cause of postback from within my server control?10/10/2003 6:57:23 PM

0/0

If you have access to deriving from the Page class, then you can override
protected virtual void RaisePostBackEvent(IPostBackEventHandler sourceControl, string eventArgument);
in order to know which control will get their IPOstBackEventHandler.RaisePostBackEvent method called. This happens directly before the event is raised.

If you can't do that, you'll have to kinda poke at the form name/value collection.

If the control used __doPostBack to postback, then __EVENTTARGET will have the UniqueID of the cause of the event.
Otherwise, you'll have to cycle the names in the collections, call Page.FindControl on those names, and see if any implement IPostBackEventHandler. That would indicate a control using normal form submit.

The problem with snooping the request variables is that these things aren't guarenteed to stay the same across versions of the framework. They may change the mechanism in the future.

And now we get to the "Enter pressed" issue. Here's the deal with that... When the user presses enter while in, say, a textbox... most browsers cause a submit. With some page configurations, the browser will just kinda choose a button which it decides will the button "clicked". Sometimes it doesn't, and just posts the data without adding a "target" button. In the case of it adding a target button, the above ways of determining the button will work. However, if the browser decides that no button will be the target, then as far as asp.net is concerned, NO control caused the postback, and no IPostBackEventHandler.RaisePostBackEvent will be invoked. In this case, there is no way to know which textbox the user was in at the time or the intent of the user.

This is the reason I created my DefaultButtons control. To make sure that some button, and in fact the "correct" one, will be considered the postback button.
Zapper888
Asp.Net User
Re: How can I detect the cause of postback from within my server control?10/10/2003 8:13:45 PM

0/0

Thanks for the insight...very helpful.
6 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Pro C# 2005 and the .NET 2.0 Platform: Public Beta Edition Authors: Andrew W. Troelsen, Pages: 982, Published: 2005
Pro ASP.NET Web Forms Techniques Authors: Alex Homer, Pages: 580, Published: 2003
Pro C# with .NET 3.0: exploring the .NET universe using curly brackets Authors: Andrew Troelsen, Pages: 1186, Published: 2007

Web:
Preventing Duplicate Record Insertion on Page Refresh or Postback ... Jeremy Schell provides a free FormValidator server control, and shows how ... at both the class level and at within my form submit event handler - no joy. ...
How do I stop a full page postback originating from a custom ... Everything works except the button within the server control, .... Detect the Ajax postback using the IsInAsyncPostBack property of the ...
ng.asp-net-forum.windows_hosting-hosting_open_forum/71 - fix error ... IsPostBack and ViewState not initialized in Composite Control, 1, 22, 10/11/2003 1:47:32 PM. How can I detect the cause of postback from within my server ...
Force Postback on FileUpload control - ASP.NET Mar 4, 2008 ... I want to write code on postback to automatically write the file to the server, so I would like to cause a postback event when it has a ...
TheMSsForum.com >> Asp >> Postback question - The Microsoft ... The client (any XYZ) should be able to post his XML file into my server and my ... Unfortunately, the action of clickin the link causes a postback which in ...
15 Seconds : Creating a Server Control for JavaScript Testing NET postback and viewstate model and how to have the server control emit client- side .... NET sites is that this control causes the page to post to itself ...
CrossPagePostback in ASP.NET 2.0 « Kedarnadhsharma’s Weblog You choose the button controls that can cause postback and set their PostBackUrl property.Notice that in this context a button control is any server control ...
Tutto .NET: ImageButton Control nested in a GridView Control ... Dec 29, 2006 ... For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally ...
Detect which ImageButton caused PostBack - .NET ASP If you can be sure the control that caused the postback is a button, From within your Page_Load event you can look for the names of the ...
ViewState :: DotNetJohn The hidden field is a postback control and when the encoded string is processed by the web server ASP.NET decodes the string at page initialisation and ...




Search This Site:










viewstate and custom control

custom treeview control & view state

javascript in custom server controls

isp with support of windows media server

how to mimic a control i made in vb6

rendering design-time content on a web usercontrol

expandableobjectconverter

problem with adding a namespace

saving state information between server requests

access databases and medium trust

writting flash html

why webcontrols do not expose javascript events?

overwriting a listbutton's "href='javascript:__dopostback..."

how to detect causesvalidation on postback

.net 2.0 : smart tags and readonly collection property

controls and templates

windows server 2003 sp1

mps versioning clarification

mass asp.net hosting

rendering style with htmltextwriter

design time support for composite controls

re: user control not displaying background

smartnavigation and javascript

stupid question, array to dropdown editor style in property browser?

accessing user controls from the code-behind

how do i raise an event?

web control library

how to get response object in the server control?

how to add an eventhandler programmatically?

composite control question...

  Privacy | Contact Us
All Times Are GMT