如何在一个按钮中调用两个javascrpt函数在c#中的网格内单击 [英] How to call two javascrpt functions in one button click inside a grid in c#

查看:57
本文介绍了如何在一个按钮中调用两个javascrpt函数在c#中的网格内单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个页面中有一个网格。在网格内我有3个按钮,Add,Sub,LinkTO一个用于向网格添加一行。第二个是为Add Button和LinkTo添加子行。我将点击子按钮,它将添加一个子。但是它的字段将是空的。之后我将点击链接。在LinkTo按钮单击我应该提出两个javascripts。如果我点击我应检查具有名为name的列的行是否是文本框字段。是否为空。如果它是空的,它应该提高下面的javascript



i have a grid in one page. inside grid i have 3 buttons,Add , Sub ,LinkTO one for adding one row to grid. second is adding subrow for the Add Button and LinkTo. i vll click sub button it will add a subrow . but its field will be empty.after that i will click linkto. in that LinkTo button click i should raise two javascripts. if i click i should check whether that row having a column named name is a textbox field . whether it is empty or not. if it is empty it should raise the below javascript

LinkToButton.Attributes.Add("onclick", "return gviewValidate(" + e.Row.RowIndex.ToString() + ")");



其中LinkToButton是我的按钮。




where LinkToButton is my button.

function gviewValidate(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;
        }
    }





如果它不是空的,它应该与另一个javascript一起使用,如下所示



if it is not empty it should work with another javascript as given below

LinkToButton.Attributes.Add("OnClick", "window.open('../ideal/LinkPopUp.aspx?Rowno=" + Rowno + "','MyWindow','height=600,width=650,left=20,top=20,resizable=no,scrollbars=yes');return false;");





但是在我的页面中它只会触发第二个javascript。并且网格内没有onclick功能。 ie



but in my page it is firing only the 2nd javascript. And there is no onclick function inside the grid. ie

<asp:Button ID="Btnlnk" runat="server" Text="Link To" CssClass="btn-info"   />



以上部分不在我的设计中。

i将以下代码添加到rowdatabound以使其工作,


the above part is not there in my design.
i added the below code to rowdatabound in order to make it work,

TextBox txtName = (TextBox)e.Row.FindControl("txtName");
            if (txtName != null)
            {
                if ((txtName.Text == null) && (txtName.Text == ""))
                {
                    if (LinkToButton != null)
                    {
                        LinkToButton.Attributes.Add("Onclick", "return gvValidate(" + e.Row.RowIndex.ToString() + ")");
                    }
                }
                else
                {
                    Rowno = Convert.ToInt32(gdvChapterDetails.DataKeys[e.Row.RowIndex][0].ToString());
                    if (LinkToButton != null)
                    {
                        LinkToButton.Attributes.Add("OnClick", "window.open('../ideal/LinkPopUp.aspx?Rowno=" + Rowno + "','MyWindow','height=600,width=650,left=20,top=20,resizable=no,scrollbars=yes');return false;");
                    }
                }
            }



但是它仍然只执行最后一个javascript,最后写的是。



帮帮我怎么写javascript?或者请在这里为我写这个javascript函数。如何使它成为我描述的方式?

我编程很差。那么请帮助我实现这个目的吗?


but still it is executing only the last javascript whichever is written last.

Help me how to write the javascript? or please write that javascript function here for me. how to make it the way which i described ?
i am very poor in programming . so please help me somebody to achieve this?

推荐答案

使用您设置为onclick值的第三个JavaScript函数。此函数将执行测试并进行相应的调用并返回:
Use a third JavaScript function that you set as your onclick value. This function will perform the test and make the appropriate calls and return:


使用下面的代码



use below code

function gviewValidate(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 != "") {
                            window.open('../ideal/LinkPopUp.aspx', 'MyWindow', 'height=600,width=650,left=20,top=20,resizable=no,scrollbars=yes');
                            return false;
                        }
                        else {
                            alert("Please enter the Index Name ,Value should not be empty");
                            return false;
                        }

                    }
                }
                return true;
            }
        }


这篇关于如何在一个按钮中调用两个javascrpt函数在c#中的网格内单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