P
PJ6
I'm stuck on this and need someone with more ASP.Net knowledge than I to
weigh in...
I've been toying around with writing my own .Net AJAX framework and been
looking at associating GUID's with delegates as my main approach:
--(from within a web control)
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
btn.ID = Me.ClientID & "_btn"
Server.AddClientSideEventAction(Me.Page, btn, "OnClick", AddressOf
OnClick)
MyBase.OnLoad(e)
End Sub
AddClientSideEventAction simply adds a new GUID and delegate to a dictionary
and adds this to the control render:
<button id="ctl02_btn"
OnClick="AjaxRequest('9713e7bc-df1c-46fa-8ee0-afd139f5d693');">BUTTON
1</button>
What happens is this server-side object can now have a method fired from
outside its original page context, an AJAX call. From the containing page we
can handle an event invoked from within this method and call another control
enabled to handle changing states both server and client-side... for
instance, a WebControl that encapsulates and serves the properties of a
TextArea:
Public Property Text() As String
Get
Return tb.InnerText
End Get
Set(ByVal value As String)
If Not value Is Nothing Then value =
value.Replace(Environment.NewLine, "\r")
AsyncEvent.SetClientProperty(Me.Page, tb.ID, "innerHTML", value)
tb.InnerText = value
End Set
End Property
AsyncEvent.SetClientProperty sends JavaScript back to the client to update
the control, if we are executing from within an AJAX context.
Unorthodox? Bad practice? This is my reasoning for exploring this approach -
1. ViewState is eliminated
2. Simple use (the code looks and acts the same as regular postback)
3. Simple, efficient communication of events between enabled controls
I have a reasonably articulated proof-of-concept working and I really like
how it works.
But there's one problem - delegate accumulation. Periodically I need to
flush the delegate dictionary to remove items associated with sessions that
have expired. Unfortunately Session.Abandon() will *not* put the server side
objects or session into a state where calling delegates / accessing the
controls will fail, or otherwise notify me that the session has terminated -
possibly because I've got pointers to them. If I can't find a good way to
deal with this, than I'll have to toss this idea out the window.
Paul
weigh in...
I've been toying around with writing my own .Net AJAX framework and been
looking at associating GUID's with delegates as my main approach:
--(from within a web control)
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
btn.ID = Me.ClientID & "_btn"
Server.AddClientSideEventAction(Me.Page, btn, "OnClick", AddressOf
OnClick)
MyBase.OnLoad(e)
End Sub
AddClientSideEventAction simply adds a new GUID and delegate to a dictionary
and adds this to the control render:
<button id="ctl02_btn"
OnClick="AjaxRequest('9713e7bc-df1c-46fa-8ee0-afd139f5d693');">BUTTON
1</button>
What happens is this server-side object can now have a method fired from
outside its original page context, an AJAX call. From the containing page we
can handle an event invoked from within this method and call another control
enabled to handle changing states both server and client-side... for
instance, a WebControl that encapsulates and serves the properties of a
TextArea:
Public Property Text() As String
Get
Return tb.InnerText
End Get
Set(ByVal value As String)
If Not value Is Nothing Then value =
value.Replace(Environment.NewLine, "\r")
AsyncEvent.SetClientProperty(Me.Page, tb.ID, "innerHTML", value)
tb.InnerText = value
End Set
End Property
AsyncEvent.SetClientProperty sends JavaScript back to the client to update
the control, if we are executing from within an AJAX context.
Unorthodox? Bad practice? This is my reasoning for exploring this approach -
1. ViewState is eliminated
2. Simple use (the code looks and acts the same as regular postback)
3. Simple, efficient communication of events between enabled controls
I have a reasonably articulated proof-of-concept working and I really like
how it works.
But there's one problem - delegate accumulation. Periodically I need to
flush the delegate dictionary to remove items associated with sessions that
have expired. Unfortunately Session.Abandon() will *not* put the server side
objects or session into a state where calling delegates / accessing the
controls will fail, or otherwise notify me that the session has terminated -
possibly because I've got pointers to them. If I can't find a good way to
deal with this, than I'll have to toss this idea out the window.
Paul