dina

dina

  • NA
  • 51
  • 0

Unable to make validation in textboxes being located in EditItemTemplate

Sep 22 2010 8:11 PM
Hi All guys,

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 :

<script type="text/javascript" language="javascript">
function
validateTextBox() {
var textElem=document.getElementById('txtname');
if(textElem.value==' '){
alert("You must enter value");
return false;

}

else{
return true;
}


}
</script>

<TemlateField>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtname"></TextBox>
</TemlateField>
</EditItemTemplate>


<TemlateField>
<EditItemTemplate>
<asp:Button runat="server" OnClick="
btnupdate_Click" onClientClick="return validateTextBox()"   ID="btnupdate" Text="Update Name"></Button>
</TemlateField>
</EditItemTemplate>


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











Answers (8)