如何使用javascript获取网格内一行中所有文本框的客户端ID? [英] How to get the client id of all the textbox in a row inside the grid on using javascript?

查看:56
本文介绍了如何使用javascript获取网格内一行中所有文本框的客户端ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Quote:

我有一个可编辑的Gridview(每行包含7个可编辑的字段/文本框).on按钮(更新)点击我想要的找到所有文本框的ID,以便我可以检查文本框是否为空。为此,我在Chrome GridSubMeter_ctl10_txtMeterIdn中作为客户端ID的文本框进行此操作,但客户端ID是在不同的浏览器中动态制作的(在firefox,opera中不同)。

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();

推荐答案

为了使它变得简单,您可以将
To make it some simple you can set "
ClientIDMode="Static"

设置为gridview中的控件。这将允许您使用相同的ID设置在Javascript中进行控制。



例如假设我在Gridview控件中有IDlink1的LinkBut​​ton控件。如果ClientIDMode设置为Static,你可以使用相同的id控制此控件'link1'。



如果此属性未设置为静态ASP.NET将控件加载类似'

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

'并且你需要在javascript中拥有代码,就像你现在正在尝试一样。

' and you need to have code in javascript like you are tryinh now.


这篇关于如何使用javascript获取网格内一行中所有文本框的客户端ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