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
ArshadPosted Sep 27, 2010, 4:56 AM
Regards,
Arshad.
dinaPosted Sep 24, 2010, 6:36 PM
Best regards.
ArshadPosted Sep 24, 2010, 2:25 AM
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.
dinaPosted Sep 23, 2010, 4:05 AM
but error raised "object is required"
dinaPosted Sep 23, 2010, 3:54 AM
Manikavelu VelayuthamPosted Sep 23, 2010, 3:45 AM
{
//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");
}
dinaPosted Sep 23, 2010, 3:05 AM
could you tell me how to access this textbox in rowdatabound event?
Manikavelu VelayuthamPosted Sep 23, 2010, 1:03 AM
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.