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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Still can not call a server side sub using the onclick event 2

Status
Not open for further replies.

bryant89

Programmer
Nov 23, 2000
150
CA
I can not call a server side sub from an onclick event within an image tag. If anyone knows how to do this let me know. If I use the <% %> asp tags it just calls the method as soon as the page is hit rather then after the onclick.
 
you can't do it unless you submit the form and run the page again. Why would you want to run a server side sub anyway, it couldn't affect the page anyway (unless you submit and reload it)

ray
rheindl@bju.edu

 
The reason I need to do this is because I want to use this image as a button to go to a different page. When I click the button I want to call a subroutine that does some security checks before taking the user to that different page. As of right now I have dtc buttons doing the job and I am using their onclick events to run the security subroutine checks. but I want to be able to use an image as a button rather than the dtc buttons.

 
in the onclick handler of the image, call theform.submit() (make sure the form's action=thecurrentpage), then when the asp script gets run at the top of the page, call the security subroutine, and if it passes, move to the next page, otherwise you could print up an error message and remain on the current page


ray
rheindl@bju.edu

 
You could also have the security check at the beggining of the page and not even show the button if there security level, or whatever, is not high enough.

Walt III
SAElukewl@netscape.net
 
uhhh k, I am not using any form tags for this asp page but I will throw them in to try it out. Another thing, If all I am doing is submitting the form, wont the security subroutine happen when you first hit the page then? I need a way of only calling this subroutine when the onclick for that image is hit. and I need to place a 5 images on the page that need to call diff security subroutines on their onclick events I cant just run the same one every time. Depending on the image that is clicked I need to do diff things.


As you can tell I am very new to this so the little descriptive details help me a lot.
 
Thanks WaltLuke3

I can only have the security subroutine ran if a certain button is clicked. I need to place a few diff buttons that go to different pages. But for each page I need to run diff security sub routines because every page needs a diff level of security. So on each button <img onclick> I need to run a diff subroutine and resubmitting the form just wont do it.

Is there any other way.

Also I cant have these routines run on the first hit to this page.
 
ok, on your form (with the images), make a hidden field:
<input type=hidden name=fldImgClicked value=''>

delcare your images like this:
<img name=img1 source=&quot;sourcepath&quot; onclick=&quot;img_onclick(this)&quot;>
<img name=img2 source=&quot;sourcepath&quot; onclick=&quot;img_onclick(this)&quot;>
etc.

then the handler would be:
function img_onclick(me) {
document.formname.fldImgClicked.value = me.name;
document.formname.submit();
}

in asp:

<%
If Request(&quot;fldImgClicked&quot;) <> &quot;&quot; Then
'call your security handlers based on whatever image was clicked (the name is in Request(&quot;fldImgClicked&quot;))
End If
...

This way, the security functions will only be called when an image was clicked, plus you will know which image was clicked and be able to call the right security function

ray
rheindl@bju.edu

 
the request statement is not working
I will show you my code.

<input type=hidden name=fldImgClicked value=&quot;why&quot;>

<%
dim imgclicked
imgclicked=Request.Form(&quot;fldImgClicked&quot;)
imgclicked=&quot;so &quot;
imgclicked=imgclicked &amp; serverImgClicked.value
Response.Write &quot;<H2>&quot; &amp; imgclicked &amp; &quot; not</H2>&quot;
%>

I am using the above code just to test things out because for some reason the request statements were not working.
Therefore I have set the value of fldImgClicked to &quot;why&quot; just to see if the request would work properly.
The Response.Write &quot;<H2>&quot; &amp; imgclicked &amp; &quot; not</H2>&quot; should disply so why not but it only displays so not. This tells me that the request is not working and I do not know why
 
bryant,

> the request statement is not working
> I will show you my code.

Your code does NOT SHOW where the object 'serverImgClicked' is declared. Therefore the problem with the code cannot be determined without guessing, here is my guess:

Is 'serverImgClicked' an HTML element? If so it is only a 'CLIENT SIDE' object and therefore does NOT exist in 'SERVER SIDE' code.

This is the same concept as before. You really need to try and get a grasp on the concept or you are going to struggle with Web development forever.

&quot;But, that's just my opinion... I could be wrong&quot;.
-pete
 
what is serverImgClicked.value coming from? It looks to me as if you are overwriting your variables. try this:

<%
dim imgclicked
imgclicked = Request(&quot;fldImgClicked&quot;)
Response.Write &quot;<h2>&quot; &amp; imgclicked &amp; &quot; not</h2>&quot;
%>

that should work. Also, make sure that your hidden field is inside the form tags ray
rheindl@bju.edu

 
My great apologies......
Sorry I am not perfect yet.

I made a mistake when I copied the code. I will recopy it. I will not struggle with this stuff forever because I am learning all of the time. In order to get a grasp you must be able to work with it. I have done 2 things now with it. I get most of it but there are still things that arent clear. Maybe the way you explains things is over my head. I have to get up to speed with everyone and try to understand from there. Whatever...

This is what my code looks like I screwed up when copying it to the thread last time.

Correct me if I am wrong...

This input control below is on the client side

<input type=hidden name=fldImgClicked value=&quot;why&quot;>

This code within the <% %> is run on the server side. In this case my language is set to vbscript.


<%
'declare 2 variables
'1 to store the request from the client
'1 to store a concatonated string
dim inputvalue
dim imgclicked

inputvalue=Request(&quot;fldImgClicked&quot;)
imgclicked=&quot;so &quot;

imgclicked=imgclicked &amp; inputvalue

Response.Write &quot;<H2>&quot; &amp; imgclicked &amp; &quot; not</H2>&quot;

%>

Now, The Request object is used to pass information from the client up to the server. So therefore it should seem possible that Request(&quot;fldImgClicked&quot;) should retrieve the value from the client side input control named fldImgClicked on the Form. In this case the value=&quot;why&quot;.
So the output from the Response.Write(which is used to pass information from the server down to the client) should read this on the asp page: so why not

But it does not, it only reads: so not.

Therefore I assume that the Request object is not working properly or I have used it incorrectly.

I am only trying to get a grasp here so let me know what I am doing wrong.
 
K I will try that ray.

>Also, make sure that your hidden field is inside the form tags

yeppers it is within the form tags
 
I tried that ray but it still just shows the word: not without the value from the hidden field
 
bryant,

> My great apologies......

No, you have nothing to apologize for. I am sorry if the point of my post was misleading. I was only attempting to focus you in on the CLIENT vs SERVER issue as it seemed to continually give you problems. I was not trying to flame you in any way. :)

