473,386 Members | 1,823 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,386 software developers and data experts.

Guidelines for overloading Render method

sk
Hi,
I'm trying to override the Render method of my Page class. Are there any
standard guidelines for this?

Thanks.
Shardul
Nov 19 '05 #1
5 1748

I don't know what about the guidlines but what I know is what overriding
Render method is a little bit difficult thing, because you should render
hidden fields, scripts, viewstate and and so forth, and so on.

This code I've found in google and it seems to me that this way ASP.NET Page
do it originally:

internal void OnFormRender(HtmlTextWriter writer, string formUniqueID)
{
if (_fOnFormRenderCalled)
{
throw new
HttpException(HttpRuntime.FormatResourceString("Mu ltiple_forms_not_allowed"));
}
_fOnFormRenderCalled = true;
_inOnFormRender = true;
RenderHiddenFields(writer);
if (_viewStateToPersist != null)
{
if (_formatter == null)
{
CreateLosFormatter();
}
writer.WriteLine();
writer.Write("<input type=\"hidden\" name=\"");
writer.Write("__VIEWSTATE");
writer.Write("\" value=\"");
_formatter.Serialize(writer, _viewStateToPersist);
writer.WriteLine("\" />");
}
else
{
writer.WriteLine();
writer.Write("<input type=\"hidden\" name=\"");
writer.Write("__VIEWSTATE");
writer.Write("\" value=\"\" />");
}
if (_fRequirePostBackScript)
{
RenderPostBackScript(writer, formUniqueID);
}
RenderScriptBlock(writer, _registeredClientScriptBlocks);
}

internal void OnFormPostRender(HtmlTextWriter writer, string
formUniqueID)
{
if (_registeredArrayDeclares != null)
{
writer.WriteLine();
writer.WriteLine("<script language=\"javascript\">\r\n<!--");
writer.Indent = writer.Indent + 1;
IDictionaryEnumerator iDictionaryEnumerator =
_registeredArrayDeclares.GetEnumerator();
while (iDictionaryEnumerator.MoveNext())
{
writer.Write("var ");
writer.Write(iDictionaryEnumerator.Key);
writer.Write(" = new Array(");
IEnumerator iEnumerator =
((ArrayList)iDictionaryEnumerator.Value).GetEnumer ator();
bool flag = true;
while (iEnumerator.MoveNext())
{
if (flag)
{
flag = false;
}
else
{
writer.Write(", ");
}
writer.Write(iEnumerator.Current);
}
writer.WriteLine(");");
}
writer.Indent = writer.Indent + 1;
writer.WriteLine("// -->\r\n</script>");
writer.WriteLine();
}
RenderHiddenFields(writer);
if (_fRequirePostBackScript && !_fPostBackScriptRendered)
{
RenderPostBackScript(writer, formUniqueID);
}
RenderScriptBlock(writer, _registeredClientStartupScripts);
_inOnFormRender = false;
}

private void RenderHiddenFields(HtmlTextWriter writer)
{
if (_registeredHiddenFields != null)
{
IDictionaryEnumerator iDictionaryEnumerator =
_registeredHiddenFields.GetEnumerator();
while (iDictionaryEnumerator.MoveNext())
{
writer.WriteLine();
writer.Write("<input type=\"hidden\" name=\"");
writer.Write((String)iDictionaryEnumerator.Key);
writer.Write("\" value=\"");
HttpUtility.HtmlEncode((String)iDictionaryEnumerat or.Value,
writer);
writer.Write("\" />");
}
_registeredHiddenFields = null;
}
}

private void RenderScriptBlock(HtmlTextWriter writer, IDictionary
scriptBlocks)
{
if (scriptBlocks != null)
{
writer.Indent = writer.Indent + 1;
IDictionaryEnumerator iDictionaryEnumerator =
scriptBlocks.GetEnumerator();
while (iDictionaryEnumerator.MoveNext())
{
writer.WriteLine((String)iDictionaryEnumerator.Val ue);
writer.WriteLine();
}
writer.Indent = writer.Indent - 1;
}
}

Best regards,
Gaidar
"sk" <sk@sk.com> wrote in message news:11*************@corp.supernews.com...
Hi,
I'm trying to override the Render method of my Page class. Are there any
standard guidelines for this?

Thanks.
Shardul

Nov 19 '05 #2
Hi Shardul:

It depends - what are you trying to achieve?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 8 Mar 2005 12:34:10 +0530, "sk" <sk@sk.com> wrote:
Hi,
I'm trying to override the Render method of my Page class. Are there any
standard guidelines for this?

