How to fire a server side function from client side

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vili

    #1

    How to fire a server side function from client side

    Hi all

    I am having a problem here

    Is it possible to fire a server side function from client side?

    ie. I have a function on codebehind

    Sub DoSomething(o as object)

    'do something to o

    End sub

    and on button press I dynamically create few linkbuttons (or something
    else if needed) and for each linkbuttons I would need to launch the
    DoSomething function from codebehind?

    I have read that with javascript __doPostback it would be possible but
    have no idea how to.

    Something like mybutton.attrib utes.add("oncli ck",
    javascript:__do postback('','') ;) ?

    Thanks

    Tuomo
  • Eliyahu Goldin

    #2
    Re: How to fire a server side function from client side

    What you describe is called "server-side events". All you need is to setup
    OnClick events for your buttons.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]




    "Vili" <virallinen@gma il.comwrote in message
    news:ac64b565-a893-4e17-9da0-298f745325f1@v3 g2000hsc.google groups.com...
    Hi all
    >
    I am having a problem here
    >
    Is it possible to fire a server side function from client side?
    >
    ie. I have a function on codebehind
    >
    Sub DoSomething(o as object)
    >
    'do something to o
    >
    End sub
    >
    and on button press I dynamically create few linkbuttons (or something
    else if needed) and for each linkbuttons I would need to launch the
    DoSomething function from codebehind?
    >
    I have read that with javascript __doPostback it would be possible but
    have no idea how to.
    >
    Something like mybutton.attrib utes.add("oncli ck",
    javascript:__do postback('','') ;) ?
    >
    Thanks
    >
    Tuomo

    Comment

    • Vili

      #3
      Re: How to fire a server side function from client side

      On 18 helmi, 17:38, "Eliyahu Goldin"
      <REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
      What you describe is called "server-side events". All you need is to setup
      OnClick events for your buttons.
      >
      --
      Eliyahu Goldin,
      Software Developer
      Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
      The problem is the dynamic controls. They get no events when clicked
      on. If I could create them in page_init I could add event handel
      but at the init I have no idea what buttons will be created

      Tuomo

      Comment

      • Eliyahu Goldin

        #4
        Re: How to fire a server side function from client side

        It is very rear when you really need to create controls in code. The proper
        way is to put them in an item template of a databound control and databind
        the control in run-time. Then you can setup all the events in the template.

        --
        Eliyahu Goldin,
        Software Developer
        Microsoft MVP [ASP.NET]




        "Vili" <virallinen@gma il.comwrote in message
        news:dac6cf45-73a8-4d36-851a-48bcc0495cde@64 g2000hsw.google groups.com...
        On 18 helmi, 17:38, "Eliyahu Goldin"
        <REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
        >What you describe is called "server-side events". All you need is to
        >setup
        >OnClick events for your buttons.
        >>
        >--
        >Eliyahu Goldin,
        >Software Developer
        >Microsoft MVP
        >[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
        >
        The problem is the dynamic controls. They get no events when clicked
        on. If I could create them in page_init I could add event handel
        but at the init I have no idea what buttons will be created
        >
        Tuomo

        Comment

        • Vili

          #5
          Re: How to fire a server side function from client side

          On 19 helmi, 11:03, "Eliyahu Goldin"
          <REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
          It is very rear when you really need to create controls in code. The proper
          way is to put them in an item template of a databound control and databind
          the control in run-time. Then you can setup all the events in the template.
          True! I just realised that I might have been able to use repeater on
          this to make the same thing I am trying to do now

          Thank you all for your answers. I was too focused on getting the
          serverside event fired from javascript to see that there
          might be a better solution.

          Tuomo

          Comment

          • siccolo

            #6
            Re: How to fire a server side function from client side

            another way of doing this - is to use
            Page.ClientScri pt.RegisterClie ntScriptBlock() and
            Page.ClientScri pt.GetCallbackE ventReference() ....

            .... more at <a href="http://www.siccolo.com/articles.asp">S iccolo
            Articles</a>

            Comment

            Working...