I want to make Validation (using javascript) on TextBox that is found in EditItemTemplate of gridview to force the user not to enter blank value
I just wrote :
this code neither call serverside function nor clientside.
I tried to get access to update button in RowDataBound Event and wrote:
btnupdate.Attributes.Add("onclick",return ValidateTextBox()");
but it seems that RowDataBound Event returns the rows that are in normal state only not in edit state
Any Suggestions would be too much appreciated

ArshadRank #2,492 · 564 reputationPosted Sep 27, 2010, 12:56 AM EDT
Regards,
Arshad.
Manikavelu VelayuthamRank #413 · 6K reputationPosted Sep 22, 2010, 9:03 PM EDT
It wont work, Becuase textbox is present inside another control, clientid will be generated like "ctl00_txtname" like that. You have to view the source in browser to see how the client id is generated.
To validate the textbox inside the gridview, you need to add the attribute to the textbox in ItemDataBound or RowDataBound of the gridview. so that each textbox in the row will be assigned to that validation.
dina21 reputationPosted Sep 22, 2010, 11:05 PM EDT
could you tell me how to access this textbox in rowdatabound event?
Manikavelu VelayuthamRank #413 · 6K reputationPosted Sep 22, 2010, 11:45 PM EDT
{
//to get the template field value
TextBox tx1 = (TextBox)GridView1.Rows[count].FindControl("txt1");
//You can add the attributes here
tx1.Attributes.Add("OnBlur","Javascript");
}
dina21 reputationPosted Sep 22, 2010, 11:54 PM EDT
dina21 reputationPosted Sep 23, 2010, 12:05 AM EDT
but error raised "object is required"
ArshadRank #2,492 · 564 reputationPosted Sep 23, 2010, 10:25 PM EDT
The above mention code is correct. use like that.
Button btn=new Button();
TextBox txtBox=new TextBox();
for (int i= 0; i< GridView1.Rows.Count; i++)
{
btn =(Button)GridView1.Rows[i].FindControl("btnupdate");
txtBox= (TextBox)GridView1.Rows[i].FindControl("txtBoxID");
btn.Attributes.Add("onclick","CallJavaScripFunction('"+txtBox.ClientID+"')");
}
Add this peace of code after the DataBind() Method.
Regards,
Arshad.
dina21 reputationPosted Sep 24, 2010, 2:36 PM EDT
Best regards.