Question

In .NET by default the client side ID's, for server side controls, get concatenated with generated text.

For example:

<asp:TextBox ID="txtUser" runat="server">

would become...

<input type="text" id="ctl00_body_txbUser">

However when I use HttpWebRequest.GetResponse(objReq.Getresponse, HttpWebResponse) to request the same page the item comes back without the auto generated text.

<input type="text" id="txbUser">

Is it possible to use an HttpWebRequest object and GetResponse in such a way that it returns a response with the Auto generated ID's .NET uses for server side controls?

I am working with a 3rd party that has previously set up translation rules specific to ID, now we are attempting have the same rules work against an API call passed a string generated from the page. However, the string generated from the page does not have the same IDs.

Below is code being used to return the Web Page as a string.

Public Shared Function GetWebPageAsString(ByVal strURI As String, ByVal strPostData As String) As String
    ' Declare our variables. '
    Dim objHttpRequest As HttpWebRequest
    Dim PostBuffer() As Byte
    Dim PostDataStream As Stream = Nothing
    Dim objHttpResponse As HttpWebResponse = Nothing
    Dim objStreamReader As StreamReader = Nothing
    Dim strResponseText As String = ""
    Try
        ' Create a new request. '
        objHttpRequest = CType(WebRequest.Create(strURI), HttpWebRequest)
        objHttpRequest.Timeout = 3000000
        objHttpRequest.Method = "POST"
        PostBuffer = Encoding.ASCII.GetBytes(strPostData)
        objHttpRequest.ContentType = "application/x-www-form-urlencoded"
        objHttpRequest.ContentLength = PostBuffer.Length
        PostDataStream = objHttpRequest.GetRequestStream
        PostDataStream.Write(PostBuffer, 0, PostBuffer.Length)
        PostDataStream.Close()
        ' Get the response to our request as a stream object. '
        objHttpResponse = CType(objHttpRequest.GetResponse, HttpWebResponse)
        ' Create a stream reader to read the data from the stream. '
        objStreamReader = New StreamReader(objHttpResponse.GetResponseStream, Encoding.UTF8)
        ' Copy the text retrieved from the stream to a variable. '
        strResponseText = objStreamReader.ReadToEnd()
        ' Close our objects. '
        objStreamReader.Close()
        objHttpResponse.Close()
    Catch ex As Exception
        strResponseText = strURI & " | " & strPostData
        Throw (ex)
    Finally
        If Not objStreamReader Is Nothing Then
            objStreamReader.Close()
        End If
        If Not PostDataStream Is Nothing Then
            PostDataStream.Close()
        End If
        If Not objHttpResponse Is Nothing Then
            objHttpResponse.Close()
        End If
        objHttpRequest = Nothing
        PostBuffer = Nothing
        PostDataStream = Nothing
        objHttpResponse = Nothing
        objStreamReader = Nothing
    End Try
    ' Set return value. '
    Return strResponseText
End Function

EDIT: Just to Clarify, I need the IDs to continue to be Auto generated by .NET. I understand that I could make them equal by setting the mode to Static. Unfortunately the 3rd Party we are working with has already created the rules for our current pages based on the IDs that were generated by .NET. Requesting the same page using the HTTPRequest object and pushing data into a stream. I am not seeing the Auto Generated IDs anymore, even though its the same page.

Was it helpful?

Solution

Create a clean master page and put your page in it. That should fix the IDs issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top