473,511 Members | 10,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to create a Page by code

In a C# Web Control library I created this Page / HttpHandler:
================
namespace WebUtils
{
public class FTBImageGallery : Page
{
public override void ProcessRequest(HttpContext context)
{
base.ProcessRequest(context);
}
protected override void CreateChildControls()
{
Button but = new Button();
but.Text = "Hello :-)";
but.ID = "myButton";
Controls.Add(but);
}
}
}
================

in a web project using this library I wrote this http handler
================
<%@ WebHandler Language="C#" Class="IGallery" %>

using System;
using System.Web;

using WebUtils;

public class IGallery : FTBImageGallery
{
}
================

When I try to query this HttpHandler I get the following error when calling base.ProcessRequest(context)

================
System.Web.HttpUnhandledException was unhandled by user code
Message="Exception of type 'System.Web.HttpUnhandledException' was thrown."
Source="System.Web"
ErrorCode=-2147467259
StackTrace:
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(Http Context context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at WebUtils.FTBImageGallery.ProcessRequest(HttpContex t context) in F:\MyWork\WebLibrary\WebUtils\WebUtils\FTBImageGal lery.cs:line 19
at System.Web.HttpApplication.CallHandlerExecutionSte p.System.Web.HttpApplication.IExecutionStep.Execut e()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean& completedSynchronously)
================

Any idea of what could have gone wrong?

--
I have taken a vow of poverty. If you want to really piss me off, send me money.

Jan 17 '06 #1
2 1689
Never mind, thanks to Reflector and the web deployment tool I figured out how to write this working (although still mysterious looking) code. I guess tomorrow I will just have to understand it!
================
public class FTBImageGallery : Page
{
public FTBImageGallery()
{
}
public override void ProcessRequest(HttpContext context)
{
base.ProcessRequest(context);
}
protected override void FrameworkInitialize()
{
base.FrameworkInitialize();
this.__BuildControlTree(this);
//base.AddWrappedFileDependencies(default_aspx.__fil eDependencies);
base.Request.ValidateInput();
}
private void __BuildControlTree(FTBImageGallery __ctrl)
{
this.InitializeCulture();
IParserAccessor accessor1 = __ctrl;
accessor1.AddParsedSubObject(new LiteralControl("\r\n\r\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n\r\n<htmlxmlns=\"http://www.w3.org/1999/xhtml\" >\r\n"));
HtmlHead head1 = this.__BuildControl__control2();
accessor1.AddParsedSubObject(head1);
accessor1.AddParsedSubObject(new LiteralControl("\r\n<body style=\"background-color:#FFFFA0\">\r\n "));
HtmlForm form1 = this.__BuildControlform1();
accessor1.AddParsedSubObject(form1);
accessor1.AddParsedSubObject(new LiteralControl("\r\n</body>\r\n</html>\r\n"));
}
private HtmlForm __BuildControlform1()
{
HtmlForm form1 = new HtmlForm();
form1.ID = "form1";
IParserAccessor accessor1 = form1;
accessor1.AddParsedSubObject(new LiteralControl("\r\n <div>\r\n\t\t"));

Button but = new Button();
but.Text = "Hello :-)";
but.ID = "myButton";
accessor1.AddParsedSubObject(but);

return form1;
}
private HtmlHead __BuildControl__control2()
{
HtmlHead head1 = new HtmlHead("head");
HtmlTitle title1 = this.__BuildControl__control3();
IParserAccessor accessor1 = head1;
accessor1.AddParsedSubObject(title1);
return head1;
}
private HtmlTitle __BuildControl__control3()
{
HtmlTitle title1 = new HtmlTitle();
IParserAccessor accessor1 = title1;
accessor1.AddParsedSubObject(new LiteralControl("Untitled Page"));
return title1;
}
}
================
"Lloyd Dupont" <net.galador@ld> wrote in message news:%2****************@TK2MSFTNGP15.phx.gbl...
In a C# Web Control library I created this Page / HttpHandler:
================
namespace WebUtils
{
public class FTBImageGallery : Page
{
public override void ProcessRequest(HttpContext context)
{
base.ProcessRequest(context);
}
protected override void CreateChildControls()
{
Button but = new Button();
but.Text = "Hello :-)";
but.ID = "myButton";
Controls.Add(but);
}
}
}
================

in a web project using this library I wrote this http handler
================
<%@ WebHandler Language="C#" Class="IGallery" %>

using System;
using System.Web;

using WebUtils;

public class IGallery : FTBImageGallery
{
}
================

When I try to query this HttpHandler I get the following error when calling base.ProcessRequest(context)

================
System.Web.HttpUnhandledException was unhandled by user code
Message="Exception of type 'System.Web.HttpUnhandledException' was thrown."
Source="System.Web"
ErrorCode=-2147467259
StackTrace:
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(Http Context context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at WebUtils.FTBImageGallery.ProcessRequest(HttpContex t context) in F:\MyWork\WebLibrary\WebUtils\WebUtils\FTBImageGal lery.cs:line 19
at System.Web.HttpApplication.CallHandlerExecutionSte p.System.Web.HttpApplication.IExecutionStep.Execut e()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean& completedSynchronously)
================

