well I want to know if javascript works well with asp controls


for example:

here is simple example:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
            function exe() {
                var a = parseInt(document.getElementById("txt").value);
                var b = parseInt(document.getElementById("txt1").value);
                document.getElementById("txt2").value = a - b;
            }
        </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txt" runat="server" />
        <asp:TextBox ID="txt1" runat="server" />
        <asp:TextBox ID="txt2" runat="server" />
        <asp:Button runat="server" Text="Click Me"  OnClientClick="return exe()"  />
        <input type="button" value="Click" onclick="return exe()" />
    </div>
    </form>
</body>
</html>

when I clik on asp button it runs postback, but when I click on HTML button there is not postback...

is it my browser's fault??...

Styles_p,

This is more of an ASP.NET question than Javascript/DHTML/AJAX.

I think you will find that most folks who monitor this section (myself included), won't have a clue about ASP.NET.

As far as I can tell, you can't mix and match raw html with asp: controls. They appear to be mutually exclusive.

This works without modifying the javascript:

<form id="form1">
  <div>
    <input id="txt" />
    <input id="txt1" />
    <input id="txt2" />
    <input type="button" value="Click" onclick="return exe()" />
  </div>
</form>

Airshow

asp.net rewrites all runat=server stuff so the javascript is looking for objects that are given different names on rendering. There are attributes that you can use in the server controls to force id's on them but in all honesty I can't remember what they are. What I can remember is that it turned out to be a rather popular question when I googled it, and some of the results even had answers too - unlike this one.

All I want to know why asp button does postback with Javascript, there is event OnClientClick which must work with javascript, but it doesn't work...

It's the defaul behaviour for buttons wot runat server.
Try:
UseSubmitBehavior="False" along with OnClientClick="return exe();"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.