Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call ASP Function onClick of a Button 1

Status
Not open for further replies.

ufobaby

MIS
Sep 25, 2001
238
US
hi, one more newbie question.
========= CODE ========
<%
Sub Auth()
DO ASP Stuff
End Sub
%>
<html>
<body>
<form name=&quot;auth&quot;>
<p><input type=&quot;button&quot; value=&quot;Submit&quot; name=&quot;B1&quot; onClick=&quot;Auth()&quot;>
</form>
</body>
</html>

This gives an error &quot;Object Expected&quot; ..... is this possible

[cheers]
Niraj [noevil]
 
try
<p><input type=&quot;button&quot; value=&quot;Submit&quot; name=&quot;B1&quot; onSubmit=&quot;Auth()&quot;>

also if this is a client side script enclose the script in the VBscript tags instead. that also may cause problems. the <% tells it to look to the server for reference but the script is on the page.
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
I think the idea here is that it's a server side script, yes?
(I hope so, would hate to use VBScript client-side).

This should give you the idea:
<html>
<head>
<title>
<% Response.Write Request.Form(&quot;AuthSubmit&quot;)
if Request.Form(&quot;AuthSubmit&quot;) = &quot;Submit&quot; then call Auth
function Auth()
'do asp stuff
Response.Write &quot; AHA!!&quot;
end function
%> </title>
</head>
<body>
<form method=&quot;post&quot;>
<input type=&quot;submit&quot; name=&quot;AuthSubmit&quot; id=&quot;AuthSubmit&quot; value=&quot;Submit&quot; />
<input type=&quot;submit&quot; name=&quot;AuthSubmit&quot; id=&quot;AuthSubmit&quot; value=&quot;SubmitAgain&quot; />
</form>
</body>
</html> codestorm
Fire bad. Tree pretty. - Buffy
select * from population where talent > 'average'
<insert witticism here>
 
Clarification on codestorms Vbscript comment incase you are not awhere. As much as I love using Vbscript in my sites. Vbscript is only recognized by internet explorer. So in turn there are major cross browser issues with using client side scripting.

I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
thanks both of u

onpnt ->

tried ur code but it does not do anything... i mean does not give an error even does not execute the Sub Procedure

codestrom ->
gives an error

Response object error 'ASP 0156 : 80004005'
Header Error
/e-specials/logscr.asp, line 19
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.

Am using Response.Redirect in the Auth() sub. also some JavaScript to populate a hidden field in the parent frame.

Any ideas on this. Please help... if u wan i would send the full page code

[cheers]
Niraj [noevil]
 
You'll have to show the code to solve the Javascript thing, but for the error:

At the top of each page (or ideally defaulted in IIS) you should have
Response.Buffer=True

and just before you Response.Redirect have a
Response.Clear codestorm
Fire bad. Tree pretty. - Buffy
select * from population where talent > 'average'
<insert witticism here>
 
hi, thank a million codestrom and onpnt for those inputs.
codesrom that worked very well. couple of clarification are needed ..... if u could please help.

1.] When we give only the method=post, it call the same page right. kind of refreshes
2.] Why to add Response.Buffer and Response.Clear, i mean what are we buffering and where.
3.] the below Javascript does not work with this asp page, but works when in a HTML page

Response.Clear
Response.Write (&quot;<script language=JavaScript>;&quot;)
Response.write(&quot;alert(window.parent.frames(header).document.forms(identity).item(me).value);&quot;)
Response.write(&quot;window.parent.frames(header).document.forms(identity).item(me).value = &quot; & u & &quot;;&quot;)
Response.Write(&quot;</script>&quot;)
Response.Redirect &quot;welcome.asp&quot;

It redirescts to &quot;welcome.asp&quot; but does not execute anything above that. tried with putting .Clear just before the redirect also.

[cheers]
Niraj [noevil]
 
1.] When we give only the method=post, it call the same page right. kind of refreshes.

Yeah - another round trip to and from the
server to redeliver your page.


2.] Why to add Response.Buffer and Response.Clear, i mean what are we buffering and where.

Buffering means that you don't send any of the HTML an ASP page produces until eith it's completed building the page, or a Response.Flush is encountered.
With buffering off, the page is sent one Response.write at a time - not sure how it handles those chunks of HTML between ASP scripts ..

Response.Clear, as the name implies, clears out any buffered HTML the ASP page has built and buffered to send.

Response.Redirect sends a message to the client browser telling it to request a new page from the server.

It will not work if enough of the current page (the headers - ie <html><head><meta ...></head>) has been sent by either using Response.Flush or having buffering off.

3.] the below Javascript does not work with this asp page, but works when in a HTML page

The reason the above server side script isn't working is that it's sending the client-side script to the browser, which I'm fairly sure will not execute it until the page has finished loading into the browser. However before you complete the page, you redirect it to another page, hence the script won't execute.

In the above example I'd suggest perhaps doing the redirect in client side javascript. codestorm
Fire bad. Tree pretty. - Buffy
select * from population where talent > 'average'
<insert witticism here>
 
hi, codestrom, a friend of mine figured out a workaround for the same here goes the code ->

... asp code (previous one)
else
%>
<html>
<head>
<script language=&quot;javascript&quot;>
<!--
function GoodJo()
{
window.parent.frames(&quot;header&quot;).document.forms(&quot;identity&quot;).item(&quot;me&quot;).value = document.form1.user.value;
window.navigate(&quot;welcome.asp&quot;)
}
//-->
</script>
</head>
<body onload=&quot;GoodJo()&quot;>
<form name=&quot;form1&quot;>
<input type=hidden name=&quot;user&quot; value=&quot;<%=u%>&quot;>
</form>
</body>
</html>
<%
'ends here
end if
End Function
%>

Can u suggest what would be the best for an intranet site.
1.] Session OR
2.] the above logic of hidden variables.

[cheers]
Niraj [noevil]
 
For a cheap'n'nasty site I'd use Session variables (simply because their maintenance is easier than hidden variables.

For a worthy site I'd use a database to store session details. codestorm
Fire bad. Tree pretty. - Buffy
select * from population where talent > 'average'
<insert witticism here>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top