Is LoadControl (virtualPath) is caching controls in a single request. If so, can i disable it.

U

Umut Tezduyar

It seems, it is caching it.
The following code is an example for it. How can avoid from this.

override void OnLoad (sender and eventargs)
{
Control control = this.LoadControl (path);
this.Controls.Add (control);

// I change the content of the html of the control.
TextReader reader = new StreamReader (path);
string content = reader.ReadToEnd ();
reader.Close();
TextWriter writer = new StreamWriter (path);
writer.Write (content + "<b>NewPart</b>");
writer.Close ();
}

override void OnPreRender (sender and eventargs)
{
// Altough i have changed the content of the control, still same control
is loaded.
Control control = this.LoadControl (path);
this.Controls.Add (control);
}

I have not copy-paste this code from VS. There may be some implementation
mistakes. Sorry for this.
 
S

Steven Cheng[MSFT]

Hi Umut,

Thanks for posting. AS for the LoadControl's caching problem you
mentioned, I've done some deep investigate into the Page.LoadControl
method. In fact, it is calling the TemplateControl.LoadControl method and
will looking for the control's type from a temporary folder. So when you
call the LoadControl again(during the same page request lifecycle), it'll
retrieve the cached item from the temporary folder rather than parsing the
raw ascx file again, this is mainly for performance consideration.
Also, since this caching only work for loading the same UserControl during
the same page request processing, so if we refresh or post back the page
again, the page will loaded the updated control (ascx file ) from its
actual position.

If you have anything else unclear , please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
U

Umut Tezduyar

Is there a way to disable this. I want to load a control twice in a page
request. And in the click event of a button, its content was changed. I have
to do Response.Redirect (). But it is waste of time.
 
S

Steven Cheng[MSFT]

Hi Umut,

Thanks for your response. As I've also mentioned in your another thread in
this group. Frequently modifying the aspx or ascx source file will make the
asp.net frequently recompile the asp.net runtime generated assembly which
may have performance concerns. Also, when the recompile time exceed the
asp.net's configuration setting, it will restart the web application, I
don't think that's what you want to see. And currently my suggestion is try
putting the UserControl's UI changing code into the Control's codebehind.
For example:

We define a UserControl which has a "Status" property. Then in the
UserControl's Load event, we can

modify the UserControl's UI Part according to the "Status" Property which
can be assigned when we Load it in the page via Page.LoadControl. How do
you think of this?

Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
U

Umut Tezduyar

Hi Steven.

I don't think this will work. In my oppinion, page.LoadControl (string path)
is caching the control according to the path of the control. Let me give an
example:

---------Request #1 Starts
It doesnt matter, how many times you call the page.LoadControl(path), in
each page gives you the same control.
---------Request #1 Ends

---------Request #2 Starts
In this request, LoadControl again loads the control. But following call
to the LoadControl (path) will give the same result with the previous as
soon as you are in the same REQUESR.
---------Request #2 Ends

By the way, I will post the control that i have done this week. With the
real example, you can suggest something different.
 
S

Steven Cheng[MSFT]

Hi Umut,

Thanks for your prompt response. Yes, the control is cached according to
its location. That's why I suggest you try put the UI changing logic in the
Usercontrol's code. We can put two diferent panels in the UserControl and
only display one of them according to a certain property value( via the
Visible property). That's more flexible and can avoid frequently changing
the ascx file which may cause the whole web application to restart. Anyway,
I'll wait for your control example to see whether there're anything else we
can help to improve it. Looking forward to your response. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
U

Umut Tezduyar

Hi Steven,

I have finished my web control. I am sorry that it is a bit delayed. Before
publishing it to all asp.net users, i want to protect my code. Do you have
an advice for me. (Free stuff is preferable). As it is stated, dotfuscator
community edition is insufficient. After protecting my code, i will publish
it.
 
S

Steven Cheng[MSFT]

Thanks for your followup Umut,

As for protecting the application/ component from dasm, currently I think
we haven't any good means on this since the IL based compiled mode make us
easy to do reverse engineering on managed assembly. Though some tools such
as dotfuscator can help make our assemblies hard to be reverse compiled,
there is still means to overcome it. As my opinion, the best means maybe
provide a particular simplized version of your control , but this is not
suitable for many scenarios. Here is a certain blog article which also
discussed this:

#How do I protect my C# code against reverse engineering?
http://blogs.msdn.com/ericgu/archive/2004/02/24/79236.aspx

Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
U

Umut Tezduyar

Hi again Steven.