Any idea of what could have gone wrong?

--
I have taken a vow of poverty. If you want to really piss me off, send me money.

Jan 17 '06 #2
In the end I came up with that:
(what do you think?)
==============
using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace WebUtils
{
public class CodePage : Page
{
public bool ValidateRequest = false;

protected override void FrameworkInitialize()
{
base.FrameworkInitialize();
InitializeCulture();
BuildPage();
Title = Title;
if(ValidateRequest)
Request.ValidateInput();
}
public readonly HtmlForm MainForm = new HtmlForm();
public readonly HtmlHead Head = new HtmlHead();
HtmlTitle pageTitle = new HtmlTitle();
public readonly HtmlGenericControl Body = new HtmlGenericControl("body");

public new string Title
{
get { return base.Title; }
set
{
pageTitle.Text = value;
base.Title = value;
}
}

protected virtual void BuildPage()
{
Head.Controls.Add(pageTitle);
Body.Controls.Add(MainForm);
MainForm.Controls.Add(new LiteralControl("\r\n"));

Controls.Add(new LiteralControl("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\" >\r\n"));
Controls.Add(Head);
Controls.Add(new LiteralControl("\r\n"));
Controls.Add(Body);
Controls.Add(new LiteralControl("\r\n</html>\r\n"));
}
}
}
==============

"Lloyd Dupont" <net.galador@ld> wrote in message news:%2****************@TK2MSFTNGP15.phx.gbl...

In a C# Web Control library I created this Page / HttpHandler:
================
namespace WebUtils
{
public class FTBImageGallery : Page
{
public override void ProcessRequest(HttpContext context)
{
base.ProcessRequest(context);
}
protected override void CreateChildControls()
{
Button but = new Button();
but.Text = "Hello :-)";
but.ID = "myButton";
Controls.Add(but);
}
}
}
================

in a web project using this library I wrote this http handler
================
<%@ WebHandler Language="C#" Class="IGallery" %>

using System;
using System.Web;

using WebUtils;

public class IGallery : FTBImageGallery
{
}
================

When I try to query this HttpHandler I get the following error when calling base.ProcessRequest(context)

================
System.Web.HttpUnhandledException was unhandled by user code
Message="Exception of type 'System.Web.HttpUnhandledException' was thrown."
Source="System.Web"
ErrorCode=-2147467259
StackTrace:
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(Http Context context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at WebUtils.FTBImageGallery.ProcessRequest(HttpContex t context) in F:\MyWork\WebLibrary\WebUtils\WebUtils\FTBImageGal lery.cs:line 19
at System.Web.HttpApplication.CallHandlerExecutionSte p.System.Web.HttpApplication.IExecutionStep.Execut e()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean& completedSynchronously)
================

Any idea of what could have gone wrong?

--
I have taken a vow of poverty. If you want to really piss me off, send me money.

Jan 17 '06 #3

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

Similar topics

2
2305
by: Gill Bates | last post by:
I'm trying to login to a banking site (https://www.providentconnection.com) using vb.net. I've tried many variations of WebClient and HttpWebRequest; none of which I've got to work. My latest...
4
2447
by: Mark J. McGinty | last post by:
Greets, Part of the content of one of our web pages uses wingdings and Chr(239) through Chr(242) (which are little arrow outlines, though that's not really important.) It worked just fine in...
6
2287
by: Frank Wilson | last post by:
Tom, It sounds to me like ASP, not ASP.NET is handling the request for WebForm1.aspx. This is most likely an IIS config issue that may have been caused by order of installation or...
2
1411
by: Paul K | last post by:
I'm trying to understand how to implement logic I currently have in an ASP application in an ASP.NET application. In ASP I have an entry application that draws an html table for a specified...
3
2079
by: Kenneth P | last post by:
Hi, I have a very good book on asp.net Sams ASP.NET Tips, Tutorials and Code ISBN 0-672-32143-2 and is trying to teach myself from examples from this book Chapter 16. Anyway I come quite...
1
1593
by: Paloma García | last post by:
Dear all, I have created personalized configuration sections in my web project following the instructions described in this page...
18
3364
by: Gleep | last post by:
I've searched google intensely on this topic and it seems noone really knows how to approch this. The goal I don't want clients to give out their usernames and passwords to friends, since the site...
5
3766
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
4
1428
by: pek | last post by:
I created a file name image.php which contains only the following code: <?php function createThumbnail($picture,$thumb,$new_w,$new_h) { $extension=substr($picture,strrpos($picture,".")+1);...
6
3322
by: AppleBag | last post by:
I'm having the worst time trying to login to myspace through code. Can someone tell me how to do this? Please try it yourself before replying, only because I have asked this a couple of times in...
0
7148
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5673
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.