what is difference between Response.write and Response.output.write please give me example
Response.Output.Write allows you to format the string before outputting, Response.Write simply writes it out as is.
Response.Write will output exactly what you pass in.
Response.Output exposes the underlying TextWriter, so Response.Output.Write has many more overloads, some with String.Format functionality.
There is no difference. Response.Write is a convenience accessor to Response.Output.Write.
You could have found out this by yourself if you installed reflector and looked up the class HttpResponse (in the assembly System.Web).
Related
I have the following request using ajax (simplified):
<asp:TextBox ID="DealNumber" runat="server" Width="100px" ToolTip="Deal (aka OPG)">
</asp:TextBox>
<Ajax:AutoCompleteExtender
ID="AutoCompleteExtender2"
runat="server"
TargetControlID="DealNumber"
ServiceMethod="GetDealNumberList"
ServicePath="/ws/WebServices.asmx"/>
and on /ws/WebServices.asmx (sorry my .VB):
<System.Web.Script.Services.ScriptMethod(UseHttpGet:=True)>
<System.Web.Services.WebMethod>
Public Function GetDealNumberList(prefixText As String, count As Integer, contextKey As String) As System.String()
return {"Test " & PrefixText & " " & ContextKey}
end function
Now, doing the typical F12 network trace, ajax reports:
Invalid method name 'getdealnumberlist', method names are case sensitive. The method name 'GetWTNumberList' with the same name but different casing was found.
Who and why the casing is changed? If I modify my .asmx works as intended.
Not sure what exactly causing the problem, but I experienced this issue long time ago while still using webforms page and AJAX callback to return something from web service (ASMX). I fixed this issue by putting MessageName property with method name in lowercase inside WebMethodAttribute like this example:
<ScriptMethod(UseHttpGet:=True)>
<WebMethod(MessageName:="getdealnumberlist")>
Public Function GetDealNumberList(prefixText As String, count As Integer, contextKey As String) As String()
Return {"Test " & PrefixText & " " & ContextKey}
End Function
This problem also sometimes occurred when the web service methods are tested directly, e.g. by entering URL like http://localhost:XXXX/path/to/webservicename.asmx/GetDealNumberList.
In this annoying issue, I found the answer and it was very trivial.
In Visual Studio, when using Option Compare Binary Option Compare Text I was under the impression that will only affect code generation. I was wrong. Not sure what is the method to create the intermediate code for Web Services and/or AJAX, but, adding Option Compare Text fix the camel issue.
I personally think this is a (survivable) bug.
i'm trying to do an do while with this code:
<%
dim i
i=0
Do While i < 19
response.Write "<th>" & data1.standing.[i].position & "</th>"
i=i+1
Loop
%>
this come from a api call, is a json response, and data1.standing.[in].position is the way to extract the position of a soccer team: url :link
but this section [i] don't iterate.
any clue?
sorry for the bad english.
Looking at your code I suspect you're actually trying to use JScript, not VBScript as I assumed.
An example of how to gather the JSON string into a variable in VBScript:
dim objXML
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXML.open "GET", "http://api.football- data.org/v1/competitions/398/leagueTable", False
objXML.send
Response.Write objXML.responseText
Take a look at this post for an excellent example of how to do what you're looking for. Any good libraries for parsing JSON in Classic ASP?
You can use my code to GET the string, then the link to parse and use it.
When I run this:
<%
www = false
response.write www
response.write "UPDATE table SET domain='"&www&"' WHERE id=n"
%>
I get this:
false
UPDATE table SET domain='Falso' WHERE id=n
Notice the 'Falso' word that is in Portuguese instead of English.
Is it possible to change the boolean values to English?
I have a Windows 2008 / IIS 7 in pt-BR.
This question was asked just recently here
I don't have a good machine to test the following code, which came from a working solution. It forces the locality you need (of course you can change the locality to what you need it to be, if 1033 is not your goal)
<%
Response.Write FormatDateTime(Now) & "<br />"
oldLocale = SetLocale(1033) '1033=English(US)
Response.Write FormatDateTime(Now) & "<br />"
SetLocale oldLocale
Response.Write FormatDateTime(Now) & "<br />"
%>
I'll not be able to provide any more testing for this 'issue' anymore.
That's because I've made a decision to format my windows and install a new one now in english.. I did this because I'm running out of time, I need to put this server working as soon as possible..
But I want to thank everyone who contributed on finding the resolution for this problem =)
If anyone is having the same issue, please leave your comment, so the others can provide more options to try to solve this.
If you dont mind changing the code, you could use a function to print the boolean value. For me thats not an option, but i'm starting to believe its the only way.
Function PB(pVal)
If pVal Then
PB = "true"
Else
PB = "false"
End If
End Function
Response.Write "UPDATE table SET domain='"&PD(www)&"' WHERE id=n"
Just use string instead:
www = "false"
Then it won't be affected by regional settings.
If you want to keep working with actual boolean values, use Parameters instead of raw SQL.
I've .NET webservice, which takes a encoded html-string as a parameter, decodes the string and creates a PDF from the html. I want to make a synchronous server side call to the webservice from a classic asp webpage. It works fine if use a plain text string (with no html tags), but when I send a encoded html string the webservice it seems that the string is empty when it reaches the webservice.
The webservice is working fine when I call it from client side, with both plain text string and an encoded html string.
My code looks like this:
Private Sub SaveBookHtmlToPdf(pHtml, pShopId)
Set oXMLHTTP = CreateObject("Msxml2.ServerXMLHTTP.6.0")
Dim strEnvelope
strEnvelope = "pShopId=" & pShopId & "&pEncodedHtml=" & Server.HTMLEncode(pHtml)
Call oXMLHTTP.Open("POST", "https://mydomain.dk:4430/PdfWebservice.asmx/SaveBookToPdf", false)
Call oXMLHTTP.SetRequestHeader("Content-Type","application/x-www-form-urlencoded")
Call oXMLHTTP.Send(strEnvelope)
Set oXMLHTTP = Nothing
End Sub
It smells like some kind of security issue on the server. It's working when posting a asynchronous call from the client side, but not when it comes from server side - it seems that the encoded html string is somehow not allowed in a server side call to the webservice.
Anyone who know how to solve this tricky problem?
This looks all wrong to me:
Server.HTMLEncode(pHtml)
Its quite common for developers to get confused between HTML encoding and URL encoding even though they are quite different. You are posting data that needs to be URL encoded. Hence your code should use URLEncode instead:
strEnvelope = "pShopId=" & pShopId & "&pEncodedHtml=" & Server.URLEncode(pHtml)
Edit:
One thing that URLEncode does that may not be compatible with a URLEncoded post is it converts space to "+" instead of "%20". Hence a more robust approach might be:
strEnvelope = "pShopId=" & pShopId & "&pEncodedHtml=" & Replace(Server.URLEncode(pHtml), "+", "%20")
Another issue to watch out for is that the current value of Response.CodePage will influence how the URLEncode encodes non-ASCII characters. Typically .NET does things by default in UTF-8. Hence you will also want to make sure that your Response.CodePage is set to 65001.
Response.CodePage = 65001
strEnvelope = "pShopId=" & pShopId & "&pEncodedHtml=" & Replace(Server.URLEncode(pHtml), "+", "%20")
This may or may not help but I use a handy SOAP Class for Classic ASP which solved a few problems I was having doing it manually. Your code would be something like this:
Set cSOAP = new SOAP
cSOAP.SOAP_StartRequest "https://mydomain.dk:4430/PdfWebservice.asmx", "", "SaveBookToPdf"
cSOAP.SOAP_AddParameter "pShopId", pShopId
cSOAP.SOAP_AddParameter "pEncodedHtml", Server.HTMLEncode(pHtml)
cSOAP.SOAP_SendRequest
' result = cSOAP.SOAP_GetResult("result")
You will probably need to set your namespace for it to work ("" currently), and uncomment the 'on error resume next' lines from the class to show errors.
AnthonyWJones made the point about URL encoding and HTML encoding, and the original problem being experienced is likely a combine of the two, a race condition if you will. While is was considered answered, it partially wasn't, and hopefully this answers the cause of the effect.
So, as the message get HTMLEncoded, the html entities for the tags become such '<' = '<'.
And as you may know, in URLEncoding, &'s delimit parameters; thus the first part of this data strEnvelope = "pShopId=" & pShopId & "&pEncodedHtml=" & Server.HTMLEncode(pHtml) upto the "&pEncodedHtml" bit, is fine. But then "<HTML>..." is added as the message, with unencoded &'s...and the receiving server likely is delimiting on them and basically truncating "&pEncodedHtml=" as a null assign: "&pEncodedHtml=<HTML>... ." The delimiting would be done on all &'s found in the URL.
So, as far as the server is concerned, the data for parameter &pEncodedHtml was null, and following it were now several other parameters that were considered cruft, that it likely ignored, which just happened to actually be your message.
Hope this provides additional info on issues of its like, and how to correct.
I'm declaring a string variable this way in classic ASP:
Dim i As String
And getting this error:
Microsoft VBScript compilation error '800a0401'
Expected end of statement
/retencion/Estadisticas/Detail.asp, line 10, column 6
Dim i As String
-----^
Why is that?
Classic ASP is written in VBScript and isn't Visual Basic itself, so you can't declare things as strings. Loosely typed I think is the phrase to describe it. Basically, you have to leave out the "as" and anything after it.
Try:
<%
Dim i
'you can now use the variable as you want.
i = "whatever"
%>
It's actually VBScript. You have to do this:
dim i
i = "some string"
I believe in classic ASP you can't give an explicit type to your variables. They all have to be variants and they have to be declared with no As clause, e.g. "dim i". Here's the MSDN help on variants in VBScript.
you do not need 'as'.
this should work.
<%
Dim myString
myString = "Hello There!"
%>
This has been sufficiently answered I think, but I'll only chime in a bit to say that technically you may not need to explicitly declare the variable at all. If you're using the option explicit, yes you do need to declare it, a la
<%
option explicit
dim str: str = "Hello World"
%>
Otherwise, you can implicitly declare it on first use, php-style.
<%
str = "I don't need no stinkin dim statements!"
%>
I should add that using option explicit is a safer way to go, even if it does require more typing.