Validate gridview textbox using javascript

Kailash Singh
Kailash...
Participant
206 Points
23 Posts

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

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

Share:   fb twitter linkedin
Answers
Rahul Maurya
Rahul M...
Teacher
4822 Points
23 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