Thanks.
Shardul


Nov 19 '05 #3
Hi Scott,
My company markets a helpdesk application that is web based and for
performing database administration tasks we have a custom application (.exe)
that is client/server based. This app is written using pure SDK (no
MFC/ATL/OWL). This code is pretty old (nearly a decade) and it supports only
English characters. It comprises of 3 main dlls which are pure C dlls (no
COM) with exported C++ classes. For the next release of our main app, we
intend to support multiple languages and so the management decided to
convert this legacy app also to web based. We have written a .NET wrapper
(written in C# and managed C++) which eventually calls into the low-level
dll's and the UI is in ASP.NET. The UI calls into the wrapper which in turn
calls into the legacy dlls. And for the most parts this works ok. But in the
old app, whenever you performed any operation a small window would open and
display status messages. For example when you performed an operation to
check the database for correctness, it would show messages like 'Checking
views...', 'Checking tables'... and so on. The calls to display these
messages are placed in the low-level dlls.

Now my job is to display these progress messages through the ASP.NET UI.
This is quite a challenge and we have figured out how to get the progress
message calls to end-up at the ASP level using delegates at the wrapper
level and function pointers at the dll level and this also works just fine.
So when the dll makes a call to show a progress message, it calls a method
at the low-level which calls the function pointer which points to the
delegate in the UI. So when my UI method is called, I just have to send it
the client (which is a browser). And this is anything but trivial.

I looked at a very good article on MSDN by Dino Esposito (Build your ASP.NET
pages on a richer Bedrock) but his solution just tells you when the
operation completes. Its not interactive. I have to mimic the exact behavior
of the old app, which is to open a small window and display the messages
within that window and then to close the window once the operation
completes.

For testing purposes I created a test page (Test2.aspx) that does NOT have a
code-behind class. And took the following steps:
1. Created a marker interface IRequireProgressMessage.
2. Put a <%@ Implements interface="IRequireProgressMessage" %> directive at
the top of my page Test2.aspx.
3. I wrote a server-side script inline within the page inside the <body> tag
and just before the <form> tag.
4. Within the block I put a check for postback and if it succeeds then I
emitted the following client-side script:
<script >
var oWin = window.showModelessDialog("blank.html",'','');
var oDoc = oWin.document;
</script>
5. After emitting this I flush the buffer just to be sure. At this point we
haven't yet called into the wrapper and the client has opened a modeless
window for displaying the progress messages. blank.html contains a single
<div> element with the id 'msgDiv'.
6. After this I setup the infrastructure to receive calls to SetMessage from
the dlls. This involves implementing an interface with one method
SetMessage(string strMessage). The implementation of SetMessage emits the
following client side script:
"<script>oDoc.all.msgDiv.innerHTML= '" +strMessage + "' </script>"
after checking whether the current handler
(System.Web.HttpContext.Current.Handler) is of the type
IRequireProgressMessage.
7. Call a method of the wrapper object. For this I created a test() method
on the wrapper which wraps a test() method on one of the lower level
objects. This method sends 2 messages with a delay of 2 seconds.

This works fine and the two messages are displayed in the modeless dialog.
However, this works only when you have the script within the .aspx page. But
the UI guys have already finished most of their work and they have used
code-behind throughout. The calls into the wrapper are placed from within
the Page_Load method. Now the problem with Page_Load is that if I emit my
script there and even if I flush the buffer, it won't get sent to the
browser. I don't know what goes on behind, but I think it just gets buffered
into another intermediate buffer and is emitted when Render gets called. So
I thought of overriding the Render method, move all of the processing from
Page_Load into the overridden method and then call into the wrapper after
rendering the <body> tag. For this I derived a new class from
System.Web.UI.Page, overrode the Render method. In this method I loop the
Controls collection and keep a check whether we rendered a LiteralControl
with the text "<body" in it. If it does it calls a virtual method
PostBodyRender. This method will be overridden by the code-behind class and
from within this do the processing that Page_Load used to do. It will first
emit the script that gets the modeless dialog to display if the page is
posted back and then do the rest of the processing, which involves setting
up the messaging infrastructure and calling into the wrapper method.

And this too works fine, but (and a big bad BUT) it gets munged if there is
some in-line script within the page!!! All aspx pages set the <title> from
server-side code. When this happens there's only one item in the Controls
collection which is the HtmlForm object representing the single <form>
element in the page. I just can't figure out when is the rest of the html
rendered and what happens to the <body> element. I figured, I must be doing
something wrong in Render and felt that there must be some standard way of
overriding the Render method which led me to post this here.

Whew! This turned out to be quite a big post! I tried to be verbose just to
be sure you have all the information. Let me know if you need anything else.

Thanks in advance.
Shardul.
"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:fk********************************@4ax.com...
Hi Shardul:

It depends - what are you trying to achieve?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 8 Mar 2005 12:34:10 +0530, "sk" <sk@sk.com> wrote:
Hi,
I'm trying to override the Render method of my Page class. Are there any
standard guidelines for this?

Thanks.
Shardul

Nov 19 '05 #4
Hi Shardul:

Quite an explanation here! It's always a pain to provide immediate
feedback to a web app - I feel your pain.

After reading your description my concern would be that whatever
solution you come up with would be fragile - in the sense that an
unknowing developer could change functionality in the ASP.NET page and
break the feedback mechanism.

Did you consider a polling mechanism? The message from the lower level
could be saved on the server, the client window could refresh or
postback every 5 seconds and check the status. Messages would still be
pretty much real time - but the solution I feel would be much easier
to maintain.


--
Scott
http://www.OdeToCode.com/blogs/scott/

On Wed, 9 Mar 2005 13:53:19 +0530, "Shardul Kulkarni"
<ks********@yahoo.co.uk> wrote:
Hi Scott,
My company markets a helpdesk application that is web based and for
performing database administration tasks we have a custom application (.exe)
that is client/server based. This app is written using pure SDK (no
MFC/ATL/OWL). This code is pretty old (nearly a decade) and it supports only
English characters. It comprises of 3 main dlls which are pure C dlls (no
COM) with exported C++ classes. For the next release of our main app, we
intend to support multiple languages and so the management decided to
convert this legacy app also to web based. We have written a .NET wrapper
(written in C# and managed C++) which eventually calls into the low-level
dll's and the UI is in ASP.NET. The UI calls into the wrapper which in turn
calls into the legacy dlls. And for the most parts this works ok. But in the
old app, whenever you performed any operation a small window would open and
display status messages. For example when you performed an operation to
check the database for correctness, it would show messages like 'Checking
views...', 'Checking tables'... and so on. The calls to display these
messages are placed in the low-level dlls.

Now my job is to display these progress messages through the ASP.NET UI.
This is quite a challenge and we have figured out how to get the progress
message calls to end-up at the ASP level using delegates at the wrapper
level and function pointers at the dll level and this also works just fine.
So when the dll makes a call to show a progress message, it calls a method
at the low-level which calls the function pointer which points to the
delegate in the UI. So when my UI method is called, I just have to send it
the client (which is a browser). And this is anything but trivial.

Agreed!
I looked at a very good article on MSDN by Dino Esposito (Build your ASP.NET
pages on a richer Bedrock) but his solution just tells you when the
operation completes. Its not interactive. I have to mimic the exact behavior
of the old app, which is to open a small window and display the messages
within that window and then to close the window once the operation
completes.

For testing purposes I created a test page (Test2.aspx) that does NOT have a
code-behind class. And took the following steps:
1. Created a marker interface IRequireProgressMessage.
2. Put a <%@ Implements interface="IRequireProgressMessage" %> directive at
the top of my page Test2.aspx.
3. I wrote a server-side script inline within the page inside the <body> tag
and just before the <form> tag.
4. Within the block I put a check for postback and if it succeeds then I
emitted the following client-side script:
<script >
var oWin = window.showModelessDialog("blank.html",'','');
var oDoc = oWin.document;
</script>
5. After emitting this I flush the buffer just to be sure. At this point we
haven't yet called into the wrapper and the client has opened a modeless
window for displaying the progress messages. blank.html contains a single
<div> element with the id 'msgDiv'.
6. After this I setup the infrastructure to receive calls to SetMessage from
the dlls. This involves implementing an interface with one method
SetMessage(string strMessage). The implementation of SetMessage emits the
following client side script:
"<script>oDoc.all.msgDiv.innerHTML= '" +strMessage + "' </script>"
after checking whether the current handler
(System.Web.HttpContext.Current.Handler) is of the type
IRequireProgressMessage.
7. Call a method of the wrapper object. For this I created a test() method
on the wrapper which wraps a test() method on one of the lower level
objects. This method sends 2 messages with a delay of 2 seconds.

This works fine and the two messages are displayed in the modeless dialog.
However, this works only when you have the script within the .aspx page. But
the UI guys have already finished most of their work and they have used
code-behind throughout. The calls into the wrapper are placed from within
the Page_Load method. Now the problem with Page_Load is that if I emit my
script there and even if I flush the buffer, it won't get sent to the
browser. I don't know what goes on behind, but I think it just gets buffered
into another intermediate buffer and is emitted when Render gets called. So
I thought of overriding the Render method, move all of the processing from
Page_Load into the overridden method and then call into the wrapper after
rendering the <body> tag. For this I derived a new class from
System.Web.UI.Page, overrode the Render method. In this method I loop the
Controls collection and keep a check whether we rendered a LiteralControl
with the text "<body" in it. If it does it calls a virtual method
PostBodyRender. This method will be overridden by the code-behind class and
from within this do the processing that Page_Load used to do. It will first
emit the script that gets the modeless dialog to display if the page is
posted back and then do the rest of the processing, which involves setting
up the messaging infrastructure and calling into the wrapper method.

And this too works fine, but (and a big bad BUT) it gets munged if there is
some in-line script within the page!!! All aspx pages set the <title> from
server-side code. When this happens there's only one item in the Controls
collection which is the HtmlForm object representing the single <form>
element in the page. I just can't figure out when is the rest of the html
rendered and what happens to the <body> element. I figured, I must be doing
something wrong in Render and felt that there must be some standard way of
overriding the Render method which led me to post this here.

Whew! This turned out to be quite a big post! I tried to be verbose just to
be sure you have all the information. Let me know if you need anything else.

Nov 19 '05 #5
Hi Scott,

A polling solution was among the first things that I thought of. But theres
a problem. If the polling interval is 5 soconds and say there are 5 messages
that are generated, then it will take a whole 25 seconds before all those
messages are displayed to the user, and the operation most likely will
complete before 25 seconds have elapsed since it was invoked. So if you
reduce the polling interval, then you will be hitting the server a lot more
and it may impair the performance of the server.

-Shardul

"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:rq********************************@4ax.com...
Hi Shardul:

Quite an explanation here! It's always a pain to provide immediate
feedback to a web app - I feel your pain.

After reading your description my concern would be that whatever
solution you come up with would be fragile - in the sense that an
unknowing developer could change functionality in the ASP.NET page and
break the feedback mechanism.

Did you consider a polling mechanism? The message from the lower level
could be saved on the server, the client window could refresh or
postback every 5 seconds and check the status. Messages would still be
pretty much real time - but the solution I feel would be much easier
to maintain.


--
Scott
http://www.OdeToCode.com/blogs/scott/

On Wed, 9 Mar 2005 13:53:19 +0530, "Shardul Kulkarni"
<ks********@yahoo.co.uk> wrote:
Hi Scott,
My company markets a helpdesk application that is web based and for
performing database administration tasks we have a custom application (.exe)that is client/server based. This app is written using pure SDK (no
MFC/ATL/OWL). This code is pretty old (nearly a decade) and it supports onlyEnglish characters. It comprises of 3 main dlls which are pure C dlls (no
COM) with exported C++ classes. For the next release of our main app, we
intend to support multiple languages and so the management decided to
convert this legacy app also to web based. We have written a .NET wrapper
(written in C# and managed C++) which eventually calls into the low-level
dll's and the UI is in ASP.NET. The UI calls into the wrapper which in turncalls into the legacy dlls. And for the most parts this works ok. But in theold app, whenever you performed any operation a small window would open anddisplay status messages. For example when you performed an operation to
check the database for correctness, it would show messages like 'Checking
views...', 'Checking tables'... and so on. The calls to display these
messages are placed in the low-level dlls.

Now my job is to display these progress messages through the ASP.NET UI.
This is quite a challenge and we have figured out how to get the progress
message calls to end-up at the ASP level using delegates at the wrapper
level and function pointers at the dll level and this also works just fine.So when the dll makes a call to show a progress message, it calls a methodat the low-level which calls the function pointer which points to the
delegate in the UI. So when my UI method is called, I just have to send itthe client (which is a browser). And this is anything but trivial.


Agreed!
I looked at a very good article on MSDN by Dino Esposito (Build your ASP.NETpages on a richer Bedrock) but his solution just tells you when the
operation completes. Its not interactive. I have to mimic the exact behaviorof the old app, which is to open a small window and display the messages
within that window and then to close the window once the operation
completes.

For testing purposes I created a test page (Test2.aspx) that does NOT have acode-behind class. And took the following steps:
1. Created a marker interface IRequireProgressMessage.
2. Put a <%@ Implements interface="IRequireProgressMessage" %> directive atthe top of my page Test2.aspx.
3. I wrote a server-side script inline within the page inside the <body> tagand just before the <form> tag.
4. Within the block I put a check for postback and if it succeeds then I
emitted the following client-side script:
<script >
var oWin = window.showModelessDialog("blank.html",'','');
var oDoc = oWin.document;
</script>
5. After emitting this I flush the buffer just to be sure. At this point wehaven't yet called into the wrapper and the client has opened a modeless
window for displaying the progress messages. blank.html contains a single
<div> element with the id 'msgDiv'.
6. After this I setup the infrastructure to receive calls to SetMessage fromthe dlls. This involves implementing an interface with one method
SetMessage(string strMessage). The implementation of SetMessage emits the
following client side script:
"<script>oDoc.all.msgDiv.innerHTML= '" +strMessage + "' </script>"
after checking whether the current handler
(System.Web.HttpContext.Current.Handler) is of the type
IRequireProgressMessage.
7. Call a method of the wrapper object. For this I created a test() methodon the wrapper which wraps a test() method on one of the lower level
objects. This method sends 2 messages with a delay of 2 seconds.

This works fine and the two messages are displayed in the modeless dialog.However, this works only when you have the script within the .aspx page. Butthe UI guys have already finished most of their work and they have used
code-behind throughout. The calls into the wrapper are placed from within
the Page_Load method. Now the problem with Page_Load is that if I emit my
script there and even if I flush the buffer, it won't get sent to the
browser. I don't know what goes on behind, but I think it just gets bufferedinto another intermediate buffer and is emitted when Render gets called. SoI thought of overriding the Render method, move all of the processing fromPage_Load into the overridden method and then call into the wrapper after
rendering the <body> tag. For this I derived a new class from
System.Web.UI.Page, overrode the Render method. In this method I loop the
Controls collection and keep a check whether we rendered a LiteralControl
with the text "<body" in it. If it does it calls a virtual method
PostBodyRender. This method will be overridden by the code-behind class andfrom within this do the processing that Page_Load used to do. It will firstemit the script that gets the modeless dialog to display if the page is
posted back and then do the rest of the processing, which involves settingup the messaging infrastructure and calling into the wrapper method.

And this too works fine, but (and a big bad BUT) it gets munged if there issome in-line script within the page!!! All aspx pages set the <title> fromserver-side code. When this happens there's only one item in the Controls
collection which is the HtmlForm object representing the single <form>
element in the page. I just can't figure out when is the rest of the html
rendered and what happens to the <body> element. I figured, I must be doingsomething wrong in Render and felt that there must be some standard way ofoverriding the Render method which led me to post this here.

Whew! This turned out to be quite a big post! I tried to be verbose just tobe sure you have all the information. Let me know if you need anything else.


Nov 19 '05 #6

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

Similar topics

6
by: stevehayter | last post by:
Wonder if anyone can help me solve this problem! I have a 3x3 table which i'm using to create a table with a rounded edge using images in the top left, top right, bottom left, and bottom right...
1
by: jarit | last post by:
Hi, Found these coding guidelines for C#, HTML, Javascript, Java, HTML, PL/SQL, T-SQL, VB and VBScript. Well written and free to download. www.demachina.com/products/swat Jeroen
6
by: james b | last post by:
Hi all, I'm trying to do something with method overloading and I can't seem to get it to work my code is along the lines of public int method1(int a, int b, int c){ //method body } public...
31
by: | last post by:
Hi, Why can I not overload on just the return type? Say for example. public int blah(int x) { }
1
by: Tomas | last post by:
Is there any sequence diagram on the web that clearly shows in which order all Page methods (load, render and so on) are being called compared to the order the page's contained control methods are...
2
by: John A Grandy | last post by:
For ASP.NET UserControls , is it possible to provide multiple overrides of the intrinsic handler methods (those for which the delegate that wires the event to the handler is built-in , such as Init...
11
by: placid | last post by:
Hi all, Is it possible to be able to do the following in Python? class Test: def __init__(self): pass def puts(self, str): print str
3
by: y-man | last post by:
Hi, I am trying to get an overloaded operator to work inside the class it works on. The situation is something like this: main.cc: #include "object.hh" #include "somefile.hh" object obj,...
10
by: Matthew | last post by:
Am I correct in thinking there is no method/function overloading of any kind in any version of PHP? Thanks, Matthew
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.