Creating custom form in Asp.NET 2.0

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have just created a class that removes action attribute from HtmlForm. The
code looks like here.

namespace ComIT.Applications.Common
{
public class Form : System.Web.UI.HtmlControls.HtmlForm
{
protected override void RenderAttributes(HtmlTextWriter writer)
{
writer.WriteAttribute("name", this.Name);
base.Attributes.Remove("name");

writer.WriteAttribute("method", this.Method);
base.Attributes.Remove("method");

this.Attributes.Render(writer);

base.Attributes.Remove("action");

if (base.ID != null)
writer.WriteAttribute("id", base.ClientID);
}
}
}

I have registered it in my ASPX page. It looks like this.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<%@ Register TagPrefix="ca" Namespace="ComIT.Applications.Common"
Assembly="ComIT.Applications.Common" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title id="PageTitle" runat="server">Default</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="imagetoolbar" content="no" />
</head>
<body>
<ca:Form id="form1" method="post" runat="server">
</ca:Form>
</body>
</html>

When I switch my ASPX page to design mode, it shows following error.

Unable to cast object of type
'System.Web.Ui.Design.HtmlIntrinsicControlDesigner' to type
'System.Web.Ui.Design.ControlDesigner'.


Why is this error coming? Am I doing anything wrong?


Thanks in advanced.


Tabi
 
Well, my first question would have to be, why do you want to do this at all?
You are breaking the object model of a WebForm by doing so.

The exception seems to indicate that the Designer for an HtmlForm is running
into a problem with your override. Designers use various methods of the
Controls they design, particularly those methods which render the Control in
the Page, to render the Control at design-time. As I have no way of peeking
inside the Designer code for the HtmlForm Control, that is all I can say.
But it does beg the question I started with.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
Hi Tabi,

My apologies. You are correct. In any case, if you're having problems with
the Designer, I think you will have to write a custom Designer for your
form, or don't switch to Design view. It's the Designer that is throwing an
exception.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
Back
Top