How to assign Action property to the Form

P

Peter Afonin

Hello,

In my application on the Webform I need to assign an action property to the
form in code, because the URL is a variable.

In MSDN there is an example - everything is simple:

Form1.Action=URL

However, this applies only to the Mobile controls. How can I do it in the
regular Webform?

I would appreciate your help.

Thank you,
 
E

Eliyahu Goldin

Peter,

You can emit javascript code assigning action property to the form from
server side:

Response.Write("<script language='Javascript'>");
Response.Write(String.Format("myForm.action={0}",myUrl);
Response.Write("</script>");

This might not work since the document object model might not be built at
the loading time.
I think, the following should work:

Response.Write("<script language='Javascript'>");
Response.Write(String.Format("document.getElementById('myForm').action={0}",
myUrl);
Response.Write("</script>");

In any case, this should work always:

In the html view set <body onload="onLoad()"> and make onLoad() on fly as
Response.Write("<script language='Javascript'>");
Response.Write(String.Format("function onLoad(){myForm.action={0};}",myUrl);
Response.Write("</script>");

Eliyahu
 
P

Peter Afonin

Thank you very much, Eliyahu. I'll give it a try.

Peter

Eliyahu Goldin said:
Peter,

You can emit javascript code assigning action property to the form from
server side:

Response.Write("<script language='Javascript'>");
Response.Write(String.Format("myForm.action={0}",myUrl);
Response.Write("</script>");

This might not work since the document object model might not be built at
the loading time.
I think, the following should work:

Response.Write("<script language='Javascript'>");
Response.Write(String.Format("document.getElementById('myForm').action={0}",
myUrl);
Response.Write("</script>");

In any case, this should work always:

In the html view set <body onload="onLoad()"> and make onLoad() on fly as
Response.Write("<script language='Javascript'>");
Response.Write(String.Format("function onLoad(){myForm.action={0};}",myUrl);
Response.Write("</script>");

Eliyahu
 
G

Guest

You may wanna implement a Front Controller pattern on the server. My personal
opinion, that injecting a client code that would (potentially) expose your
inner logic to a client is a bad idea.

So, refer to Microsoft Enterprise Solution Patterns book (obtained online)
for implementation of the mentioned pattern (again, Front Controller).
Basically, the idea is to first, determine, what type of client you're
dealing with, and then using server.transfer() redirect the execution to a
more proper page/logic.

Hope this would be helpful for your work.

Andrew.

Eliyahu Goldin said:
Peter,

You can emit javascript code assigning action property to the form from
server side:

Response.Write("<script language='Javascript'>");
Response.Write(String.Format("myForm.action={0}",myUrl);
Response.Write("</script>");

This might not work since the document object model might not be built at
the loading time.
I think, the following should work:

Response.Write("<script language='Javascript'>");
Response.Write(String.Format("document.getElementById('myForm').action={0}",
myUrl);
Response.Write("</script>");

In any case, this should work always:

In the html view set <body onload="onLoad()"> and make onLoad() on fly as
Response.Write("<script language='Javascript'>");
Response.Write(String.Format("function onLoad(){myForm.action={0};}",myUrl);
Response.Write("</script>");

Eliyahu
 
P

Peter Afonin

Thank you, Andrew.

Peter

Andrew_Revinsky said:
You may wanna implement a Front Controller pattern on the server. My personal
opinion, that injecting a client code that would (potentially) expose your
inner logic to a client is a bad idea.

So, refer to Microsoft Enterprise Solution Patterns book (obtained online)
for implementation of the mentioned pattern (again, Front Controller).
Basically, the idea is to first, determine, what type of client you're
dealing with, and then using server.transfer() redirect the execution to a
more proper page/logic.

Hope this would be helpful for your work.

Andrew.
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top