Modifying form action attribute

D

Dilip

Hi

Is there a way to modify the action attribute of a form just before the
initial GET for that page renders the HTML?

I have a case where I do a GET on a URL like so:
http://www.somewebsite.com/mydisplay.aspx?somequerystring=0

This page renders like this:

<form method="post" action="mydisplay.aspx?somequerystring=0"
</form>

What I want is the page to be rendered as usual but before that I need
to modify the action attribute to point to something else (actually i
need to change the querystrings in the action URL). I have been
looking into MSDN but I think I may not be on the right path. Any
pointers are greatly appreciated.

thanks!
 
V

vMike

Dilip said:
Hi

Is there a way to modify the action attribute of a form just before the
initial GET for that page renders the HTML?

I have a case where I do a GET on a URL like so:
http://www.somewebsite.com/mydisplay.aspx?somequerystring=0

This page renders like this:

<form method="post" action="mydisplay.aspx?somequerystring=0"
</form>

What I want is the page to be rendered as usual but before that I need
to modify the action attribute to point to something else (actually i
need to change the querystrings in the action URL). I have been
looking into MSDN but I think I may not be on the right path. Any
pointers are greatly appreciated.

thanks!
Look into overriding the page render as follows.

Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)

Dim _stringBuilder As StringBuilder = New StringBuilder()
Dim _stringWriter As StringWriter = New StringWriter(_stringBuilder)
Dim _htmlWriter As HtmlTextWriter = New HtmlTextWriter(_stringWriter)
MyBase.Render(_htmlWriter)

' at this point _stringBuilder contains the html that will be rendered
'you then manipulate _stringBuilder. when done you write it back out

writer.Write(_stringBuilder.tostring())

End Sub

Of course if the page isn't posting back to itself, its state will be all
messed up I think. Another method, if you are just adding a simple secondary
form to a webpage is to build the html for the form by hand in a literal
control and add it to a placeholder using .. plcID.controls.add(new
literalcontrol(formshtmltextasstringbuilder.tostring())) This must be done
outside of any forms with runat tags.

Mike
 
I

intrader

Hi

Is there a way to modify the action attribute of a form just before the
initial GET for that page renders the HTML?

I have a case where I do a GET on a URL like so:
http://www.somewebsite.com/mydisplay.aspx?somequerystring=0

This page renders like this:

<form method="post" action="mydisplay.aspx?somequerystring=0"
</form>

What I want is the page to be rendered as usual but before that I need
to modify the action attribute to point to something else (actually i
need to change the querystrings in the action URL). I have been
looking into MSDN but I think I may not be on the right path. Any
pointers are greatly appreciated.

thanks!
You can do myform.action = yoururl at the client as soon as the page loads
(on the onload event).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top