EDIT: Here is a screenshot of the rendered page:\n
Maybe you can change asp:button for a html button:
\n\n<button onclick=\"mean( document.getElementById('<%=TextBoxA.ClientID%>'));\" ></button>\n
\n\nOr try getting client ids inside js function:
\n\nASPX
\n\n<!DOCTYPE html>\n\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head runat=\"server\">\n <title></title>\n <script type=\"text/javascript\">\n function mean() {\n var a = document.getElementById('<%=TextBoxA.ClientID%>');\n var b = document.getElementById('<%=TextBoxB.ClientID%>');\n var c = document.getElementById('<%=TextBoxC.ClientID%>');\n alert(a.value);\n alert(b.value);\n alert(c.value);\n }\n </script>\n</head>\n<body>\n <form id=\"form1\" runat=\"server\">\n <div>\n <asp:TextBox ID=\"TextBoxA\" runat=\"server\" ></asp:TextBox>\n <asp:TextBox ID=\"TextBoxB\" runat=\"server\" ></asp:TextBox>\n <asp:TextBox ID=\"TextBoxC\" runat=\"server\" ></asp:TextBox>\n <asp:Button runat=\"server\" ID=\"Calculate_Mean\" Text=\"Calculate Mean\" \n OnClientClick=\"mean();\" />\n </div>\n </form>\n</body>\n</html>\n
\n","author":{"@type":"Person","name":"Mate"},"upvoteCount":1}}}Reputation: 65
This one looks similar to the question that is asked here but the scenario asked by the OP looks different as his accepted answer do does not meet my requirement.In my case, I am trying to embed an asp snippet as parameter of a Javascript method called from an onclick
of button , but the result is that the tags gets escaped when compiled. The ASP code is :
<asp:Button runat="server" ID="Calculate_Mean" Text="Calculate Mean"
OnClientClick="mean('<%$TextBoxA.ClientID + ',' + TextBoxB.ClientID + ',' +
TextBoxC.ClientID%>')"
The Outcome I got is:
<input type="submit" name="Calculate_Mean"
value="Calculate Mean"
onclick="mean('<%=TextBoxA.ClientID%>');" id="Calculate_Mean" />
I've referred and tried the following pages but still couldn't solve the issue:
Passing ASP.net control to JS Function
Different Embedded ASP Code Blocks and its uses
EDIT: Here is a screenshot of the rendered page:
Upvotes: 0
Views: 83
Reputation: 5284
Maybe you can change asp:button for a html button:
<button onclick="mean( document.getElementById('<%=TextBoxA.ClientID%>'));" ></button>
Or try getting client ids inside js function:
ASPX
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function mean() {
var a = document.getElementById('<%=TextBoxA.ClientID%>');
var b = document.getElementById('<%=TextBoxB.ClientID%>');
var c = document.getElementById('<%=TextBoxC.ClientID%>');
alert(a.value);
alert(b.value);
alert(c.value);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBoxA" runat="server" ></asp:TextBox>
<asp:TextBox ID="TextBoxB" runat="server" ></asp:TextBox>
<asp:TextBox ID="TextBoxC" runat="server" ></asp:TextBox>
<asp:Button runat="server" ID="Calculate_Mean" Text="Calculate Mean"
OnClientClick="mean();" />
</div>
</form>
</body>
</html>
Upvotes: 1