user3123769
user3123769

Reputation: 21

asp.net <form> tag getting stripped out of asp:literal

Okay... I know having nested tags is not officially supported. But stay with me on this one..

I have an ASP.NET web page with the standard <form runat=server> tag at the top. I am pulling in a Form (and associated fields) from a 3rd party source via HttpWebRequest on the server side (code behind). I can verify the data I get contains a <form> tag -- via a Trace statement. Then I assign the data to my literal like this:


    Dim objRequest As System.Net.HttpWebRequest = System.Net.WebRequest.Create(url)
    Dim objResponse As System.Net.WebResponse
    objRequest.Method = "POST"
    Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData.ToString)
    objRequest.ContentType = "application/x-www-form-urlencoded"
    objRequest.ContentLength = byteArray.Length
    Dim dataStream As Stream = objRequest.GetRequestStream()
    dataStream.Write(byteArray, 0, byteArray.Length)
    dataStream.Close()


    objResponse = objRequest.GetResponse()
    Dim streamRead As New StreamReader(objResponse.GetResponseStream())
    Dim strResponse As String = streamRead.ReadToEnd()

    me.litCMSForm.Text = strResponse

When the page is rendered, somehow .NET removed the <form> tag that was within the literal.

I also tried assigning the variable "strResponse" to a public variable to be displayed and it too had the tag stripped out. And I tried assigning the variable to an asp:Label as well with no luck. And I tried assigning the value to the literal on the "PreRender" function with no success.

Any thoughts on this and why .NET is stripping out the <form> tag?

Thanks!

Upvotes: 2

Views: 589

Answers (2)

Brett
Brett

Reputation: 256

I had the same problem. I was able to work around the situation by adding another form before the one I really wanted to insert. It seems like ASP was only frisky enough to strip out the first firm it found. Perhaps this would work for you:

me.litCMSForm.Text = "<form name='fakeOut'></form>" + strResponse

I actually had my form code be a little fancier (I gave it an action and an hidden input). I didn't continue to test to see what could be taken away because it worked.

Upvotes: 1

suff trek
suff trek

Reputation: 39767

You're correct - nested form tags are not supported. What you can do is generate JavaScript that would pass the string to an HTML container outside of ASP.NET form or, better yet, output it to an independent iframe.

Upvotes: 1

Related Questions