Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Quote:
i have a editable Gridview(containing 7 editable fields/textbox in each row).on button(update) click i want to find the id of the all the textbox so that i can check if the textbox is empty or not. for that i am doing this as the textbox of the client id in chrome GridSubMeter_ctl10_txtMeterIdnbut but the client id is getting dynamically made in different browsers(different in firefox,opera).


var v = val.id.split('_')[2];
           var merter = document.getElementById('GridSubMeter_' +  v +'txtMeterIdn_' ).value.trim();
           var Billper = document.getElementById('GridSubMeter_' + v + 'txBillPer_' ).value.trim()
           var Endkwh = document.getElementById('GridSubMeter_' + v + 'txEndKwh_' ).value.trim();
           var startkwh = document.getElementById('GridSubMeter_' + 'txStartKwh_').value.trim();
           var ReadEndDate = document.getElementById('GridSubMeter_' +  v+'txReadEndDate_' ).value.trim();
           var ReadStartDate = document.getElementById('GridSubMeter_' + v+'txReadStartDate_' ).value.trim();
           var CTFACT = document.getElementById('GridSubMeter_' + v+ 'txCTFact_' ).value.trim();


function fnCheck(val) {
              var success = true;
              var text1 = val.value;
              var v = val.id.split('_')[2];
              var merter = document.getElementById('GridSubMeter_' +  v +'txtMeterIdn_' ).value.trim();
              var Billper = document.getElementById('GridSubMeter_' + v + 'txBillPer_' ).value.trim()
              var Endkwh = document.getElementById('GridSubMeter_' + v + 'txEndKwh_' ).value.trim();
              var startkwh = document.getElementById('GridSubMeter_' + 'txStartKwh_').value.trim();
              var ReadEndDate = document.getElementById('GridSubMeter_' +  v+'txReadEndDate_' ).value.trim();
              var ReadStartDate = document.getElementById('GridSubMeter_' + v+'txReadStartDate_' ).value.trim();
              var CTFACT = document.getElementById('GridSubMeter_' + v+ 'txCTFact_' ).value.trim();

              var btn = document.getElementById('GridSubMeter_' + v+'btn_Update_' );
              debugger;
                          if (merter != '') {
                          }
                          else {
                              alert("Meter Identifier is Required Field");
                              success = false;
                          }
              if (Billper != '') {
              }
              else {
                  alert("Bill Period is Required Field");
                  success = false;
              }
              if (Endkwh != '') {
              }
              else {
                  alert("EndKwh is Required Field");
                  success = false;
              }
              if (startkwh != '') {
              }
              else {
                  alert("StartKwh is Required Field");
                  success = false;
              }
              if (ReadEndDate != '') {
              }
              else {
                  alert("Read EndDate is Required Field");
                  success = false;
              }
              if (ReadStartDate != '') {
              }
              else {
                  alert("Read StartDate is Required Field");
                  success = false;
              }
                          if (CTFACT != '') {
                          }
                          else {
                              alert("CT Factor is Required Field");
                              success = false;
                          }


What I have tried:

ar v = val.id.split('_')[2];
           var merter = document.getElementById('GridSubMeter_' +  v +'txtMeterIdn_' ).value.trim();
           var Billper = document.getElementById('GridSubMeter_' + v + 'txBillPer_' ).value.trim()
           var Endkwh = document.getElementById('GridSubMeter_' + v + 'txEndKwh_' ).value.trim();
           var startkwh = document.getElementById('GridSubMeter_' + 'txStartKwh_').value.trim();
           var ReadEndDate = document.getElementById('GridSubMeter_' +  v+'txReadEndDate_' ).value.trim();
           var ReadStartDate = document.getElementById('GridSubMeter_' + v+'txReadStartDate_' ).value.trim();
           var CTFACT = document.getElementById('GridSubMeter_' + v+ 'txCTFact_' ).value.trim();
Posted
Updated 14-May-17 16:45pm

1 solution

To make it some simple you can set "
ClientIDMode="Static"
to your controls inside gridview. This will allow you to use same "ID" you set for control in Javascript.

E.g. Assuming I have LinkButton control with ID 'link1' inside Gridview control. If ClientIDMode is set to Static you can aceess this control with same id 'link1'.

If this property not set to static ASP.NET will have control loaded with something like '
GridView1_link1_0
' and you need to have code in javascript like you are tryinh now.
 
Share this answer
 
Comments
Richard Deeming 16-May-17 11:50am    
A static client ID isn't going to work in a GridView - you'd end up with multiple controls with the same ID.

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