How to fire a server side function from client side

  • Thread starter Thread starter Vili
  • Start date Start date
V

Vili

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
 
What you describe is called "server-side events". All you need is to setup
OnClick events for your buttons.

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
 
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 said:
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
 
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
 
Back
Top