Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > calling JavaScript function from code-behind

Reply
Thread Tools

calling JavaScript function from code-behind

 
 
Alexander Kaplunov
Guest
Posts: n/a
 
      06-16-2004
Hello,

I was wondering if there is a way to call a JavaScript function from
code-behind. I know that you can add a "onclick" attribute to a button but
that is not what I'm looking for. What I'm looking for is something similar
to this:

Client side:

function test()
{
alert("Got test!");
}

Server side:

public void foo()
{
call_javascript_function("test");
}

Is there a way to accomplish this?

Any help is appreciated.
Alex.


 
Reply With Quote
 
 
 
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      06-17-2004
have a look at registerstartupscript or you can just response.write it out
if push comes to shove

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"Alexander Kaplunov" <> wrote in message
news:%23deHFg$...
> Hello,
>
> I was wondering if there is a way to call a JavaScript function from
> code-behind. I know that you can add a "onclick" attribute to a button but
> that is not what I'm looking for. What I'm looking for is something
> similar
> to this:
>
> Client side:
>
> function test()
> {
> alert("Got test!");
> }
>
> Server side:
>
> public void foo()
> {
> call_javascript_function("test");
> }
>
> Is there a way to accomplish this?
>
> Any help is appreciated.
> Alex.
>
>



 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      06-17-2004
Or, in Page_Load, you can do this:

control.attributes.add(eventHandlerName, clientFunctionToRun)


