OnClick event won't fire

G

Guest

Karl,

you have runat="server" set for your control - in order to add client side
onclick you will need to either remove runat attribute add this as an
attribute to your control:
' provided that you added id="inpSubmit" to your htmlInput control:
inpSubmit.Attributes("onclick") = "submit()"
 
K

-Karl

Ok, I tried removing the runat=server on all my controls as well as
the scrpt tag tself. No luck.
I then tried figuring out how to use the .attribute feature you
mentioned but I am not having any luck there.

Any chance you could show me a working example of what I need to do
please? I apologize but this is driving me nuts right now. I'm
etting myself all confused over this.

------

my updated code without the runat commands:

<script runat='server'>
Sub submit()
response.redirect("http://www.google.com")
End Sub
</script>

....

v = v + "<div class='' title='' onclick='' id=''><form ><input
type='text' name='QueryMap' size='9' value='1q' /> <input
type='submit' value='Find' OnClick='submit()' /></form></div>"
 
K

-Karl

It appears that my code will not accept my using ANY asp.net controls
so I'm stuck with using html controls instead. Not a big deal bt I do
have a bigger issue. I need to pass my JS variable into ASP.net.
passing asp.net variables to JS is easy but not the other way around.
Any ideas on how to do this? I am beginning to think a cookie would
be the easiest way. Yea, I am already looking into AJAX but that's
something else that I am not ready to understand at this time.

Thanks!
 
A

Alexey Smirnov

It appears that my code will not accept my using ANY asp.net controls
so I'm stuck with using html controls instead. Not a big deal bt I do
have a bigger issue. I need to pass my JS variable into ASP.net.
passing asp.net variables to JS is easy but not the other way around.
Any ideas on how to do this? I am beginning to think a cookie would
be the easiest way. Yea, I am already looking into AJAX but that's
something else that I am not ready to understand at this time.

If you have a postback you can set a hiddenfield
 
A

Alexey Smirnov

Karl,

you have runat="server" set for your control - in order to add client side
onclick you will need to either remove runat attribute add this as an
attribute to your control:
' provided that you added id="inpSubmit" to your htmlInput control:
inpSubmit.Attributes("onclick") = "submit()"

that's correct

<script runat="server">
Sub submit()
.....
 
A

Alexey Smirnov

Karl,

you have runat="server" set for your control - in order to add client side
onclick you will need to either remove runat attribute add this as an
attribute to your control:
' provided that you added id="inpSubmit" to your htmlInput control:
inpSubmit.Attributes("onclick") = "submit()"

that's correct

<script runat="server">
Sub submit()
.....
 
G

Guest

Karl,

I am not sure what are you trying to do.

Say you want to process onSubmit event on the server, then the easiest way
would be removing your html input control, and drag ASP.Button control in its
place. Double clicking on the button (while in design view), will open the
code (onclick) procedure where you can enter your code to process on the
server side.

If, on another hand you want to handle the onclick event on the client side
(my original suggestion assumed that), then you will need to follow my
previous post.

Please let me know if you need more assistance - will be glad to help
 
K

-Karl

In a nutshell, I am making a custom map using Google's map API / SDK.
I have my map working but now I am trying to add more functionality to
it, in this case a search feature.

Google maps uses JS very heavily and some AJAX as well (Something new
for me to learn). The menu system is based off some fanncy DIV's and
rendered client side using JS. As such, my ASP:INPUT control won't
render for some reason so I am using abasic HTML Input control
instead. What I am trying to do is fire off the OnClick event and
pass the input to my asp control so I can perform a lookup and search
against my DB. The OnClick event gets fired off in a JS function and
there lies my issue.

I'll post my page when I get home so you have a clear idea of what I
am facing. I know my code isn't the cleanest. Please understand,
I've been piecing together pieces from all over the net trying to get
this to work.

Thank you for all your help...
-Karl
 
K

-Karl

K, here is my updated code:
http://www.nomorepasting.com/getpaste.php?pasteid=1057&seen=true&numbered=on&langoverride=asp


Line 72 is where the input control is. I know I have the runas=server
option in it (I forgot to remove it before pasting).

The Onclick event fires up the JS function Fou() which can read the
HTML Input control value. I was playing around trying to see if maybe
I could store that value into a cookie to be read by ASP but there
seems to be some difference between how each language creates cookies
so I am nt able top pass the value via cookie. So now I am looking
into having JS write to a file just to have ASP read that file and
pass the variable on. There has to be some easier method here but I
can't find ANY working examples wehich is driving me nuts!

I keep hearing AJAX and I understand it sends partial page info to the
server instead of the entire page. Is this really the only way to
pass a JS variable to ASP???

I'm looking over http://www.w3schools.com/ajax/ajax_example.asp. This
might clue me in unless you can think of another method? It's a bit
of code but maybe this is what I need after all??
 
G

Guest

Karl,

I cannot find in the code provided how v string ends up on the browser. In
your fou js function you can populate a hidden input (with runat='server' and
id) and then its value can be read on the server by your ASP.Net
 
K

-Karl

sorry for being so dumb about this but I'm still confused. I don't
see how this would be any different. You are saying that I need to
pass the variable from my HTML input to my hidden HTML input with a
runas=server??

I'm heading home soon and I'll give it a try and see what happens. My
head is in the clouds today.
 
A

Alexey Smirnov

sorry for being so dumb about this but I'm still confused. I don't
see how this would be any different. You are saying that I need to
pass the variable from my HTML input to my hidden HTML input with a
runas=server??

I'm heading home soon and I'll give it a try and see what happens. My
head is in the clouds today.

First of all, you cannot call a server code from client script like
this. From what I see in code, v is executed on the server inside a
client js-script. Regarding your first question, why submit() worked
inside <% %> and not onClick event. It works in the former case
because you call it correctly on a <% server %> while in the latter
you tried to execute it as a client script. I am sorry that I didn't
realize this before.

The code should be following

<input id="Submit1" type='submit' value='Find' onserverclick="submit"
runat='server'/>
http://msdn2.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlbutton.onserverclick.aspx

In case you want to use ASP.NET control you might have

<asp:Button id="Submit1" onclick="submit" text="Find" runat="server" /
Note, that submit() method should be modified too (the signature):
Sub submit(sender As Object, e As System.EventArgs)

In case you will need a client script from an ASP.NET control, you
should use OnClientClick event, e.g.

<asp:Button runat="server" OnClientClick="ClientJS();"....

Hope it helps to get your code working

Regarding Google Maps. There are very good examples of code in SDK,
did you check it?
 
K

-Karl

Hope it helps to get your code working
Regarding Google Maps. There are very good examples of code in SDK,
did you check it?



I've tried using a .net button but it doesn't get rendered (gets
processed as text) so then I tried using the runat = server as you
mentioned but then I ran into errors. I forgot what it said but I can
post it later. I then found a nice tutorial on AJAX from w3schools
that I started to modify but as soon as I started to put my connect
string in the asp page, it bugged out on me.

I'll be looking thru the SDK perhaps tonight. I was looking at some
of their AJAX APIs, trying to get an idea on this. I was really
hoping to avoid doing postback but if I need to, I will have to design
my age around that. Not sure how that will work out though.

My head is killing me. I can't figure out why this has to be so
hard.

Again, thank you for all your help on this. I'm going to have a great
laugh at myself when it works. I'll have to send you a thank you card
or something.
 

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

Top