Nave Tseva
Nave Tseva

Reputation: 878

Create form action as variable

I have t following ASPX source :

  <form name="AddComment" action="ViewArticle.aspx?ArticleID=<%=ArticleID %>" method="post" runat="server">

The problem is that when I click submit I got this url

http://localhost:61175/WebSite1/ViewArticle.aspx?ArticleID=%3C%=ArticleID%20%%3E

But I want get this URL :

http://localhost:61175/WebSite1/ViewArticle.aspx?ArticleID=1

If I delete the "runat="server"" command it works fine, but can this form work with the variable and the runat server at the same time?

Upvotes: 1

Views: 881

Answers (2)

nBalu
nBalu

Reputation: 76

In server side controls you can't do such things as <%= ActionID %> you can only bind <%# ActionID %>.

The upper solution won't work, becouse the form is not that form. You have to give a control ID + name than setup the post url. If it's not an option you can dinamicly search for form item in the control tree, so dynamic ID-s can be handled.

Upvotes: 1

jbl
jbl

Reputation: 15413

Maybe you can try setting the action just before the form markup like this (or in codebehind, at your choice)

 <%
     this.Form.Action = "ViewArticle.aspx?ArticleID=" + ArticleID.ToString();
 %>
 <form name="AddComment"  method="post" runat="server">

Upvotes: 1

Related Questions