Link to home
Start Free TrialLog in
Avatar of SamHobbs
SamHobbs

asked on

Doing ASP when a button is clicked

I am in the habit of using things like buttons without forms. This works well using DHTML. Is there an easy way to do the following and get the ASP code to also work? The following code works, except not the Response.Write line. I am assuming this is easy but I am afraid that there is too much for me to read for the answer, so if someone can provide an answer I will appreciate it.


<%@ Language=VBScript%>

<head>
<title>Buttons Test</title>
</head>

<script language="VBScript">
Sub SayType(Something)
MsgBox "Type " + Something
Response.Write "Type " + Something
End Sub
</script>

<body>

<h1 align="center">Buttons Test</h1>
<blockquote>
  <p>&nbsp;</p>
  <table border="0" cellspacing="10">
    <tr>
      <td><input type="button" name="FormatText" value="Text" onclick="SayType 'Text'"></td>
      <td><input type="button" name="FormatMIME" value="MIME" onclick="SayType 'MIME'"></td>
    </tr>
  </table>
</blockquote>
</body>
SOLUTION
Avatar of nilapenn
nilapenn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bendX
bendX

OK, I tried this also previously, this is what I found :

If you call your function that do the Response.Write after the page is loaded, then it will append that to the bottom of the page. You have to call it while the page is loading.

Also the Response.Write MUST be in server side scripts.
example :

<script language-"VBScript" runat="server">

</script>

or

if you declared the language already at the top :
<%@ Language="VBScript"%>

then you can use these tags :

<%

%>

and if you would like to call a server variable/function and just write in somewhere :

<html>
 <p> <%=ServerDetail%> </p>
</html>

or to excecute a function

<html>
 <input="button" onclick="<%ServerFucntion()%>">
</html>
Avatar of SamHobbs

ASKER

I am sorry, bendX, but I could not get it to work using your suggestion. I tried as many variations as I could think of.

Note that I am using a VBScript procedure, not a function, so the syntax is slightly different. Also, if I were to have a function, then I think that VBScript is different from C++ and JScript and such. I think that VBScript will complain if you do not assign the return value of a function to a variable. This is a minor detail.

So I did a very simple test to try your suggestions and could not get it to work either. The following is what I tried. It is the complete file.


<%@ Language=VBScript%>

<head>
<title>Simple Test</title>
</head>

<%
Sub Init()
Response.Write "loaded"
MsgBox "loaded"
End Sub
%>

<body onload="<%Init%>">
<h1 align="center">Simple Test</h1>
</body>
Immediately after creating this question I realized I should have made it clear that the Response.Write is just a sample and that in reality I want to do much more in the procedure when a button is clicked. In particular, I need to use CDONTS. So nilapenn, your suggestion will not help; I am sorry; I should have been more clear.
I forgot to click on the button before.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm sorry, mouatts, but there is not any ASP in your suggestion; I know how to do it using DHTML without ASP.
Of course there is no ASP because ASP executes on the server side and you are wanting something submitted which MUST occur on the client side.
I think I got the answer from the Microsoft ASP newsgroup. It's address is:

microsoft.public.inetserver.asp.general

The answer is that what I want to do is not possible. It was not clear to me that there is no ASP code in a HTML file sent to the client, and therefore when a DHTML event occurs, the ASP code is gone.

I will probably request this question be deleted soon.
My self and others told you that ASP were server side only so you have ineffect your answer
The explanation provided by Moshe in the newsgroup included the explanation "Once an ASP page has finished processing on the server, it shows up at the client with the ASP part GONE.".

That is not the same as saying "Response is object is used onluy in server side scripts." or "the Response.Write MUST be in server side scripts" or "Of course there is no ASP because ASP executes on the server side and you are wanting something submitted which MUST occur on the client side."

I realize that for someone that understands that ASP only executes before the HTML is first sent to the client, all the comments probably are relevant, but for someone such as I that did not yet understand, the explanations provided in here were not clear enough.
Then don't expect any further help on EE
Avatar of Gary
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Deleted and Points Refunded
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
GaryC123
EE Cleanup Volunteer
Thank you. That suggestion is good.
Valid answers were given so I don't see why points should be refunded. I'd suggest points to nilapenn or split between him/her and me

Steve
This is why it is so difficult emotionally and technically to close questions and why I don't use EE anymore. The issue is not points. I have an abundance of points to use. The issue is what is right.

A valid answer was not provided. Perhaps the intended meaning of answers were relevant but they are not understandable to me. I do not criticize a person's use of english but perhaps the answers are not clear to me because the person's primary language is not english.

I might have been willing to allow the points to be awarded anyway but a person should never be rewarded for saying things like "Then don't expect any further help on EE". That attitude must not be allowed. The issue is not points; the issue is what is right.
Technically both Nilapens answer and mine were more accurate than the one you found else where. But that aside it is the norm on EE when someone provides an answer that the points and credit are attributed to the person or people concerned, even if you subsequently find an answer better or otherwise else where.

Simply saying well I've found it elsewhere so I'll get it deleted is quite discourtious to those who have responded, and you will find that those who have got themselves a reputation for doing this find their questions ignored.

You question whether english was the answerers primary language well if you are refering to Nilapens then its clear enough to me and if you are refering to mine I am English!