Access to the control in FormView

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • max ternoff
    New Member
    • Apr 2012
    • 4

    Access to the control in FormView

    Hi! Can I get access to the TextBox control (that is included in FormView) from code behind?

    Code:
     <asp:FormView ID="formview_NewsFull" runat="server" DataSourceID="ds_NewsFull">
    ...
        <EditItemTemplate>
          <asp:TextBox ID="newstitle"  ClientID="blahblahblah" runat="server" Text=<%#Bind("newstitle_ua")%>></asp:TextBox>
        </EditItemTemplate>
    
    
        </asp:FormView>
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    This is unrelated, but you shouldn't set the ClientID of an ASP.NET object. A ClientID is automatically generated for ASP.NET controls when they are rendered as HTML. This is done based on the ID given to the asp.net control and some other things...it ensures that every HTML element that was generated by an ASP.NET control has a unique ID so that the HTML is valid.

    Anyways, to access the TextBox in your server side code, use the FormView.FindCo ntrol method and provide this method with the ID of your TextBox (not the ClientID since you want to retrieve the server object based on the server-side id).

    -Frinny
    Last edited by Frinavale; Apr 2 '12, 07:57 PM.

    Comment

    • max ternoff
      New Member
      • Apr 2012
      • 4

      #3
      Frinavale, thank you!

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        No problem!
        You actually gave me an idea for my own project inadvertently :)

        Comment

        Working...