"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:...
> have a look at registerstartupscript or you can just response.write it out
> if push comes to shove
>
> --
> Regards,
> Alvin Bruney
> [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
> Got tidbits? Get it here... http://tinyurl.com/27cok
> "Alexander Kaplunov" <> wrote in message
> news:%23deHFg$...
> > Hello,
> >
> > I was wondering if there is a way to call a JavaScript function from
> > code-behind. I know that you can add a "onclick" attribute to a button

but
> > that is not what I'm looking for. What I'm looking for is something
> > similar
> > to this:
> >
> > Client side:
> >
> > function test()
> > {
> > alert("Got test!");
> > }
> >
> > Server side:
> >
> > public void foo()
> > {
> > call_javascript_function("test");
> > }
> >
> > Is there a way to accomplish this?
> >
> > Any help is appreciated.
> > Alex.
> >
> >

>
>



 
Reply With Quote
 
Alexander Kaplunov
Guest
Posts: n/a
 
      06-18-2004
Not every control has attributes so this won't work in my case.


"Scott M." <s-> wrote in message
news:...
> Or, in Page_Load, you can do this:
>
> control.attributes.add(eventHandlerName, clientFunctionToRun)
>
>
> "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
> news:...
> > have a look at registerstartupscript or you can just response.write it

out
> > if push comes to shove
> >
> > --
> > Regards,
> > Alvin Bruney
> > [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
> > Got tidbits? Get it here... http://tinyurl.com/27cok
> > "Alexander Kaplunov" <> wrote in message
> > news:%23deHFg$...
> > > Hello,
> > >
> > > I was wondering if there is a way to call a JavaScript function from
> > > code-behind. I know that you can add a "onclick" attribute to a button

> but
> > > that is not what I'm looking for. What I'm looking for is something
> > > similar
> > > to this:
> > >
> > > Client side:
> > >
> > > function test()
> > > {
> > > alert("Got test!");
> > > }
> > >
> > > Server side:
> > >
> > > public void foo()
> > > {
> > > call_javascript_function("test");
> > > }
> > >
> > > Is there a way to accomplish this?
> > >
> > > Any help is appreciated.
> > > Alex.
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      06-18-2004
Alex,

Nearly everything does have an eventhandler (onClick, onLoad, onChange,
onBlur, etc.). Your code doesn't tell us what it is you want to do other
than show us a server call to a client function. When do you need your
client function to fire?

"Alexander Kaplunov" <> wrote in message
news:...
> Not every control has attributes so this won't work in my case.
>
>
> "Scott M." <s-> wrote in message
> news:...
> > Or, in Page_Load, you can do this:
> >
> > control.attributes.add(eventHandlerName, clientFunctionToRun)
> >
> >
> > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
> > news:...
> > > have a look at registerstartupscript or you can just response.write it

> out
> > > if push comes to shove
> > >
> > > --
> > > Regards,
> > > Alvin Bruney
> > > [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
> > > Got tidbits? Get it here... http://tinyurl.com/27cok
> > > "Alexander Kaplunov" <> wrote in message
> > > news:%23deHFg$...
> > > > Hello,
> > > >
> > > > I was wondering if there is a way to call a JavaScript function from
> > > > code-behind. I know that you can add a "onclick" attribute to a

button
> > but
> > > > that is not what I'm looking for. What I'm looking for is something
> > > > similar
> > > > to this:
> > > >
> > > > Client side:
> > > >
> > > > function test()
> > > > {
> > > > alert("Got test!");
> > > > }
> > > >
> > > > Server side:
> > > >
> > > > public void foo()
> > > > {
> > > > call_javascript_function("test");
> > > > }
> > > >
> > > > Is there a way to accomplish this?
> > > >
> > > > Any help is appreciated.
> > > > Alex.
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Alexander Kaplunov
Guest
Posts: n/a
 
      06-18-2004
OK, I am using Microsoft.Web.UI.WebControls.ToolbarButton

This control has a ButtonClick event, which is handeled on the server. What
I really need is when this button is clicked to call a javascript function
on the client side.



"Scott M." <s-> wrote in message
news:...
> Alex,
>
> Nearly everything does have an eventhandler (onClick, onLoad, onChange,
> onBlur, etc.). Your code doesn't tell us what it is you want to do other
> than show us a server call to a client function. When do you need your
> client function to fire?
>
> "Alexander Kaplunov" <> wrote in message
> news:...
> > Not every control has attributes so this won't work in my case.
> >
> >
> > "Scott M." <s-> wrote in message
> > news:...
> > > Or, in Page_Load, you can do this:
> > >
> > > control.attributes.add(eventHandlerName, clientFunctionToRun)
> > >
> > >
> > > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
> > > news:...
> > > > have a look at registerstartupscript or you can just response.write

it
> > out
> > > > if push comes to shove
> > > >
> > > > --
> > > > Regards,
> > > > Alvin Bruney
> > > > [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
> > > > Got tidbits? Get it here... http://tinyurl.com/27cok
> > > > "Alexander Kaplunov" <> wrote in message
> > > > news:%23deHFg$...
> > > > > Hello,
> > > > >
> > > > > I was wondering if there is a way to call a JavaScript function

from
> > > > > code-behind. I know that you can add a "onclick" attribute to a

> button
> > > but
> > > > > that is not what I'm looking for. What I'm looking for is

something
> > > > > similar
> > > > > to this:
> > > > >
> > > > > Client side:
> > > > >
> > > > > function test()
> > > > > {
> > > > > alert("Got test!");
> > > > > }
> > > > >
> > > > > Server side:
> > > > >
> > > > > public void foo()
> > > > > {
> > > > > call_javascript_function("test");
> > > > > }
> > > > >
> > > > > Is there a way to accomplish this?
> > > > >
> > > > > Any help is appreciated.
> > > > > Alex.
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      06-18-2004
you can still use the attributes function and append the javascript to the
particular button. Something like this should work:

//set a pointer to button number 2
ToolbarButton oSchedule = (ToolbarButton)Tools.Items[1];

//append javascript the normal way
oSchedule.Attributes blah blah blah

or you may want to just embed the javascript inside the text of the
particular button on the toolbar. You can do this either thru the above
statement and using

oSchedule.Text = "<onclick = 'somefunction()' span
style="color:brown;Borderutset;">View Rates</span>"

or you can just do it from the text attribute of the toolbar item property
in the designer.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"Alexander Kaplunov" <> wrote in message
news:%...
> OK, I am using Microsoft.Web.UI.WebControls.ToolbarButton
>
> This control has a ButtonClick event, which is handeled on the server.
> What
> I really need is when this button is clicked to call a javascript function
> on the client side.
>
>
>
> "Scott M." <s-> wrote in message
> news:...
>> Alex,
>>
>> Nearly everything does have an eventhandler (onClick, onLoad, onChange,
>> onBlur, etc.). Your code doesn't tell us what it is you want to do other
>> than show us a server call to a client function. When do you need your
>> client function to fire?
>>
>> "Alexander Kaplunov" <> wrote in message
>> news:...
>> > Not every control has attributes so this won't work in my case.
>> >
>> >
>> > "Scott M." <s-> wrote in message
>> > news:...
>> > > Or, in Page_Load, you can do this:
>> > >
>> > > control.attributes.add(eventHandlerName, clientFunctionToRun)
>> > >
>> > >
>> > > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
>> > > news:...
>> > > > have a look at registerstartupscript or you can just response.write

> it
>> > out
>> > > > if push comes to shove
>> > > >
>> > > > --
>> > > > Regards,
>> > > > Alvin Bruney
>> > > > [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
>> > > > Got tidbits? Get it here... http://tinyurl.com/27cok
>> > > > "Alexander Kaplunov" <> wrote in message
>> > > > news:%23deHFg$...
>> > > > > Hello,
>> > > > >
>> > > > > I was wondering if there is a way to call a JavaScript function

> from
>> > > > > code-behind. I know that you can add a "onclick" attribute to a

>> button
>> > > but
>> > > > > that is not what I'm looking for. What I'm looking for is

> something
>> > > > > similar
>> > > > > to this:
>> > > > >
>> > > > > Client side:
>> > > > >
>> > > > > function test()
>> > > > > {
>> > > > > alert("Got test!");
>> > > > > }
>> > > > >
>> > > > > Server side:
>> > > > >
>> > > > > public void foo()
>> > > > > {
>> > > > > call_javascript_function("test");
>> > > > > }
>> > > > >
>> > > > > Is there a way to accomplish this?
>> > > > >
>> > > > > Any help is appreciated.
>> > > > > Alex.
>> > > > >
>> > > > >
>> > > >
>> > > >
>> > >
>> > >
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
Fritz
Guest
Posts: n/a
 
      06-19-2004
"Alvin Bruney [MVP]" <vapor at steaming post office> wrote:

> you can still use the attributes function and append the javascript to the
> particular button. Something like this should work:
>
> //set a pointer to button number 2
> ToolbarButton oSchedule = (ToolbarButton)Tools.Items[1];
>
> //append javascript the normal way
> oSchedule.Attributes blah blah blah
>
> or you may want to just embed the javascript inside the text of the
> particular button on the toolbar. You can do this either thru the above
> statement and using
>
> oSchedule.Text = "<onclick = 'somefunction()' span
> style="color:brown;Borderutset;">View Rates</span>"
>
> or you can just do it from the text attribute of the toolbar item property
> in the designer.
>

Or catch the event at the form level. Add an attribute to the form, then
catch it there. Works properly only for IE.
 
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
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
calling virtual function results in calling function of base class... Andreas Lagemann C++ 8 01-10-2005 11:03 PM
calling virtual function results in calling function of base class ... tiwy C++ 0 01-09-2005 11:17 PM
output text in control location; calling control javascript from page javascript Lisa Calla ASP .Net Building Controls 0 11-09-2004 02:17 AM
Calling Javascript function Krishna ASP .Net 5 07-09-2003 02:23 PM



Advertisments