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() + ")");
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;
}
}
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;");
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" />
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;");
}
}
}
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?