1

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?

2 Answers 2

1

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">
Sign up to request clarification or add additional context in comments.

3 Comments

How can I put the code in the codebehind page? When I do it I get an error
@NaveTseva works fine here, with the exact same line as first line of page_load. What is the error you get ?
@NaveTseva might be many reasons, because the form is not available at that moment ( in a usercontrol, added dynamically, with an ancestor or itself being Visible=false, ...)
1

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.

1 Comment

Compared to other controls, Form has a special status : msdn.microsoft.com/en-us/library/system.web.ui.page.form.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.