![]() |
|
|
|||||||
![]() |
ASP Net - Creating custom form in Asp.NET 2.0 |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 =?Utf-8?B?VGFiaQ==?= |
|
|
|
|
#2 |
|
Posts: n/a
|
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. "Tabi" <> wrote in message news:9843FDFA-48AB-4842-A67A-... > 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 > |
|
|
|
#3 |
|
Posts: n/a
|
Dear Kevin,
Thanks for answer. I am actually using url rewriting as described at msdn http://msdn.microsoft.com/library/de...lrewriting.asp Please check out the "Handling Postbacks" section. I am using 100% same code. The problem is that this code does not work in asp.net 2.0. Is there any other way to work around this in asp.net 2.0? Thanx once again. Tabi "Kevin Spencer" wrote: > 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. > > "Tabi" <> wrote in message > news:9843FDFA-48AB-4842-A67A-... > > 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 > > > > > |
|
|
|
#4 |
|
Posts: n/a
|
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. "Tabi" <> wrote in message news:3550CA34-609D-46D7-8DAA-... > Dear Kevin, > > Thanks for answer. I am actually using url rewriting as described at msdn > http://msdn.microsoft.com/library/de...lrewriting.asp > > Please check out the "Handling Postbacks" section. I am using 100% same > code. The problem is that this code does not work in asp.net 2.0. > > Is there any other way to work around this in asp.net 2.0? > > Thanx once again. > > Tabi > > > "Kevin Spencer" wrote: > >> 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. >> >> "Tabi" <> wrote in message >> news:9843FDFA-48AB-4842-A67A-... >> > 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 >> > >> >> >> |
|
|
|
#5 |
|
Junior Member
Join Date: Mar 2007
Posts: 1
|
Hello, I'm also having the same trouble with Designer for the ActionlessForm. Did you find a solution?
Thanks! |
|
|
|
|
|
#6 |
|
Junior Member
Join Date: Apr 2008
Posts: 1
|
did anybody have solution for that?
|
|
|
|