c# - get value from dynamic Textbox -
i hava arrays save controls. when call function initialize arrays , save in arrays controls.
code:
private label[] lblname; private textbox[] txtname; private label[] lblsurname; private textbox[] txtsurname; private label[] lblinstitution; private textbox[] txtinstitution; private label[] lblcountry; private textbox[] txtcountry; private label[] lblemail; private textbox[] txtemail; private placeholder placeholder1; public int numberofotherauthors() { int32 index = convert.toint32(numberlist.selectedvalue); return index; } public void guiofotherauthor() { int authors; int = 0; int j = 1; authors = numberofotherauthors(); lblname = new label[authors]; txtname = new textbox[authors]; lblsurname = new label[authors]; txtsurname = new textbox[authors]; lblinstitution = new label[authors]; txtinstitution = new textbox[authors]; lblcountry = new label[authors]; txtcountry = new textbox[authors]; lblemail = new label[authors]; txtemail = new textbox[authors]; placeholder1 = new placeholder(); (i = 0; < authors; i++) { label authorinformation = new label(); authorinformation.text = "information author " + j.tostring() + " :"; lblname[i] = new label(); lblname[i].text = "name:"; txtname[i] = new textbox(); lblsurname[i] = new label(); lblsurname[i].text = "surname:"; txtsurname[i] = new textbox(); lblinstitution[i] = new label(); lblinstitution[i].text = "institution:"; txtinstitution[i] = new textbox(); lblcountry[i] = new label(); lblcountry[i].text = "country:"; txtcountry[i] = new textbox(); lblemail[i] = new label(); lblemail[i].text = "email:"; txtemail[i] = new textbox(); placeholder1.controls.add(new literalcontrol("<table>")); placeholder1.controls.add(new literalcontrol("<span style=\"font-weight:bold;\" ")); placeholder1.controls.add(authorinformation); placeholder1.controls.add(new literalcontrol("</span>")); placeholder1.controls.add(new literalcontrol("<tr><td>")); placeholder1.controls.add(lblname[i]); placeholder1.controls.add(new literalcontrol("</td><td>")); placeholder1.controls.add(txtname[i]); placeholder1.controls.add(new literalcontrol("</td></tr>")); placeholder1.controls.add(new literalcontrol("<tr><td>")); placeholder1.controls.add(lblsurname[i]); placeholder1.controls.add(new literalcontrol("</td><td>")); placeholder1.controls.add(txtsurname[i]); placeholder1.controls.add(new literalcontrol("</td></tr>")); placeholder1.controls.add(new literalcontrol("<tr><td>")); placeholder1.controls.add(lblinstitution[i]); placeholder1.controls.add(new literalcontrol("</td><td>")); placeholder1.controls.add(txtinstitution[i]); placeholder1.controls.add(new literalcontrol("</td></tr>")); placeholder1.controls.add(new literalcontrol("<tr><td>")); placeholder1.controls.add(lblcountry[i]); placeholder1.controls.add(new literalcontrol("</td><td>")); placeholder1.controls.add(txtcountry[i]); placeholder1.controls.add(new literalcontrol("</td></tr>")); placeholder1.controls.add(new literalcontrol("<tr><td>")); placeholder1.controls.add(lblemail[i]); placeholder1.controls.add(new literalcontrol("</td><td>")); placeholder1.controls.add(txtemail[i]); placeholder1.controls.add(new literalcontrol("</td></tr>")); placeholder1.controls.add(new literalcontrol("</table><br /> ")); panel1.controls.add(placeholder1); j++; } } now want take value of textboxes in function public void uploadform(){...}. try it
int i; int numberofotherauthors = numberofotherauthors(); for(i=0; i<numberofotherauthors; i++) { string = txtname[i].text } the textboxes values want upload database, let's save them string. when this, have nullreferenceexception. how value of textboxes??? thanks
i noticed uploadform() function referencing txtname, while actual textbox declared txtname. since field names case-sensitive, field "txtname" (lower-case 'n') not defined, cause of nullreferenceexception in dynamic page.
Comments
Post a Comment