Re: I don't get javascript. How do you use it?



On Sat, 24 Mar 2007 13:52:31 -0400, "Tony Girgenti"
<tony(nospam)@lakesideos.com> wrote:

Hello Mark and Mark.

I tried it both Mark Fitzpatrick's way and Mark Rae's way. Either way does
not give an error, but it does not do anything.

<input id="Button1" style="z-index: 103; left: 496px; position: absolute;
top: 392px"
type="button" value="button" onClick="ShowCal;" />
<asp:Button ID="Button2" runat="server" Style="z-index: 104; left: 688px;
position: absolute; top: 392px" Text="Button" onClientClick="ShowCal();" />

When i click Button1, it does nothing and puts an "Error on page" on the
bottom of the IE screen and does nothing. When i click Button2, i can see
the progress bar at the bottom of the IE screen, but it does nothing.

Thanks,
Tony

"Mark Rae" <mark@xxxxxxxxxxxxxxxxx> wrote in message
news:uKWUbTjbHHA.4888@xxxxxxxxxxxxxxxxxxxxxxx
"Tony Girgenti" <tony(nospam)@lakesideos.com> wrote in message
news:OfTZE7ibHHA.2300@xxxxxxxxxxxxxxxxxxxxxxx

I tried some javascript testing in VS2005, SP1, VB , .NET 2.0, ASP.NET
2.0 on WIN XP Pro, SP2.

It's real simple. I put a button on a page and coded the onClick in it
like this:
<asp:Button ID="Button1" runat="server" Style="z-index: 103; left: 528px;
position: absolute; top: 392px" Text="Button" OnClick="ShowCal" />

Here is the function:
<script type="text/javascript" language="javascript">
function ShowCal() {
var x = Button1.Style.z - index;
alert(x);
}
</script>

It won't let me run the program saying "'ShowCal' is not a member of
'ASP.default_aspx'"

If javascript is so popular, why can't i use it?

Because you're not calling it... The OnClick event of an <asp:Button> will
cause the page to post back (unless you're using AJAX or something
similar) and try to run a server-side method...

Change your code to the following:

<asp:Button ID="Button1" runat="server" Style="z-index: 103; left: 528px;
position: absolute; top: 392px" Text="Button" OnClientClick="ShowCal();"
/>

It's difficult to give a complete answer to you question without looking
at your entire page. However: your javascript function is:

function ShowCal() {
var x = Button1.Style.z - index;
alert(x);
}

There's an error there but no matter ... are you sure that the html
version of <asp:Button ID="Button1" ... /> actually has the same id that
you gave to the server-side control. That's not always the case (e.g.
when using master pages).

Your javascript should've been:

function ShowCal() {
var x = document.getElementById('<%=Button1.ClientID
%>').Style.zIndex;
alert(x);
}

You can view your html code by typing: view-source: before the URL in
the address bar (if the right context View Source command has been
disabled or if you don't have an Edit button in your browser toolbar.
.


Loading