Programatically change form action value?
-
Can anyone tell me how to programatically change the html form action value? For example, my page has this form.
I want to change the action value. I have tried this... HtmlForm objForm = (HtmlForm)Page.Controls[1]; which gets me a handle for the form, but I can see no value that will allow me to change the action. Thanks in advance - Dave.
-
Can anyone tell me how to programatically change the html form action value? For example, my page has this form.
I want to change the action value. I have tried this... HtmlForm objForm = (HtmlForm)Page.Controls[1]; which gets me a handle for the form, but I can see no value that will allow me to change the action. Thanks in advance - Dave.
Hi Dave, Even you use the
HtmlForm.Attributes
property to add theaction
value, it'll still be removed in theRenderAttributes
method. There are a couple of options here, you can use the client side code to change theaction
value of theform
element by creating an event handler for theonload
event of thebody
element. Or you can create your own custom html form control by overriding theRenderAttributes
method, there's an example posted here on CP http://www.codeproject.com/aspnet/CHtmlForm.asp[^]. However, you also need to consider theViewState
issue when submit the page to another one. -
Hi Dave, Even you use the
HtmlForm.Attributes
property to add theaction
value, it'll still be removed in theRenderAttributes
method. There are a couple of options here, you can use the client side code to change theaction
value of theform
element by creating an event handler for theonload
event of thebody
element. Or you can create your own custom html form control by overriding theRenderAttributes
method, there's an example posted here on CP http://www.codeproject.com/aspnet/CHtmlForm.asp[^]. However, you also need to consider theViewState
issue when submit the page to another one.Thanks for that valuable information. I would never have guessed! I've been wrestling with dot net for the last 8 months (many hours every day) and I still have to fight it every inch of the way unless I want to do 'hello world' level programs. I sometimes spend weeks doing what I could have done in VS6 in hours! I do like VS7 but find it very complicated still and hope that I don't starve to death before that time comes. (Are you listening Mr Gates???):((
-
Thanks for that valuable information. I would never have guessed! I've been wrestling with dot net for the last 8 months (many hours every day) and I still have to fight it every inch of the way unless I want to do 'hello world' level programs. I sometimes spend weeks doing what I could have done in VS6 in hours! I do like VS7 but find it very complicated still and hope that I don't starve to death before that time comes. (Are you listening Mr Gates???):((