Validate gridview textbox using javascript

Kailash Singh
Kailash...
Participant
66 Points
28 Posts

Hello Sir, How to Validate Grid View's Text Box  using Javascript to on blur ?

Views: 8213
Total Answered: 1
Total Marked As Answer: 0
Posted On: 08-Dec-2015 09:04

Share:   fb twitter linkedin
Answers
Rahul Maurya
Rahul M...
Moderator
1172 Points
211 Posts
         

Hi Kailash,

On Gridview rowdatabound event add an attribute onblur as : 

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
TextBox txt = new TextBox();
txt =(TextBox) e.Row.FindControl("TextBox1");
txt.Attributes.Add("onblur", "blurmethodValidate(this);");
}
}

 And Aspx page: 

<asp:GridView ID="GridView1" OnRowDataBound="gv_RowDataBound" runat="server">
 
<Columns>
 
<asp:TemplateField>
 
<HeaderTemplate>
 
</HeaderTemplate>
 
<ItemTemplate>
 
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
 
</ItemTemplate>
 
</asp:TemplateField>
 
</Columns>
 
</asp:GridView>

 Javascript method: 

<script> 
function blurmethodValidate(txt) {
alert($(txt).val());
</script>
Posted On: 08-Dec-2015 09:33
 Log In to Chat