As to your last code post it seems as though you have everything in order. The Request object does not fail so I would focus on two things:

**** one ***
inputvalue=Request(&quot;fldImgClicked&quot;)
imgclicked=imgclicked &amp; inputvalue
************
That is VB code and I don't know VB very well. There might be something wrong with the way you are addressing the VB variables and objects

***** two ****
> yeppers it is within the form tags
**************

This of course MUST be true as well as the form must be 'submitted'. If the page is just 'linked' too, then the form variables are not sent from the browser to the server.

Hope this helps
-pete


 
>I was not trying to flame you in any way.

Sorry I thought you were. Its so hard to tell without hearing the tone of someones voice.

Anyway my problem is the form is not being submitted at all. It has to be submitted when the page is hit so that the variables get passed from the client to the server.

Then once an image is clicked the form must be submitted again.

I gotta mess with this to see what going on. I have code everywhere. I gotta clean things up and sort things out.
 
bryant, sorry if I came across like I was being disrespectful or something.

anyway, how about posting the onclick handler of your images. - make sure it is submitting the form - document.form.submit()

if you are running those few lines of asp, of course Request(&quot;fldImgClicked&quot;) won't return anything, since the form doesn't even exist yet. Request(&quot;fldImgClicked&quot;) will be blank until something gets put in it when the form is submitted

