Click here to Skip to main content
15,886,753 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

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

where LinkToButton is my button.

C#
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;
        }
    }


if it is not empty it should work with another javascript as given below
C#
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;");


but in my page it is firing only the 2nd javascript. And there is no onclick function inside the grid. ie
C#
<asp:Button ID="Btnlnk" runat="server" Text="Link To" CssClass="btn-info"   />

the above part is not there in my design.
i added the below code to rowdatabound in order to make it work,
C#
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;");
                    }
                }
            }

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?
Posted
Updated 21-Aug-14 0:57am
v9
Comments
PhilLenoir 21-Aug-14 9:22am    
I notice that your button ID is BtnLink. How are you instatiating LinkToButton?

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:
 
Share this answer
 
Comments
Member 11017651 21-Aug-14 4:08am    
How ? Help me to write that 3rd javacsript function?
use below code

C#
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;
            }
        }
 
Share this answer
 
Comments
Member 11017651 21-Aug-14 6:32am    
i already tried this .It is not Working, sorry. And My other buttons stopped working after adding This.
ClimerChinna 21-Aug-14 6:42am    
from which event you are adding this event to the button
Member 11017651 21-Aug-14 6:44am    
In Rowdatabound
ClimerChinna 21-Aug-14 6:47am    
why it was not working for you its working fine here
i have used below code in rowdatabound event check that once
if (e.Row.DataItem != null)
{
Button btnsubmit = (Button)e.Row.FindControl("btnsubmit");
btnsubmit.Attributes.Add("onclick", "return gviewValidate(" + e.Row.RowIndex.ToString() + ")");
}
Member 11017651 21-Aug-14 6:52am    
i have another 2 buttons . if i add this code it will open the popup page for that button clicks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900