I have a grid view, where user can add a new row. On the adding of row, the id's are changed like this..
我有一个网格视图,用户可以在其中添加新的行。在行相加时,id会像这样变化。
$('<div class=".grdLoaded">').load("GridRow.htm", function () {
// insert the html
$(_InsertionID).after($(this).html());
// now change the default id(s) that were present on GridRow.htm
// to something that represent current value(s)
$('#grdEntry').find('#grdEntry_ctl00_lblSNO').attr('id', 'SNo_' + _insCurRowNumber + '');
$('#grdEntry').find('#grdEntry_ctl00_lblQty').attr('id', 'Qty_' + _insCurRowNumber + '');
$('#grdEntry').find('#grdEntry_ctl00_lblItemName').attr('id', 'ItemName_' + _insCurRowNumber + '');
$('#grdEntry').find('#grdEntry_ctl00_lblProcess').attr('id', 'Prc_' + _insCurRowNumber + '');
$('#grdEntry').find('#grdEntry_ctl00_lblRemarks').attr('id', 'Remarks_' + _insCurRowNumber + '');
$('#grdEntry').find('#grdEntry_ctl00_lblColor').attr('id', 'Color_' + _insCurRowNumber + '');
$('#grdEntry').find('#grdEntry_ctl00_lblAmount').attr('id', 'Amount_' + _insCurRowNumber + '');
where insCurRowNumber
is the current row id that is being added, for the first time its 1, second 2 and so on.. The problem is if I try to access any of these control on server, like this
其中inrownumber是正在添加的当前行id,第一次是它的1、2等等。问题是如果我试图访问服务器上的任何这些控件,就像这样
((Label)grdEntry.Rows[i].FindControl("ItemName_1").Text;
or event if like this
或者像这样的事件
Page.FindControl("ItemName_1")
I get a null reference exception
. Seems like the issue is server side can't find these dynamically generated id(s). If that is the cause how do I circumvent this? If its not the cause then what is causing this behavior and again, how do I find these control(s) to access their value(s)?
我得到一个空引用异常。似乎问题是服务器端找不到这些动态生成的id。如果这就是原因,我该如何规避呢?如果不是原因,那么是什么导致了这种行为,我如何找到这些控件来访问它们的值呢?
EDIT : In response to Steven Hunt, the request was in post format, and here's the key's collection.
编辑:作为对Steven Hunt的回应,请求是post格式的,这里是key的集合。
Request.Form.AllKeys {string[177]} string[]
[0] "__EVENTTARGET" string
[1] "__EVENTARGUMENT" string
[2] "__LASTFOCUS" string
[3] "__VIEWSTATE" string
[4] "__EVENTVALIDATION" string
[5] "check" string
[6] "txtDueDate" string
[7] "txtTime" string
[8] "txtCustomerName" string
[9] "grdEntry$ctl01$txtQty" string
[10] "grdEntry$ctl01$txtName" string
[11] "grdEntry$ctl01$txtProcess" string
[12] "grdEntry$ctl01$txtRate" string
[13] "grdEntry$ctl01$txtRemarks" string
[14] "tags" string
[15] "grdEntry$ctl01$txtColor" string
[16] "txtRemarks" string
[17] "drpCheckedBy" string
[18] "btnSaveBooking" string
[19] "txtCurrentDue" string
[20] "a" string
[21] "txtDiscount" string
[22] "txtDiscount_TextBoxWatermarkExtender_ClientState" string
[23] "txtDiscountAmt" string
[24] "txtSrTax" string
[25] "txtTotal" string
[26] "txtAdvance" string
[27] "txtBalance" string
[28] "txtItemName" string
[29] "txtItemSubQty" string
[30] "txtNewItemName" string
[31] "txtItemCode" string
[32] "hdntemp" string
[33] "hdnItemCode" string
[34] "txtProcessCode" string
[35] "txtProcessName" string
[36] "txtCNameSearch" string
[37] "txtAddress" string
[38] "txtPhoneNo" string
[39] "grdCustomerSearch$ctl02$lnkBtnCustomerCode" string
[40] "grdCustomerSearch$ctl03$lnkBtnCustomerCode" string
[41] "grdCustomerSearch$ctl04$lnkBtnCustomerCode" string
[42] "grdCustomerSearch$ctl05$lnkBtnCustomerCode" string
[43] "grdCustomerSearch$ctl06$lnkBtnCustomerCode" string
[44] "grdCustomerSearch$ctl07$lnkBtnCustomerCode" string
[45] "grdCustomerSearch$ctl08$lnkBtnCustomerCode" string
[46] "grdCustomerSearch$ctl09$lnkBtnCustomerCode" string
[47] "grdCustomerSearch$ctl10$lnkBtnCustomerCode" string
[48] "grdCustomerSearch$ctl11$lnkBtnCustomerCode" string
[49] "grdCustomerSearch$ctl12$lnkBtnCustomerCode" string
[50] "grdCustomerSearch$ctl13$lnkBtnCustomerCode" string
[51] "grdCustomerSearch$ctl14$lnkBtnCustomerCode" string
[52] "grdCustomerSearch$ctl15$lnkBtnCustomerCode" string
[53] "grdCustomerSearch$ctl16$lnkBtnCustomerCode" string
[54] "grdCustomerSearch$ctl17$lnkBtnCustomerCode" string
[55] "grdCustomerSearch$ctl18$lnkBtnCustomerCode" string
[56] "grdCustomerSearch$ctl19$lnkBtnCustomerCode" string
[57] "grdCustomerSearch$ctl20$lnkBtnCustomerCode" string
[58] "grdCustomerSearch$ctl21$lnkBtnCustomerCode" string
[59] "grdCustomerSearch$ctl22$lnkBtnCustomerCode" string
[60] "grdCustomerSearch$ctl23$lnkBtnCustomerCode" string
[61] "grdCustomerSearch$ctl24$lnkBtnCustomerCode" string
[62] "grdCustomerSearch$ctl25$lnkBtnCustomerCode" string
[63] "grdCustomerSearch$ctl26$lnkBtnCustomerCode" string
[64] "grdCustomerSearch$ctl27$lnkBtnCustomerCode" string
[65] "grdCustomerSearch$ctl28$lnkBtnCustomerCode" string
[66] "grdCustomerSearch$ctl29$lnkBtnCustomerCode" string
[67] "grdCustomerSearch$ctl30$lnkBtnCustomerCode" string
[68] "grdCustomerSearch$ctl31$lnkBtnCustomerCode" string
[69] "grdCustomerSearch$ctl32$lnkBtnCustomerCode" string
[70] "grdCustomerSearch$ctl33$lnkBtnCustomerCode" string
[71] "grdCustomerSearch$ctl34$lnkBtnCustomerCode" string
[72] "grdCustomerSearch$ctl35$lnkBtnCustomerCode" string
[73] "grdCustomerSearch$ctl36$lnkBtnCustomerCode" string
[74] "grdCustomerSearch$ctl37$lnkBtnCustomerCode" string
[75] "grdCustomerSearch$ctl38$lnkBtnCustomerCode" string
[76] "grdCustomerSearch$ctl39$lnkBtnCustomerCode" string
[77] "grdCustomerSearch$ctl40$lnkBtnCustomerCode" string
[78] "grdCustomerSearch$ctl41$lnkBtnCustomerCode" string
[79] "grdCustomerSearch$ctl42$lnkBtnCustomerCode" string
[80] "grdCustomerSearch$ctl43$lnkBtnCustomerCode" string
[81] "grdCustomerSearch$ctl44$lnkBtnCustomerCode" string
[82] "grdCustomerSearch$ctl45$lnkBtnCustomerCode" string
[83] "grdCustomerSearch$ctl46$lnkBtnCustomerCode" string
[84] "grdCustomerSearch$ctl47$lnkBtnCustomerCode" string
[85] "grdCustomerSearch$ctl48$lnkBtnCustomerCode" string
[86] "grdCustomerSearch$ctl49$lnkBtnCustomerCode" string
[87] "grdCustomerSearch$ctl50$lnkBtnCustomerCode" string
[88] "grdCustomerSearch$ctl51$lnkBtnCustomerCode" string
[89] "grdCustomerSearch$ctl52$lnkBtnCustomerCode" string
[90] "grdCustomerSearch$ctl53$lnkBtnCustomerCode" string
[91] "grdCustomerSearch$ctl54$lnkBtnCustomerCode" string
[92] "grdCustomerSearch$ctl55$lnkBtnCustomerCode" string
[93] "grdCustomerSearch$ctl56$lnkBtnCustomerCode" string
[94] "grdCustomerSearch$ctl57$lnkBtnCustomerCode" string
[95] "grdCustomerSearch$ctl58$lnkBtnCustomerCode" string
[96] "grdCustomerSearch$ctl59$lnkBtnCustomerCode" string
[97] "grdCustomerSearch$ctl60$lnkBtnCustomerCode" string
[98] "grdCustomerSearch$ctl61$lnkBtnCustomerCode" string
[99] "grdCustomerSearch$ctl62$lnkBtnCustomerCode" string
[100] "grdCustomerSearch$ctl63$lnkBtnCustomerCode" string
[101] "grdCustomerSearch$ctl64$lnkBtnCustomerCode" string
[102] "grdCustomerSearch$ctl65$lnkBtnCustomerCode" string
[103] "grdCustomerSearch$ctl66$lnkBtnCustomerCode" string
[104] "grdCustomerSearch$ctl67$lnkBtnCustomerCode" string
[105] "grdCustomerSearch$ctl68$lnkBtnCustomerCode" string
[106] "grdCustomerSearch$ctl69$lnkBtnCustomerCode" string
[107] "grdCustomerSearch$ctl70$lnkBtnCustomerCode" string
[108] "grdCustomerSearch$ctl71$lnkBtnCustomerCode" string
[109] "grdCustomerSearch$ctl72$lnkBtnCustomerCode" string
[110] "grdCustomerSearch$ctl73$lnkBtnCustomerCode" string
[111] "grdCustomerSearch$ctl74$lnkBtnCustomerCode" string
[112] "grdCustomerSearch$ctl75$lnkBtnCustomerCode" string
[113] "grdCustomerSearch$ctl76$lnkBtnCustomerCode" string
[114] "grdCustomerSearch$ctl77$lnkBtnCustomerCode" string
[115] "grdCustomerSearch$ctl78$lnkBtnCustomerCode" string
[116] "grdCustomerSearch$ctl79$lnkBtnCustomerCode" string
[117] "grdCustomerSearch$ctl80$lnkBtnCustomerCode" string
[118] "grdCustomerSearch$ctl81$lnkBtnCustomerCode" string
[119] "grdCustomerSearch$ctl82$lnkBtnCustomerCode" string
[120] "grdCustomerSearch$ctl83$lnkBtnCustomerCode" string
[121] "grdCustomerSearch$ctl84$lnkBtnCustomerCode" string
[122] "grdCustomerSearch$ctl85$lnkBtnCustomerCode" string
[123] "grdCustomerSearch$ctl86$lnkBtnCustomerCode" string
[124] "grdCustomerSearch$ctl87$lnkBtnCustomerCode" string
[125] "grdCustomerSearch$ctl88$lnkBtnCustomerCode" string
[126] "grdCustomerSearch$ctl89$lnkBtnCustomerCode" string
[127] "grdCustomerSearch$ctl90$lnkBtnCustomerCode" string
[128] "grdCustomerSearch$ctl91$lnkBtnCustomerCode" string
[129] "txtExtraProcess1" string
[130] "txtExtraRate1" string
[131] "txtExtraProcess2" string
[132] "txtExtraRate2" string
[133] "txtWholeRemark" string
[134] "drpTitle" string
[135] "txtCName" string
[136] "txtCAddress" string
[137] "txtMobile" string
[138] "drpPriority" string
[139] "txtNewPriority" string
[140] "txtAreaLocaton" string
[141] "txtRemarks1" string
[142] "txtBDate" string
[143] "txtADate" string
[144] "hdnMAC" string
[145] "hdnEditItemId" string
[146] "hdnOption" string
[147] "hdnCustId" string
[148] "hdnUpdate" string
[149] "BranchId" string
[150] "hdnItems" string
[151] "hdnDataValues" string
[152] "hdnFirstAdd" string
[153] "hdnCustomerNameFocusOut" string
[154] "hdnCurrentValue" string
[155] "hdnCurrentGrossAmt" string
[156] "isInEditMode" string
[157] "hdnDefaultItem" string
[158] "hdnDefaultProcess" string
[159] "hdnDefaultItemProcessRate" string
[160] "hdnTaxBefore" string
[161] "hdnAllDiscount" string
[162] "hdnAllTax" string
[163] "hdnUrgentRateApplied" string
[164] "hdnAllDiscountFocusOut" string
[165] "isNetAmountInDecimal" string
[166] "hdnRecompTax" string
[167] "hdnRecompDiscount" string
[168] "hdnCustCode" string
[169] "hdnTaxAmtRecomp" string
[170] "hdnDisAmtRecomp" string
[171] "hdnBalance" string
[172] "hdnTotal" string
[173] "hdnDiscountValue" string
[174] "hdnGrdRowCount" string
[175] "hdnAllGridData" string
[176] "hiddenInputToUpdateATBuffer_CommonToolkitScripts" string
It doesn't contains anything but data of the header of the grid (those values with grdEntry$ctl01$txtQty
, not the data of the row(s). But nonetheless, I found my way around, stored all variable in a temporary array and passed that to server, job done!
Thanks for the effort though.
它只包含网格头部的数据(这些值带有grdEntry$ctl01$txtQty,而不是行数据)。尽管如此,我还是找到了方法,将所有变量存储在一个临时数组中,并将其传递给服务器,任务完成!谢谢你的努力。
1 个解决方案
#1
1
First off, the "id" attribute doesn't get sent back to the server on a postback, that's what the "name" attribute is for. Second, you would want to look in the Request.Form (for post) or Request.QueryString (for get) collections for your data since they would not be bound to controls. ASP .net has to be involved in instanciating the controls, they don't magically exist on the postback when you create them in javascript.
首先,“id”属性不会在回发时被发送回服务器,这就是“name”属性的作用。其次,您需要查看请求。表格(邮寄)或要求。查询字符串(用于获取)数据集合,因为它们不会绑定到控件。net必须参与实例化控件,当您在javascript中创建控件时,它们不会神奇地出现在回发中。
#1
1
First off, the "id" attribute doesn't get sent back to the server on a postback, that's what the "name" attribute is for. Second, you would want to look in the Request.Form (for post) or Request.QueryString (for get) collections for your data since they would not be bound to controls. ASP .net has to be involved in instanciating the controls, they don't magically exist on the postback when you create them in javascript.
首先,“id”属性不会在回发时被发送回服务器,这就是“name”属性的作用。其次,您需要查看请求。表格(邮寄)或要求。查询字符串(用于获取)数据集合,因为它们不会绑定到控件。net必须参与实例化控件,当您在javascript中创建控件时,它们不会神奇地出现在回发中。