Calling simple javascript from codebehind???

Calling simple javascript from codebehind???

Post by M O J » Tue, 12 Feb 2002 07:31:39



Hi,

I'm using a DHTML menu in my aspx file.

When the user clicks a parant, this code is fired:

   onclick="menu(0); return false"

...and the branch opens and closes.

Now I've put a button on the page as well and I want to call the javascript
(above) when user clicks the button.

So in my codebehind I've written:

Response.Write("<script language='JavaScript'>menu(0);</script>")

....but it has no effect at all. The branch doesn't open or close.

Can you help me out?

Thanks!

M O J O

 
 
 

Calling simple javascript from codebehind???

Post by Victor Garcia Apre » Tue, 12 Feb 2002 07:51:01


Are you getting any client-side error? Where does your server-side generated
javascript appears (I think its being written passed the </html> tag)?

It will help if you can post some code,

-Victor.



Quote:> Hi,

> I'm using a DHTML menu in my aspx file.

> When the user clicks a parant, this code is fired:

>    onclick="menu(0); return false"

> ...and the branch opens and closes.

> Now I've put a button on the page as well and I want to call the
javascript
> (above) when user clicks the button.

> So in my codebehind I've written:

> Response.Write("<script language='JavaScript'>menu(0);</script>")

> ....but it has no effect at all. The branch doesn't open or close.

> Can you help me out?

> Thanks!

> M O J O


 
 
 

Calling simple javascript from codebehind???

Post by Joe Kin » Tue, 12 Feb 2002 08:07:32


Wouldn't you want to place this code in the client-side OnClick event of the
button?  Just placing it between client script blocks as you have done
doesn't associate it with any clicking action.  This will just invoke the
menu(0); function in-line as the page loads in the browser.

What kind of button are you using?  (HTMLButton, asp:Button or just plain
old <input>)

Regards,

Joseph King
Coalesys, Inc.
http://www.coalesys.com
WebMenu for ASP.NET
PanelBar for ASP.NET



Quote:> Hi,

> I'm using a DHTML menu in my aspx file.

> When the user clicks a parant, this code is fired:

>    onclick="menu(0); return false"

> ...and the branch opens and closes.

> Now I've put a button on the page as well and I want to call the
javascript
> (above) when user clicks the button.

> So in my codebehind I've written:

> Response.Write("<script language='JavaScript'>menu(0);</script>")

> ....but it has no effect at all. The branch doesn't open or close.

> Can you help me out?

> Thanks!

> M O J O

 
 
 

Calling simple javascript from codebehind???

Post by Jim Ross [MVP » Tue, 12 Feb 2002 08:17:35


I suspect that when a table column width is not explicitly set, the
rendered width will not be known until AFTER it has been rendered by
the browser on the client. If you want to control the width from the
server, you'll have to begin by explicitly setting it.


Quote:>Hi,

>I'm using a DHTML menu in my aspx file.

>When the user clicks a parant, this code is fired:

>   onclick="menu(0); return false"

>...and the branch opens and closes.

>Now I've put a button on the page as well and I want to call the javascript
>(above) when user clicks the button.

>So in my codebehind I've written:

>Response.Write("<script language='JavaScript'>menu(0);</script>")

>....but it has no effect at all. The branch doesn't open or close.

>Can you help me out?

>Thanks!

>M O J O

Jim Ross
MS MVP [VC/MFC]

Remove "nospam" to send email, but please ask all questions in the newsgroups, not via private mail

 
 
 

Calling simple javascript from codebehind???

Post by Jim Ross [MVP » Wed, 13 Feb 2002 01:34:56


Oppps... I was responding to a different question here... sorry.


>I suspect that when a table column width is not explicitly set, the
>rendered width will not be known until AFTER it has been rendered by
>the browser on the client. If you want to control the width from the
>server, you'll have to begin by explicitly setting it.


>>Hi,

>>I'm using a DHTML menu in my aspx file.

>>When the user clicks a parant, this code is fired:

>>   onclick="menu(0); return false"

>>...and the branch opens and closes.

>>Now I've put a button on the page as well and I want to call the javascript
>>(above) when user clicks the button.

>>So in my codebehind I've written:

>>Response.Write("<script language='JavaScript'>menu(0);</script>")

>>....but it has no effect at all. The branch doesn't open or close.

>>Can you help me out?

>>Thanks!

>>M O J O

>Jim Ross
>MS MVP [VC/MFC]

>Remove "nospam" to send email, but please ask all questions in the newsgroups, not via private mail

Jim Ross
MS MVP [VC/MFC]

Remove "nospam" to send email, but please ask all questions in the newsgroups, not via private mail