Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 688575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:14:38+00:00 2026-05-14T02:14:38+00:00

I have – for instance – an asp:FormView which supports Read, Insert, Update, Delete

  • 0

I have – for instance – an asp:FormView which supports Read, Insert, Update, Delete and is bound to a DataSource:

<asp:FormView ID="FormView1" runat="server" 
    DataSourceID="ObjectDataSource1" >
    <ItemTemplate>
        <asp:Label ID="Label1" runat="server" Text='<%# Bind("MyText") %>' />
    </ItemTemplate>
    <EditItemTemplate>
        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("MyText") %>' />
    </EditItemTemplate>
    <InsertItemTemplate>
        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("MyText") %>' />
    </InsertItemTemplate>
</asp:FormView>

If I am in Read-Mode or Edit-Mode the control is initialized with the property MyText of the current object which is bound to the FormView.

But when I go to Insert-Mode I do not have a “current object” (FormView1.DataItem is indeed null) and the controls are empty.

If I want to have my TextBox control initialized with a specific value how can I do that? In which event can I hook in to set default values to the controls in the InsertItemTemplate?

Especially I have in mind using an ObjectDataSource. I was expecting that the InsertItemTemplate is initialized with a business object which underlies my ObjectDataSource and which is created by the ASP.NET framework simply by using its default constructor when the InsertItemTemplate gets activated. In the default constructor I would init the class members to the default values I’d like to have in my controls of the InsertItemTemplate. But unfortunately that’s not the case: No “default” object is created and bound to the FormView. So it seems I have to initialize all controls separately or to create the default object manually and bind it to the InsertItemTemplate of the FormView. But how and where can I do that?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:14:38+00:00Added an answer on May 14, 2026 at 2:14 am

    Try the ModeChanged event.

    Therein you can use

    TextBox _tb = this.FormView1.FindControl("TextBox1") as TextBox
    if(_tb != null)
    {
      _tb.Text = Mybusinessobject.property;
    }
    

    If .FindControl does return null, try to this:

    this.FormView1.DataBind();
    TextBox _tb = this.FormView1.FindControl("TextBox1") as TextBox
    if(_tb != null)
    {
      _tb.Text = Mybusinessobject.property;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have deployed numerous report parts which reference the same view however one of them
Have anyone used Redmine Documentor which lets you convert PHP to HTML to Redmine
have the following text file: <div> <asp:HyperLinkField HeaderText=Hello World of Regular Expression /> </div>
Have the following scenario. I have a few form, which essentially have a few
Have a WCF service in a Services directory in my asp.net web app. In
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have a question about calling one prototype function in another prototype function. for instance
Have a text box which get data for price. If someone enter something like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.