Connecting Tech Pros Worldwide Help | Site Map

How to overwrite the FORM ACTION attribute

wwwmike@gmx.ch
Guest
 
Posts: n/a
#1: Dec 27 '06
How can I overwrite the <FORM action=attribute?

I can add new attributes with

Dim xx As System.Web.UI.HtmlControls.HtmlForm
xx = Page.FindControl("form1")
xx.Attributes.Add("something", "POST")

....but I can not overwrite the action attribute like (Page.Load event)

xx.Attributes.Add("action", "http://www.somewhere")

this also does not work

xx.Attributes("action") = "http://www.somewhere"

Thanks for helping

Patrick.O.Ige
Guest
 
Posts: n/a
#2: Dec 28 '06

re: How to overwrite the FORM ACTION attribute


What are you trying to achieve?
Patrick

<wwwmike@gmx.chwrote in message
news:1167260838.394553.18200@h40g2000cwb.googlegro ups.com...
Quote:
How can I overwrite the <FORM action=attribute?
>
I can add new attributes with
>
Dim xx As System.Web.UI.HtmlControls.HtmlForm
xx = Page.FindControl("form1")
xx.Attributes.Add("something", "POST")
>
...but I can not overwrite the action attribute like (Page.Load event)
>
xx.Attributes.Add("action", "http://www.somewhere")
>
this also does not work
>
xx.Attributes("action") = "http://www.somewhere"
>
Thanks for helping
>

Joerg Jooss
Guest
 
Posts: n/a
#3: Jan 2 '07

re: How to overwrite the FORM ACTION attribute


Thus wrote wwwmike@gmx.ch,
Quote:
How can I overwrite the <FORM action=attribute?
>
I can add new attributes with
>
Dim xx As System.Web.UI.HtmlControls.HtmlForm
xx = Page.FindControl("form1")
xx.Attributes.Add("something", "POST")
...but I can not overwrite the action attribute like (Page.Load
event)
>
xx.Attributes.Add("action", "http://www.somewhere")
>
this also does not work
>
xx.Attributes("action") = "http://www.somewhere"
Each ASP.NET Page either posts back to itself or to the URL specified by
the PostbackUrl property of an IButtonControl. You cannot set the action
attribute manually in server-side code.

Cheers,
--
Joerg Jooss
news-reply@joergjooss.de


Joe (MCAD)
Guest
 
Posts: n/a
#4: Jan 3 '07

re: How to overwrite the FORM ACTION attribute


Joerg Jooss wrote:
Quote:
Thus wrote wwwmike@gmx.ch,
>
Quote:
>How can I overwrite the <FORM action=attribute?
>>
>I can add new attributes with
>>
>Dim xx As System.Web.UI.HtmlControls.HtmlForm
>xx = Page.FindControl("form1")
>xx.Attributes.Add("something", "POST")
>...but I can not overwrite the action attribute like (Page.Load
>event)
>>
>xx.Attributes.Add("action", "http://www.somewhere")
>>
>this also does not work
>>
>xx.Attributes("action") = "http://www.somewhere"
>
Each ASP.NET Page either posts back to itself or to the URL specified by
the PostbackUrl property of an IButtonControl. You cannot set the action
attribute manually in server-side code.
>
Cheers,
Using trusty reflector, here is the code from the FORM class...

protected override void RenderAttributes(HtmlTextWriter writer)
{
....
writer.WriteAttribute("method", this.Method);
base.Attributes.Remove("method");
writer.WriteAttribute("action", this.GetActionAttribute(), true);
base.Attributes.Remove("action");
....
}
base.EnsureID();
base.RenderAttributes(writer);
}

What we see is that this class is not marked as sealed (YEA!) and that
the action comes from the GetActionAttribute which isnt marked as
virtual (BOOO!) and private (BOOO!). 2 BOOO's outweigh 1 YEA, i.e. MS in
their infinite wisdom decided that you really don't want to be able to
do this. This would be a very good argument on why the web controls
should be open source.

As stated above, the postbackURL is a way to bypass this mechanism. Here
is the code in the framework to do this in the button control...
protected virtual PostBackOptions GetPostBackOptions()
{
PostBackOptions options1 = new PostBackOptions(this, string.Empty);
options1.ClientSubmit = false;
if (this.Page != null)
{
if (this.CausesValidation &&
(this.Page.GetValidators(this.ValidationGroup).Cou nt 0))
{
options1.PerformValidation = true;
options1.ValidationGroup = this.ValidationGroup;
}
if (!string.IsNullOrEmpty(this.PostBackUrl))
{
options1.ActionUrl =
HttpUtility.UrlPathEncode(base.ResolveClientUrl(th is.PostBackUrl));
}
options1.ClientSubmit = !this.UseSubmitBehavior;
}
return options1;
}

