我在我的页面中引用了我的 javascript,如下所示
<script src="JScript1.js" type="text/javascript"></script>
这些是我在该脚本文件中的函数
function multiplication(txtQuantity) {
var weight = document.getElementById(txtQuantity).value;
}
function f(sender, args) {
args.IsValid = false;
var gridview = document.getElementById("<%=Gridview1.ClientID%>");
var txt = gridview.getElementsByTagName("textarea");
for (i = 0; i < txt.length; i++) {
if (txt[i].id.indexOf("TextBox1") != -1) {
if (txt[i].value == '') {
args.IsValid = false;
}
else {
args.IsValid = true;
}
}
}
}
function f1(sender, args) {
args.IsValid = false;
var gridview = document.getElementById("<%=Gridview1.ClientID%>");
var txt = gridview.getElementsByTagName("textarea");
for (i = 0; i < txt.length; i++) {
if (txt[i].id.indexOf("TextBox2") != -1) {
if (txt[i].value == '') {
args.IsValid = false;
}
else {
args.IsValid = true;
}
}
}
}
我想从后面的代码中调用这些函数,并且我想将该函数分配给自定义验证器
我尝试了一些如下但不工作
<asp:CustomValidator ID="custValCountry" runat="server" ValidationGroup="Country"
ValidateEmptyText="true" ControlToValidate="TextBox1" ClientValidationFunction="javascript:f"
ErrorMessage="Other is required"></asp:CustomValidator>
另外,我在我的RowDataBound
活动中写如下,这也不起作用
protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TextBox txt = (TextBox)e.Row.FindControl("TextBox1");
Page.ClientScript.RegisterClientScriptBlock(txt.GetType(), "onBlur", "multiplication('" + txt.ClientID + "')");
//Page.ClientScript.RegisterClientScriptBlock(, "Script", "alert('Records Successfuly Saved!');", true);
// txt.Attributes.Add("onBlur", "return javascript:multiplication('" + txt.ClientID + "');");
//TextBox txt1 = (TextBox)e.Row.FindControl("TextBox2");
txt1.Attributes.Add("onBlur", "return javascript:multiplication('" + txt1.ClientID + "');");
}
}
有人能帮我吗