473,326 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to overwrite the FORM ACTION attribute

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

Dec 27 '06 #1
4 3090
What are you trying to achieve?
Patrick

<ww*****@gmx.chwrote in message
news:11*********************@h40g2000cwb.googlegro ups.com...
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

Dec 28 '06 #2
Thus wrote ww*****@gmx.ch,
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
ne********@joergjooss.de
Jan 2 '07 #3
Joerg Jooss wrote:
Thus wrote ww*****@gmx.ch,
>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)



Jan 3 '07 #4
in an older 1.1 app we used response filter and some regex to do this


"Joe (MCAD)" <jo***************@yahoo.comwrote in message
news:EV*******************@newssvr25.news.prodigy. net...
Joerg Jooss wrote:
>Thus wrote ww*****@gmx.ch,
>>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)





Jan 3 '07 #5

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

Similar topics

4
by: Bruce Duncan | last post by:
I'm new to PHP...and my previous post was a bit premature. I've narrowed my problem down to this: I have this very simple form in test1.php <form name='formx6' action="testz.php?varxy=1">...
13
by: dogu | last post by:
Noob alert. Code is below. File is saved as a .php. What I'm trying to do: User uses 'select' box drop down list to pick a value. Value ($site) is derived from a db query. This works fine....
2
by: chris | last post by:
hi, i am tinkering with properties of new style classes: class Base(object): def m(self): return 'p of Base' p = property(m) class Sub(Base):
4
by: Sarah | last post by:
Hi all. I have a form, and several text and image links on it that should submit the form with different actions. I prepared a simple page with just the code that's not working. PROBLEM:...
5
by: Jan Gregor | last post by:
Hello I want to change attribute action in form. Problem is that in that form is also input with name action. Unfortunately renaming of that input is worst case because many servlets depend on...
10
by: iam247 | last post by:
Hi In my prototype asp page (with no javascript and no password validation, I have a registration form with the following action: <form name="form" method="post" action="RegDetails.asp"> ...
2
by: belgie | last post by:
Whereas in Asp I could submit my form contents to any other Asp page, it appears that in Asp.NET the primary Asp form will only submit to itself. I have tried changing the Action attribute in the...
3
by: Don Parker | last post by:
I am a newbie to ASP.NET. I am converting some asp pages I had working. I have a page which has a form with several input elements. When the user clicks on a Submit element - the action specified...
4
by: Roshawn | last post by:
Hi, I have a web page that contains an html form and has a few controls in it. The html form and its controls are all server controls. However, I've set the enableViewState attribute of the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.