私のページには、スイッチがオンになったときに jQuery 関数を挿入するユーザー コントロールがあります。そして、これはユーザーコントロールの背後にある私のコードです:
public bool isRequired {
set {
if (value == true) {
ClientScriptManager cs = Page.ClientScript;
string csname = "isRequiredScript";
if (!cs.IsClientScriptBlockRegistered(this.GetType(), csname)) {
StringBuilder cstext = new StringBuilder();
cstext.Append("<script type=\"text/javascript\">");
cstext.Append("$(document).ready(function () {");
cstext.Append("function QuestionwithConditionalInfo_validation() {");
cstext.Append("if ($(\"#MainPlaceHolder_" + QuestionOption.ClientID + " :checked\").val() == null) {");
cstext.Append("alert(\"Please answer the question '" + setQuestionText + "'\");");
cstext.Append("return false;");
cstext.Append("}} });");
cstext.Append("</script>");
cs.RegisterClientScriptBlock(this.GetType(), csname, cstext.ToString(), false);
}
}
}
}
次に、メイン ページで、その jQuery 関数を呼び出すことを計画しました。
function childpage_validation() {
if (QuestionwithConditionalInfo_validation() == false)
return false;
}
<asp:Button ID="page1_Next" Text="Next page" runat="server" OnClick="page1_Next_Command" OnClientClick="return childpage_validation()" />
次に、関数が定義されていないというエラーが発生しました。その後、同じエラーが発生した代わりQuestionwithConditionalInfo_validation()
に試しました。誰かが理由を知っていますか?RegisterStartupScript
RegisterClientScriptBlock