WebServer "Behavior" question

A

Alex Nitulescu

Hi. I have the following HTML (snip):

_____________________________________________
<body MS_POSITIONING="GridLayout" onload="Init()">
<form id="frmWebServerAdvanced_1Test" method="post" runat="server">
<div id="service" style="behavior:url(webservice.htc)"
onresult="Service_Result()"></div>
°Fahrenheit: <input id="txtFahrenheit">
<input type="Button" value="Convert !" onclick="Button_Click()">
<span id="lblCelsius"></span>
</form>
</body>
_____________________________________________

and the following script:
_____________________________________________
<script language="javascript">

var intCallID=0;

function Init()
{
service.useService("http://localhost/aspnetprojects/vsnet/WebServerAdvanced_1/TemperatureWithBehaviour.asmx?WSDL","TemperatureWithBehaviour");
}

function Service_Result()
{
//If there is an error, and the call came from the call() in init()
if((event.result.error) && (intCallID == event.result.id))
{
//Pull the error information from the event.result.errorDetail
properties
var xfaultcode = event.result.errorDetail.code;
var xfaultstring = event.result.errorDetail.string;
var xfaultsoap = event.result.errorDetail.raw;
alert(xfaultstring);
//Add code to handle specific error codes here
}
//If there was no error, and the call came from the call() in init()
else if((!event.result.error) && (intCallID == event.result.id))
{
//Show the result !
lblCelsius.innertext="The result of the conversion is " +
event.result.value + " °Fahrenheit"
//alert("The result of the conversion is " + event.result.value +
"°Fahrenheit");
}
else
{
alert("Something else fired the event!");
}
}

function Button_Click()
{
intCallID = service.TemperatureWithBehaviour.callService("ToCelsius",
txtFahrenheit.value);
//intCallID = service.TemperatureWithBehaviour.callService("ToCelsius",
87);
}

</script>
_____________________________________________

I have the following two problems -
1. Microsoft JScript runtime error: 'txtFahrenheit' is undefined
If I comment out the line, as above, and enter a fixed value, it works okay.

2. lblCelsius.innertext does not work - it does not complain, but it simply
does not work. However, ALERT works just fine. I obtain
"The result of the conversions is 30.55..." etc

What am I missing here ? I look at the HTML and everything seems to be in
order.

Thank you, Alex.
 
D

Derek Harmon

Alex Nitulescu said:
intCallID = service.TemperatureWithBehaviour.callService("ToCelsius", txtFahrenheit.value); : :
1. Microsoft JScript runtime error: 'txtFahrenheit' is undefined

Double check (a) you don't have a typo, and (b) txtFahrenheit has a value,
as it works for me. If nothing else occurs to you, try rummaging through
document.all to retrieve the IHTMLElement by it's id attribute value like
this [unverified],

intCallID = service.TemperatureWithBehaviour.callService( "ToCelsius",
document.all["txtFahrenheit"].value);

or look at what Visual Studio .NET debugger tells you when you put
txtFahrenheit into the Watch window during a debug session.
2. lblCelsius.innertext does not work - it does not complain, but it simply does not work.

It's always permissible to add an extra attribute on a client-side DOM element.
Whether the browser interprets the attribute you've invented is another matter.

Use

lblCelsius.innerText = "The result of the conversion is " + event.result.value + " °Fahrenheit";

instead (note the camel case).


Derek Harmon
 
A

Alex Nitulescu

Fantastic :))))

1. It was innerText, not innertext !
2. For some (very obscure to me) reason,
intCallID = service.TemperatureWithBehaviour.callService("ToCelsius",
document.all["txtFahrenheit"].value);
works, but
intCallID = service.TemperatureWithBehaviour.callService("ToCelsius",
txtFahrenheit.value);
doesn't - it says that 'txtFahrenheit' is undefined.

(Even the debugger says the same thing - that 'txtFahrenheit' is undefined.
However, when I tried with document.all["txtFahrenheit"].value, it showed my
value (32) correctly. Hmmmmm......)

Something else, please, I see that you're *very* knowledgeable, if I may:

1. If I have another webservice which returns an image (a jpeg) as a byte
array (and it works fine), how could I show the picture in a frame (or, even
better, in a "img" element) ? Right now I have the code:

Dim objBinaryWebService As New localhost.ImagesWebService()

Response.Clear()
Response.ClearHeaders()
Response.ContentType = "image/jpeg"
Response.BinaryWrite(objBinaryWebService.GetRandomImage)
objBinaryWebService.Dispose()

which works, but all my controls on the form are not even considered,
because of the Content-Type, I assume. My intent is to use this to show
random thumbnails of the "Products" in the Products table - so I plan to
stop using the web reference but use a behaviour instead, and use
setInterval("GetRandomImage()",5000) to change the images every 5 secs !

2. A simpler one - will this code I'm fighting with right now work with
Mozilla ?

Thanks again ! :)))

Alex.




Derek Harmon said:
Alex Nitulescu said:
intCallID = service.TemperatureWithBehaviour.callService("ToCelsius",
txtFahrenheit.value); : :
1. Microsoft JScript runtime error: 'txtFahrenheit' is undefined

Double check (a) you don't have a typo, and (b) txtFahrenheit has a value,
as it works for me. If nothing else occurs to you, try rummaging through
document.all to retrieve the IHTMLElement by it's id attribute value like
this [unverified],

intCallID = service.TemperatureWithBehaviour.callService( "ToCelsius",
document.all["txtFahrenheit"].value);

or look at what Visual Studio .NET debugger tells you when you put
txtFahrenheit into the Watch window during a debug session.
2. lblCelsius.innertext does not work - it does not complain, but it
simply does not work.

It's always permissible to add an extra attribute on a client-side DOM
element.
Whether the browser interprets the attribute you've invented is another
matter.

Use

lblCelsius.innerText = "The result of the conversion is " +
event.result.value + " °Fahrenheit";

instead (note the camel case).


Derek Harmon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top