Thanks Gregory
Is there no way to publically reference a particular control so that
its properties can be set from anywhere, on any event?
For instance if I create a class and create a public shared variable,
say:
Public class myclass
public shared mynumber as integer = 0
end class
when ever I need to set this variable (or refer to it)
All I have to do in an aspx code behind page is - for example:
imports myclass
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
mynumber = 1
End Sub
I can then set or use this variable from anywhere within the
codebehind.
I suppose what I am trying to acheive is to use a similar process but
with a publically declared control.
Here is what is happening, to understand why this is so complex compared
to windows forms and libraries, etc.
1. User changes drop down
2. User's browser has a javascript routine (emitted by your page) that
sets up a postback
3. Request is created as a POST with name of handler in it
4. IIS sees an ASPX request
5. IIS redirects to the ASP.NET engine (worker process)
6. The worker process finds the page to run (which could be compiled in
the bin or compiled on the fly, etc.)
7. The worker process process the page through a set of events
8. The response is sent back to the user
The issue here is most of the work is being done through event handlers
on the page class, so handling setting of multiple properties through a
single class would mean one of two things:
1. The page sends itself to a secondary class. Not impossible, but too
much chance of messing things up as the changer and the changee are the
same object.
2. The asp.net process is altered.
The second option can be done through Http modules, etc., but depending
on how deep you go, you may end up having to rewrite more of the ASP.NET
engine than you would like. This adds a lot of complexity to your
application simply to avoid some typing.
One potential option to achieve what you desire is to put all of the
form elements into a user class and expose the control as a Property
there. The issue, or perhaps potential issue, would come when you pass
the user control to the library that sets things on and off. I see two
choices (brainstorming again):
1. Control passed by value to ensure items set in it are set on the
page. This has overhead, but may have a higher degree of success.
2. Control rebound to the page. Not sure how difficult this would be.
There is one other possible choice and that is to completely build the
page on the fly. The issue with this route is there is a lot of room to
really screw up your page.
Oh, and one other option. Change to the MVC paradigm, where writing out
the entire page is not as dangerous. ;-)
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
Twitter: @gbworld
Blog:
http://gregorybeamer.spaces.live.com
*******************************************
| Think outside the box! |
*******************************************