如何在一个按钮单击中调用javascript函数,该按钮位于gridview之外,以验证c#中的按钮单击 [英] How to call a javascript function in one button click which is outside a gridview to validate that button click in c#
本文介绍了如何在一个按钮单击中调用javascript函数,该按钮位于gridview之外,以验证c#中的按钮单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的javascript,如下所示
i have a javascript like this as given below
function gvValidate(rowIndex)
{
var grid = document.getElementById('<%= gdvChapterDetails.ClientID %>');
if (grid != null)
{
var Inputs = grid.rows[rowIndex + 1].getElementsByTagName("input");
for (i = 0; i < Inputs.length; i++)
{
if (Inputs[i].type == 'text')
{
if (Inputs[i].value == "") {
alert("* Please Enter The Index Name , Value Should Not Be Empty.");
return false;
}
}
}
return true;
}
}
这是使用下面给出的代码验证网格内的按钮,该代码位于rowdatabound内部
this is validating a button inside grid using the code given below which is inside rowdatabound
Button.Attributes.Add("Onclick", "return gvValidate(" + e.Row.RowIndex.ToString() + ")");
它工作得很好。
但我的问题是
所以像
it is working perfectly fine.
but my problem is
so like
Button.Attributes.Add("Onclick", "return gvValidate(" + e.Row.RowIndex.ToString() + ")");
this。
this .
i need to validate a button which is outside gridview using this script?
can anyone help me in this?
我的保存按钮名称是BtnContinue。
my saving button name is BtnContinue.
推荐答案
如果我理解正确,你需要在继续操作之前对网格的所有行进行验证。
编写新的验证函数:
If I understand correctly, you need to do validation of all the rows of the grid before continuing with the operation.
Write new validating function along the lines:
function validateGrid() {
var rows =
( #grid TR跨度>);
rows.each( function (index){
if (!validateRow( this ))
return false ; // 这将停止循环,首先一个无效意味着网格无效
}
}
function validateRow(row){
if (row.value< 0 ) return false ; // 这里你必须找到行中的值元素(尝试使用td选择器和eq(索引)函数
return true ;
}
("#grid tr"); rows.each(function (index) { if (!validateRow(this)) return false; // this will stop the loop, first one not valid means the grid is not valid } } function validateRow(row) { if (row.value < 0 ) return false; // here you have to of course find the value from the row elements (try using td selector and eq(index) function return true; }
玩一下你的具体细节
Play a bit for your concrete details
这篇关于如何在一个按钮单击中调用javascript函数,该按钮位于gridview之外,以验证c#中的按钮单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文