Finally i have uploaded my project to web.
http://www.tezduyar.com/umut/WebTemplate.aspx
This is the main page for this project. I will develop it with the
feedbacks of my users. The main purpose of this project is developent
N-depth web sites very easly. I am sure that you can quicly discover it. But
i want to warn you that its UI is not so simple. At least for the beggining.
I am explaining the initiation of the program. Its only one .dll file.
You can add it to your toolbox. I have VS support. After adding it, there
are two controls in your toolbox. WebFramework (Main part) and LoginControl.
To use WebFramework as an administrator you have to login to the system. You
can use my LoginControl. This control supports two functions, function as
LoginControl (like .net framewrok 2.0) and function as my custom
LoginControl (default). There is a property named "CustomLoginScenario" for
that. To use it for the first time, start your that has LoginControl in it.
It displays different UI if it is your first login. Login to the system, and
then use the WebFramework. Hint, You can use placeholders in your Tabs/
MasterControl poperty. These days i will add also a sample project to its
page. You are the first tester of this project. Have fun :))

You are very interested with blogs, i have an additional question to
you. Is there a custom format for blogging. For example
..text uses a format like blogger/archieve/year/month/day/id.aspx
(ericgu/archive/2004/02/24/79236.aspx). Nikhil Kothari uses query strings
for it (like blog.aspx?id=123). Some blogs have custom http handlers. Which
one is valid.

Last question :) If i write my own IHttpHandler, how can i load controls
like asp.net page life cycle.

// This is not working.
public void ProcessRequest(HttpContext context)
{

Page p = new Page();


HtmlForm form = new HtmlForm();

form.ID = "Form1";

p.Controls.Add (form);

StringWriter writer = new StringWriter();

HtmlTextWriter html = new HtmlTextWriter(writer);

LinkButton btn = new LinkButton();

btn.Text = "Click";

form.Controls.Add (c);

p.RenderControl (html);

context.Response.Write (writer.ToString ());

html.Close ();

writer.Close ();

}
 
S

Steven Cheng[MSFT]

Hi Umut,

Thanks for your followup. So surprised and glad that you've published your
web controls. Congratulations!

I've just downloaded the assembly and its docs, I'm sure I'll spend some
times to have a overview on it. Also, you may try introduce it to some
other communitry or discussions such as codeproject....

As for the Blog articles' URL format, such as
(ericgu/archive/2004/02/24/79236.aspx). or
blogthread.aspx?user=xxx&date=xxx...

I think they're the same in nature, in other words, the
(ericgu/archive/2004/02/24/79236.aspx) style url will also be parsed into
querystring style(dynamic url) before the web application process it. The
reason why use use (ericgu/archive/2004/02/24/79236.aspx ) style url is it
is like the static web page url which is more friendly to search engine (
can easily be found by search enigines). Yes, some thing like a filter
is able to do so, also the ASP.NET has provide the UrlReWriting function
which is capable of providing such search engine friendly url, here are
some related tech articles:

#Search engine friendly URLs using ASP.NET (C#.NET)
http://www.codetoad.com/asp.net_ma_searchenginefriendly.asp
http://www.ftponline.com/vsm/2002_02/magazine/columns/qa/
http://www.15seconds.com/issue/030522.htm

You can also search for some former threads in the newsgroup discussing on
this topic.


As for the last question you mentioned:
================
Last question :) If i write my own IHttpHandler, how can i load
controls
like asp.net page life cycle.
================

this is becaues the HTTPHandler is only providing some basic interfaces to
write content into the response stream. Yes, we can manually create
controls (nested sub controls ) and use HtmlTextWirter to intercept the
controls' rendered html and write into the handler's response stream, then
the client browser can display the control's rendered html. But when the
user fire some post back events, (such as a server button's click) that
won't work. Because the httphandler isn't a asp.net page( the asp.net page
class is a particular HttpHandler) which will do serveral additional tasks
such as Init, LoadPostData, LoadViewSTate, ... RaisePostBack events ,
SaveViewstates.... , these things won't be done automatically. So ,
if you're wanting to use httphandler, you may try programming under the
traditional web page programming's roles, like in classic ASP or JSP ...
which haven't thing like postback. When we want to post page to do some
serve side to do some works, just set the <form > tag's action and provide
a submit button in the form which will help post the page(submit the form)..

Just some of my understanding. If you have any thing unclear, please feel
free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
U

Umut Tezduyar

Thanks for your interest. I will be waiting your comments on it.
I will create a new thread to "microsoft.public.framework.aspnet" and
"microsoft.dotnet.framework.aspnet.webcontrols". Also as you stated, i will
introduce it on the codeproject and some other community forums. :)
 

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top