How to fire a server side function from client side

Discussion in 'ASP .Net' started by Vili, Feb 18, 2008.

  1. Vili

    Vili Guest

    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.attributes.add("onclick",
    javascript:__dopostback('','');) ?

    Thanks

    Tuomo
     
    Vili, Feb 18, 2008
    #1
    1. Advertising

  2. 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/egoldin
    http://usableasp.net


    "Vili" <> wrote in message
    news:...
    > 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.attributes.add("onclick",
    > javascript:__dopostback('','');) ?
    >
    > Thanks
    >
    > Tuomo
     
    Eliyahu Goldin, Feb 18, 2008
    #2
    1. Advertising

  3. Vili

    Vili Guest

    On 18 helmi, 17:38, "Eliyahu Goldin"
    <> wrote:
    > 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
     
    Vili, Feb 19, 2008
    #3
  4. 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]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Vili" <> wrote in message
    news:...
    > On 18 helmi, 17:38, "Eliyahu Goldin"
    > <> wrote:
    >> 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
     
    Eliyahu Goldin, Feb 19, 2008
    #4
  5. Vili

    Vili Guest

    On 19 helmi, 11:03, "Eliyahu Goldin"
    <> wrote:
    > 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
     
    Vili, Feb 19, 2008
    #5
  6. Vili

    siccolo Guest

    another way of doing this - is to use
    Page.ClientScript.RegisterClientScriptBlock() and
    Page.ClientScript.GetCallbackEventReference()....

    .... more at <a href="http://www.siccolo.com/articles.asp">Siccolo
    Articles</a>
     
    siccolo, Feb 19, 2008
    #6
    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. ken busse
    Replies:
    2
    Views:
    467
  2. Mark
    Replies:
    2
    Views:
    2,472
    Alphonse Giambrone
    May 13, 2004
  3. Ant
    Replies:
    3
    Views:
    765
    Andy Fish
    Nov 4, 2004
  4. Stuart Whiteford
    Replies:
    2
    Views:
    751
    Stuart Whiteford
    Apr 25, 2006
  5. Guest

    Fire server side event before client side event

    Guest, Mar 17, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    608
    Ken Cox [Microsoft MVP]
    Mar 18, 2005
Loading...

Share This Page