The output from this class is then registered with
public string
Page.ClientScript.GetPostBackEventReference(PostBa ckOptions options,
bool registerForEventValidation)
which will behind the scene change the action attribute for you. I
believe this is the way .NET wants to enforce this kind of functionality
is because you can have multiple forms and such on a page AND within
anyone of those forms you can postback to multiple pages. Here is a blog
entry on how to get this to work...
http://fredrik.nsquared2.com/viewpost.aspx?PostID=222


But then again, this isnt exactly what you were looking for. If you must
change the form action attribute there are two ways.
1. easy way. use javascript on the body's onLoad event and change it there.
2. hard way. capture the output of the rendering before being sent
across and parse it out.

Joe (MCAD)











gerry
Guest
 
Posts: n/a
#5: Jan 3 '07

re: How to overwrite the FORM ACTION attribute


in an older 1.1 app we used response filter and some regex to do this




"Joe (MCAD)" <joe_c_miguel-news@yahoo.comwrote in message
news:EVImh.42068$wc5.23152@newssvr25.news.prodigy. net...
Quote:
Joerg Jooss wrote:
Quote:
>Thus wrote wwwmike@gmx.ch,
>>
Quote:
>>How can I overwrite the <FORM action=attribute?
>>>
>>I can add new attributes with
>>>
>>Dim xx As System.Web.UI.HtmlControls.HtmlForm
>>xx = Page.FindControl("form1")
>>xx.Attributes.Add("something", "POST")
>>...but I can not overwrite the action attribute like (Page.Load
>>event)
>>>
>>xx.Attributes.Add("action", "http://www.somewhere")
>>>
>>this also does not work
>>>
>>xx.Attributes("action") = "http://www.somewhere"
>>
>Each ASP.NET Page either posts back to itself or to the URL specified by
>the PostbackUrl property of an IButtonControl. You cannot set the action
>attribute manually in server-side code.
>>
>Cheers,
>
Using trusty reflector, here is the code from the FORM class...
>
protected override void RenderAttributes(HtmlTextWriter writer)
{
...
writer.WriteAttribute("method", this.Method);
base.Attributes.Remove("method");
writer.WriteAttribute("action", this.GetActionAttribute(), true);
base.Attributes.Remove("action");
...
}
base.EnsureID();
base.RenderAttributes(writer);
}
>
What we see is that this class is not marked as sealed (YEA!) and that the
action comes from the GetActionAttribute which isnt marked as virtual
(BOOO!) and private (BOOO!). 2 BOOO's outweigh 1 YEA, i.e. MS in their
infinite wisdom decided that you really don't want to be able to do this.
This would be a very good argument on why the web controls should be open
source.
>
As stated above, the postbackURL is a way to bypass this mechanism. Here
is the code in the framework to do this in the button control...
protected virtual PostBackOptions GetPostBackOptions()
{
PostBackOptions options1 = new PostBackOptions(this, string.Empty);
options1.ClientSubmit = false;
if (this.Page != null)
{
if (this.CausesValidation &&
(this.Page.GetValidators(this.ValidationGroup).Cou nt 0))
{
options1.PerformValidation = true;
options1.ValidationGroup = this.ValidationGroup;
}
if (!string.IsNullOrEmpty(this.PostBackUrl))
{
options1.ActionUrl =
HttpUtility.UrlPathEncode(base.ResolveClientUrl(th is.PostBackUrl));
}
options1.ClientSubmit = !this.UseSubmitBehavior;
}
return options1;
}
>
The output from this class is then registered with
public string Page.ClientScript.GetPostBackEventReference(PostBa ckOptions
options, bool registerForEventValidation)
which will behind the scene change the action attribute for you. I believe
this is the way .NET wants to enforce this kind of functionality is
because you can have multiple forms and such on a page AND within anyone
of those forms you can postback to multiple pages. Here is a blog entry on
how to get this to work...
http://fredrik.nsquared2.com/viewpost.aspx?PostID=222
>
>
But then again, this isnt exactly what you were looking for. If you must
change the form action attribute there are two ways.
1. easy way. use javascript on the body's onLoad event and change it
there.
2. hard way. capture the output of the rendering before being sent across
and parse it out.
>
Joe (MCAD)
>
>
>
>
>
>
>
>
>
>
>

Closed Thread