also, you said that you have code all over the place. why don't you try a simple page with just the images and a little bit of asp code to test with ray
rheindl@bju.edu

 
>bryant, sorry if I came across like I was being disrespectful or something.

No you werent. I was confused.(as usual)

I am a below novice programmer that has been subjected to a project right in the middle. I am expected to pretty much take off where the project was left off. But unfortunatley I know nothing about asp or interdev. Without your guys' help I would be stuck. I appreciate all the assistance you can give me. (I know you have to dummy it up for me). Hopefully I will get up to speed soon and wont have to ask so many dumb questions.

Anyway you are right the submit is not being executed in the image onclick event handler. the image name is being passed fine becuase I can output it in an alert within the handler. But I have put an alert after the submit and it does not execute so I don't think the submit is working.
But the reason it is not working is because of some other factor. I put the code into a simple asp page like this:

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<script language=&quot;javascript&quot;>
function img_onclick(me) {

document.all(&quot;fldImgClicked&quot;).value = me;
alert (me);
document.sw.submit();
alert (me);

}
</script>
</HEAD>
<BODY>
<form name=sw>
<input type=hidden name=fldImgClicked value=&quot;&quot;>
<%

dim imgclicked
imgclicked = Request(&quot;fldImgClicked&quot;)
Response.Write &quot;<h2>&quot; &amp; imgclicked &amp; &quot; not</h2>&quot;

%>
<img src=&quot;../images/menu-main-off.gif&quot; width=44 height=25 name=&quot;main&quot; alt=&quot;Main&quot; border=&quot;0&quot; onclick=&quot;img_onclick(this.name)&quot;>

</body>
</form>
</HTML>

This works fine but when I put it into the page where it is supposed to work it will not work and I think it has something to do with scripting object model being enabled. I dont know much but It looks to me like its creating its own form.
It doesnt work on this page
<%@ Language=VBScript %>
<% Option Explicit
Response.Buffer=True
%>

<script id=&quot;DebugDirectives&quot; runat=&quot;server&quot; language=&quot;javascript&quot;>
// Set these to true to enable debugging or tracing
@set @debug=false
@set @trace=false
</script>

<% ' VI 6.0 Scripting Object Model Enabled %>
<!--#include file=&quot;../_ScriptLibrary/pm.asp&quot;-->
<% if StartPageProcessing() Then Response.End() %>
<FORM name=thisForm METHOD=post>


<html>
<head>
<title></title>

<meta name=&quot;VI60_defaultClientScript&quot; content=JavaScript>
<meta NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;../FormFormats.css&quot;>
<script language=&quot;javascript&quot;>
function img_onclick(me) {

document.all(&quot;fldImgClicked&quot;).value = me;
alert (me);
document.sw.submit();
alert (me);

}
</script>
</head>
<body >
<form name=sw>
<input type=hidden name=fldImgClicked value=&quot;&quot;>
<%

dim imgclicked
imgclicked = Request(&quot;fldImgClicked&quot;)
Response.Write &quot;<h2>&quot; &amp; imgclicked &amp; &quot; not</h2>&quot;

%>
<img
src=&quot;../images/menu-main-off.gif&quot;
width=44 height=25
name=&quot;main&quot;
alt=&quot;Main&quot; border=&quot;0&quot; onclick=&quot;img_onclick(this.name)&quot;>


</form>
</body>


<% ' VI 6.0 Scripting Object Model Enabled %>
<% EndPageProcessing() %>


</FORM>

I assume I need all of this extra stuff in here because the programmer before me has it in here. But hopefully you guys will know whats up
</html>
 
bryant,

Ok, now it is all clear. #-)

The scripting object model (DTC's) do not support nested forms. The DTC's create a form for the entire page named 'thisForm'. You cannot place any forms anywhere else on the page and have the DTC's work correctly.

This is documented on MSDN but I don't have a link to the article.

Hope this helps
-pete
 
So I guess I can not do anything about this and I have to use these dtc buttons. Rather than the javascript ones I designed. Its hard to make a page appealing with these

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top