Click here to Skip to main content
15,894,907 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Good Morning to every one in my project i am using grid view inside grid view footer template using two text box one is single line text box another one is multy line text box i am using the following code to validate the text box in JavaScript
C#
var gridViewID = "<%=grdMenu.ClientID %>";
           var gridView = document.getElementById(gridViewID);
           var Menuitem = new Ncoretech.Business.Data.MenuType();
           var e = document.getElementById("<%= ddlRestaurantName.ClientID%>");
           var gridViewControls = gridView.getElementsByTagName("input");
           for (i = 0; i < gridViewControls.length; i++) {
                   if (gridViewControls[i].id.search("txtNewMenuName") != "-1") {
                   Menuitem.MenuName = gridViewControls[i].value;
               }
               else if (gridViewControls[i].id.search("txtNewMenuDescription") != "-1") {
                   Menuitem.MenuDescription = gridViewControls[i].value;
               }
           }
           Menuitem.RestaurantIndex_Id = e.options[e.selectedIndex].value;
           if (Menuitem.MenuName == "") {
               alert("Item name has to be enter.");
               return false;
           }
           if (Menuitem.MenuDescription == "") {
               Menuitem.MenuDescription = "none";
           }



in the above method the single line textbox having no problem but in the multiline textbox id not shown in the gridViewControls.How can i solve this please any one help to me.
Thanks in advance
By
Meganathan M
Posted

1 solution

Multiline textbox is not a part of INPUT element group, rather it is a TEXTAREA tag. So you need to fetch this also.
For example-
JavaScript
var gridViewID = "<%=grdMenu.ClientID %>";
           var gridView = document.getElementById(gridViewID);
           var Menuitem = new Ncoretech.Business.Data.MenuType();
           var e = document.getElementById("<%= ddlRestaurantName.ClientID%>");
           var gridViewControls = gridView.getElementsByTagName("input");
           for (i = 0; i < gridViewControls.length; i++) {
               if (gridViewControls[i].id.search("txtNewMenuName") != "-1") {
                   Menuitem.MenuName = gridViewControls[i].value;
               }
           }
           gridViewControls = gridView.getElementsByTagName("textarea");
           for (i = 0; i < gridViewControls.length; i++) {
               if (gridViewControls[i].id.search("txtNewMenuDescription") != "-1") {
                   Menuitem.MenuDescription = gridViewControls[i].value;
               }
           }
           Menuitem.RestaurantIndex_Id = e.options[e.selectedIndex].value;
           if (Menuitem.MenuName == "") {
               alert("Item name has to be enter.");
               return false;
           }
           if (Menuitem.MenuDescription == "") {
               Menuitem.MenuDescription = "none";
           }


Hope this may help you out...

Regards,
Niral Soni
 
Share this answer
 
Comments
meganathanm 27-Jul-12 4:45am    
Thank you Mr.NIRAL SONI this method working fine You save my times thanks a lot i have another one problem if i am using var gridViewControls = gridView.getElementsByTagName("Image"); the IE show the controls but Firefox,Safari,Chrome not show how can i solve this
Thanks
By
Meganathan
Niral Soni 28-Jul-12 6:34am    
Try getElementsByTagName('img')
meganathanm 31-Jul-12 8:27am    
Thank you Mr.NIRAL SONI this method working fine You save my times thanks a lot.Sorry for late reply

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900