자바 스크립트 함수를 추가하면 작동하지 않으며 텍스트를 변경하려고하는 버튼도 작동하지 않습니다. 코드는 javaScript 함수가 내 ASP.Net 컨트롤에서 작동하지 않습니다.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function clientValidate(source, args)
{
if (parseInt(args.Value) < 10)
{
return source.IsValid = false;
}
else
{
return source.IsValid = true;
}
}
function Alert(ctr)
{
alert("Hello");
ctr.Text = "clicked";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Value Must not be Below 10" ClientValidationFunction="clientValidate" OnServerValidate="CustomValidator1_ServerValidate" ControlToValidate="txt" Display="Dynamic" ForeColor="#FF5050"></asp:CustomValidator>
<asp:TextBox ID="txt" runat="server" AutoPostBack="true" ></asp:TextBox>
<asp:Button ID="btn1" runat="server" Text="Button" OnClientClick="Alert(btn1)" />
</div>
</form>
</body>
</html>
한 경고 스크립트 작업을하지만 버튼의 텍스트가 변경되지 않은 것을 말하는 것은 벨로
입니다.다른 것은 검증 자의 서버 측 이벤트가 별도의 cs 파일에 있습니다. 도움을
감사합니다.
형님 감사합니다, 첫 번째 일은 괜찮습니다. 그러나 두 번째 부분에서. 예를 들어, 페이지에서 다른 객체 (예 : asp : 원본 게시물에서 볼 수 있듯이 ID가 txt 인 텍스트 상자 컨트롤)를 전송하여 경고하고 가치를 얻은 다음이를 허용하는 것이 가능합니까? ==> 기능 경고 (ctr) { 경고 ("Hello"+ ctr.Text); } 또는 수행 ==> 기능 알림 (ctr) { alert ("Hello"); ctr.Text = "클릭"; } 가능합니까? – Heydar
내가 이해할 수있는 asp 보낼 수 없습니다 : Contols javascript 메서드. 그래서 그것은 HTML 컨트롤이어야합니다. 그거야? – Heydar
정확하지 않습니다. 'asp : controls'는 HTML 요소로 표현됩니다. 조심해. –