c# - The name 'txtStudentDOB' does not exist in the current context -


i have web form user control , want add calender textbox in edit form, error txtstudentdob in void calendar1_selectionchanged1(object sender, eventargs e) . problem cannot access calender edit form context.

using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; using system.globalization;  namespace learningsystem.controls {  public partial class usrstudent : system.web.ui.usercontrol {     protected void page_load(object sender, eventargs e)      {         if (!ispostback)         {             calendar1.visible = false;         }      }     protected void imagebutton1_click(object sender, imageclickeventargs e)     {         if (calendar1.visible == false)         {             calendar1.visible = true;         }         else         {             calendar1.visible = true;         }     }       void calendar1_selectionchanged1(object sender, eventargs e)     {         txtstudentdob.text = calendar1.selecteddate.toshortdatestring();         calendar1.visible = false;     }  } 

here html codes

 <asp:formview id="frmstudent" runat="server" datasourceid="odsstudent" width="100%" onitemdeleted="frmstudent_itemdeleted" datakeynames="studentid" oniteminserted="frmstudent_iteminserted" onitemupdated="frmstudent_itemupdated" > <edititemtemplate>                  <asp:textbox id="txtstudentdob" runat="server" cssclass="form-control" text='<%# bind("studentdob" , "{0:d}") %>'  />                 <asp:imagebutton id="imagebutton1" runat="server" onclick="imagebutton1_click" />                 <asp:requiredfieldvalidator id="requiredfieldvalidator12" runat="server" display="dynamic" controltovalidate="txtstudentdob" errormessage="please enter date of birth" forecolor="red">*</asp:requiredfieldvalidator>                 <asp:rangevalidator id ="rvdate" runat ="server" c                 &nbsp;</div>         </div>          <div class="col-md-offset-2 col-md-10"">         <asp:linkbutton id="btnupdate" runat="server" cssclass="btn btn-success" causesvalidation="true" commandname="update" text="update" onclick="btnupdate_click" />         &nbsp;<asp:linkbutton id="btncancel" runat="server" causesvalidation="false" commandname="cancel" text="cancel" font-bold="false" />     </div>     </div> </edititemtemplate>  <asp:calendar id="calendar1" runat="server" onselectionchanged="calendar1_selectionchanged1" >          </asp:calendar> 

you cannot access control within formview directly. need find in form view. try following code

void calendar1_selectionchanged1(object sender, eventargs e) {    textbox txtstudentdob = frmstudent.findcontrol("txtstudentdob") textbox;    if(txtstudentdob != null)    {       txtstudentdob.text = calendar1.selecteddate.toshortdatestring();       calendar1.visible = false;    } } 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -