Forum Moderators: open

Message Too Old, No Replies

Problem with response.write

         

msokol

5:46 pm on Dec 7, 2002 (gmt 0)

10+ Year Member



I am using ADO model to retrieve data from Acces DB to intialize some global variables for VBScripts. The data is apparently retieved properly but when I attempt to pass the values to scripts to run with <BODY onload ="sub1()"..
I do not observe behavior I would expect. Specifically the global values being tested in IF statements don't appear to be interpreted properly. I attempted to add diagnostic output using response.write in the sub1 to observe the value and get runtime error stating object required: 'Respose'.

Sub called by onload method has the following:

Sub sub1
dim temp
temp = 0
response.write ("XXX")
{more code to test global variables intialized by the VBscript run to acquire the info from the Access DB }
End Sub

I was just attempting to output a static string before I
tried outputing variable values. The above produces the error. How to I get output during the function call to see what is going on if the above doesn't work.? I have not discovered any other write except the <%= which is a shortcut to the other form and produces same error.
This is my first attempt at using ASP and ADO etc.

aspdaddy

6:47 pm on Dec 7, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi msokol,

BODY onload is used to run client-side scripts, if you want to display data from a database you (usually) do this server-side, before sending the page to the browser.

Check out some simple asp examples on the developers sites to do database reads etc, sticky me if you want some links.

<added...and welcome to webmaster world:)</added>

duckhunter

9:03 pm on Dec 7, 2002 (gmt 0)

10+ Year Member



Are you using .NET? or ASP?

.NET use the code behind the aspx in the Page_Load event to call your subroutine.

If it's just ASP then:

<HTML>
<BODY>
<%
'Call your Subroutine:
MyRoutine

Sub MyRoutine()

Response.write "XXX"

End Sub
%>
</BODY>
</HTML>

msokol

3:17 pm on Dec 9, 2002 (gmt 0)

10+ Year Member



I am using ASP..(PWS on NT4 Workstation as the server).

Intended application is to read Access DB to initialize the state of <BUTTON> tags .. at this time just setting background color. (Eventually to click on BUTTON and reset value back in the AccessDB>) My ADO script appears to be working okay and retrieves correct data, it is defined before the <BODY> in my ASP file within <%...%>. The other functions where defined outside the body as well but within <Script language="vbscript">...</script> tags and I guess this makes them client side , which I didn't know. The sub executed "onload" set the background colors to static values ("red", "green" etc.) with no data passed from the results of the ADO objects. This is where I lose control.

In the server side code I set the retrieved values into variables declared in the script? Do these persist? If not how do I use the info once I need to process the client side properties? Can I reference in the server side script objects created later in the <BODY>. For example, my client side onload sub declares Button1.sytle.backgroundcolor="Green" where button1 is id of <BUTTON> and this works. I want this property to be dynamic based on what I retrieve in the server side results of the SQL query on my data base.
I have purchased two ASP books but there is still lots to learn. Thanks. BTW.. what is the syntax for passing arguments to a sub in the onload statement.. I am using onload=sub() since I have no args. Since passing args wehn calling subs in VBScript are not delimited within () as they are with functions...

aspdaddy

1:38 pm on Dec 11, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My objective is to set the initial color of the buttons displayed to be red if the DB value is 0 and green if 1.

The way to do this is all on the server side.
First assign variables for the colors based on the data in the recordset


if objRS(0)=1 then
strColor="green"
else
strColor="red"
end if

Then just write the buttons using ASP


Response.write "<input type='button'
style='color:black; height:30; width:100; background:" & strColor & ";'>"

If you want to have onClick events that do different things depending on what was in the database, you have to use the same approach and write ther client-scrript, on the server side! using ASP.

Remember, once the page is displayed in the broswer - the database is closed unless you use some other technology e.g RDO/Client-side data binding.

I Hope this helps, it is confusing, but it is the way to achieve what you want to do in this situation.

msokol

4:59 pm on Dec 11, 2002 (gmt 0)

10+ Year Member



The method you described works now.. and acutally I figured out this is what I had to do after my previous sticky mail to you.. I create the entire page using Response.Write withing the script. No HTML is placed on the page directly. In this way I have complete control on substituting values into the arguments to the response.write. It takes some understanding of what buffered output to the page actually is and what and when the page actually receives. The easiest was to let the script write all.

My onClick events which I assume are client side still work to change the displayed button styles. Now to get the data back to the database as part of the onclick events...

Thanks...