CodeVerge.Net Beta


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

ASP.NET Web Hosting – 3 Months Free!



Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 4/4/2004 5:21:11 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 1 Views: 97 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
2 Items, 1 Pages 1 |< << Go >> >|
xa2ir
Asp.Net User
Problem: sample of HtmlTextWriter class4/4/2004 5:21:11 AM

0/0

Hi,
I have a problem implementing a sample of MSDN.
I wanted to have a separate class for the following code, so I created a class (e.g. class4.cs) in my web project and write these lines of codes into it. Then I created an instance of "MyPage" class in "Page_Load" event (code behind) of my web form, but after running the application I couldn't see anything on my page.
Maybe I did some thing wrong. Would you please guide me?

Thanks in advance


namespace WebPage
{
using System;
using System.IO;
using System.Web.UI;

public class MyPage : Page
{
public MyPage():base()
{
}

[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter writer)
{
return new MyHtmlTextWriter(writer);
}

[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
protected override void Render(HtmlTextWriter writer)
{
// Write a Font control.
writer.AddAttribute("color", "red");
writer.AddAttribute("size", "6pt");
writer.RenderBeginTag(HtmlTextWriterTag.Font);
writer.Write("<br>" + "The time on the server:<br> " + System.DateTime.Now.ToLongTimeString());
writer.RenderEndTag();
}
}

public class MyHtmlTextWriter : HtmlTextWriter
{
public MyHtmlTextWriter(TextWriter writer):base(writer)
{
writer.Write("<font color=blue> 'MyHtmlTextWriter' is used for rendering.</font>");
}
}

}
FancyKetsup
Asp.Net User
Re: Problem: sample of HtmlTextWriter class4/5/2004 12:02:52 AM

0/0

This is more for using as a base for your page. In your aspx code behind just have it inherit from MyPage instead of Page and it will work the way you expect I think. I guess you could create an instance of it on a page event like oninit or pageload and then call the methods you need... but without doing more thinking I am not sure if just creating an instance and clalling the method CreateHtmlTextWriter will work you may have to put something in your aspx code behind like the code below if your going to just creat an instance of it rather than have your code behind inherit from it instead of Page.

Inyour code behind put this instead of using page load...


protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter writer)
{
MyPage newWriter = new MyPage();
return newWriter.MyHtmlTextWriter(writer);
}


code not tested nor implied to be correct :)

Answering a question increases your knowledge asking a question shows your Intelligence!
2 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Pro ASP.NET 2.0 in VB 2005: From Professional to Expert Authors: Laurence Moroney, Matthew MacDonald, Pages: 1253, Published: 2006
Pro ASP.NET 2.0 in C# 2005 Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1255, Published: 2005
Mastering ASP.NET with C# Authors: A. Russell Jones, Pages: 816, Published: 2002
Developing Microsoft ASP.NET Server Controls and Components Authors: Nikhil Kothari, Vandana Datye, Pages: 689, Published: 2002
Essential ASP. NET with Examples in C#: With Examples in C# Authors: Fritz Onion, Pages: 393, Published: 2003
Professional ASP.NET 2.0 Server Control and Component Development Authors: Shahram Khosravi, Pages: 1186, Published: 2006
Pro ASP.NET 2.0 in C# 2005: Create Next-generation Web Applications with the Latest Version of Microsoft's Revolutionary Technology Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1426, Published: 2006
Microsoft SharePoint: Building Office 2003 Solutions Authors: Scot P. Hillier, Pages: 392, Published: 2006
Programming ASP.NET: Building Web Applications and Services Using C and VB.NET. Authors: Jesse Liberty, Dan Hurwitz, Pages: 988, Published: 2003
Pro ASP. Net 3. 5 Server Controls and AJAX Components Authors: Rob Cameron, Dale Michalk, Pages: 740, Published: 2008

Web:
HtmlTextWriter Class (System.Web.UI) The HtmlTextWriter class is used to render HTML 4.0 to desktop browsers. The HtmlTextWriter is also the base class for all markup writers in the System.Web. ...
Use of the HtmlTextWriter Class to Render Custom Controls Nov 14, 2006 ... This article will address the use of the HtmlTextWriter class and the ... The real problem occurs with added complexity and the increased ...
HtmlTextWriter Class [Visual Basic, C#, JScript] The following example demonstrates how to use members of the HtmlTextWriter class to generate HTML that renders in the browser ...
ASP.NET.4GuysFromRolla.com: Stopping JavaScript Errors When ... Aug 24, 2005 ... (For example, if you set the LinkButton's ForeColor property to Red, the base class's AddAttributesToRender(HtmlTextWriter) method will ...
Sreenath Reddy G: Create HTML using HtmlTextWriter class in x++ HtmlTextWriter class is used to output properly formed HTML into a web page. ... The HtmlTextWriter class permits the developer to generate page output in a ...
O'Reilly - Safari Books Online - 0735615829 - Developing Microsoft ... Unlike the earlier samples in this chapter, LoginUI exercises the ... To demonstrate the functionality of the HtmlTextWriter class, the LoginUI control ...
HtmlTextWriter Constructor Initializes a new instance of the HtmlTextWriter class. ... The constructor is from a custom HtmlTextWriter class, named CstmHtmlTW. ...
ASPRunner.NET. Articles. Basics of creating server controls. Part ... NET is able to substitute automatically HtmlTextWriter class with its heirs depending on .... In my next article problems of saving state between postbacks, ...
ASP.NET - HtmlTextWriter Use Problem. Write HTML programmatically using the HtmlTextWriter object. ... We should learn about and master the HtmlTextWriter class. ...
Safari Books Online - 0735615829 - Developing Microsoft ASP.NET ... The base Control class defines three methods for rendering, which Table 8-1 shows. All three methods take an instance of the HtmlTextWriter class as their ...




Search This Site:










custom control not working when declaring in codebehind

control that can print its parent assembly version

unsupported network devices

disappointed with ultimahosts

dynamic controls on post back?

asp .net server control

execute .bat file in web form using asp.net

virtual path error with user control

getting submitted value from composite control

usercontrol maintaining values

using controls or dlls to communicate with database

hosting competencies at certified partner level?

usercontrol in composite control

need some help on custom dropdownlist...

how to hide client script in web custom controls?

setting user control property programmatically

viewstate hassels

windows home server

cuastome template data grdi column doesnt appear after post back

looking for fast performance in dnn and application hosting

asp.net 2.0 hosting companies?

plz advise: max $20

error creating ram disk on ibm blade

itemtemplate in my derived datagrid

custom controls and postback

how to change properties of webcontrols internally?

web custom controls position on it's aspx page?

which namespace to be imported to access server and application objects?

styling web user controls

custom control caching...

  Privacy | Contact Us
All Times Are GMT