OnClick event won't fire

Discussion in 'ASP .Net' started by -Karl, Jul 5, 2007.

  1. -Karl

    -Karl Guest

    -Karl, Jul 5, 2007
    #1
    1. Advertising

  2. 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()"


    "-Karl" wrote:

    > Snippet: http://www.nomorepasting.com/getpaste.php?pasteid=1020&seen=true&numbered=on&langoverride=asp
    >
    > Line 37 is where I am having the problem. I can't get the onclick
    > event to fire off. Yet line 16 works like it's supposed to. How do I
    > get my onclick event to work? I tried changing it from onclick to
    > onserverclick but that had no effect.
    >
    >
    > Thanks!
    >
    >
     
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=, Jul 5, 2007
    #2
    1. Advertising

  3. -Karl

    -Karl Guest

    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>"
     
    -Karl, Jul 5, 2007
    #3
  4. -Karl

    -Karl Guest

    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!
     
    -Karl, Jul 5, 2007
    #4
  5. On Jul 5, 7:38 pm, -Karl <> wrote:
    > 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
     
    Alexey Smirnov, Jul 5, 2007
    #5
  6. On Jul 5, 6:46 am, Sergey Poberezovskiy
    <> wrote:
    > 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()
    .....
     
    Alexey Smirnov, Jul 5, 2007
    #6
  7. On Jul 5, 6:46 am, Sergey Poberezovskiy
    <> wrote:
    > 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()
    .....
     
    Alexey Smirnov, Jul 5, 2007
    #7
  8. 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

    "-Karl" wrote:

    > 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>"
    >
    >
    >
     
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=, Jul 6, 2007
    #8
  9. -Karl

    -Karl Guest

    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
     
    -Karl, Jul 6, 2007
    #9
  10. -Karl

    -Karl Guest

    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??
     
    -Karl, Jul 6, 2007
    #10
  11. 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


    "-Karl" wrote:

    > 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??
    >
    >
    >
    >
     
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=, Jul 6, 2007
    #11
  12. -Karl

    -Karl Guest

    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.


    On Jul 6, 1:08 am, Sergey Poberezovskiy
    <> wrote:
    > 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
     
    -Karl, Jul 6, 2007
    #12
  13. On Jul 6, 10:16 pm, -Karl <> wrote:
    > 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?
     
    Alexey Smirnov, Jul 7, 2007
    #13
  14. -Karl

    -Karl Guest

    > 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.
     
    -Karl, Jul 9, 2007
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chad
    Replies:
    4
    Views:
    8,345
  2. Ryan
    Replies:
    4
    Views:
    9,003
    Chris Botha
    Nov 8, 2005
  3. Replies:
    3
    Views:
    15,228
  4. Stefan

    Button in WebCustomControl don't fire the onclick event, why?

    Stefan, Jul 8, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    227
    Stefan
    Jul 9, 2003
  5. mbs57

    ASP.NET button control OnClick event doesn't fire

    mbs57, Jun 18, 2009, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    1,432
Loading...

Share This Page