Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to fire a server side function from client side

Reply
Thread Tools

How to fire a server side function from client side

 
 
Vili
Guest
Posts: n/a
 
      02-18-2008
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
 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      02-18-2008
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
 
Vili
Guest
Posts: n/a
 
      02-19-2008
On 18 helmi, 17:38, "Eliyahu Goldin"
<(E-Mail Removed)> 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
 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      02-19-2008
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On 18 helmi, 17:38, "Eliyahu Goldin"
> <(E-Mail Removed)> 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



 
Reply With Quote
 
Vili
Guest
Posts: n/a
 
      02-19-2008
On 19 helmi, 11:03, "Eliyahu Goldin"
<(E-Mail Removed)> 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
 
Reply With Quote
 
siccolo
Guest
Posts: n/a
 
      02-19-2008
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>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Server-side events do not fire the first time after client-side validators have fired Stuart Whiteford ASP .Net 2 04-25-2006 10:10 AM
Fire server side event before client side event ASP .Net Web Controls 3 03-18-2005 03:20 PM
Web User Control - fire function from client side Ant ASP .Net 3 11-04-2004 08:32 AM
Client side validation does not fire on deployment server Mark ASP .Net 2 05-13-2004 03:21 PM



Advertisments