Solved

FormView: Insert Record Issues

Posted on 2010-09-14
2
880 Views
Last Modified: 2012-05-10
Hi,

I have a formview for insert and updates. I was trying to call a procedure in formview_itemcommand event without setting InsertMethod for the ObjectDataSource. I got an
error and so I gave the exact procedure name for insert method to get rid of the error.

Since the formview objectdatasource method does not exactly match (the no of argument and name) with FormView Datasource(in insertiemtemplate), I was trying to avoid calling the selectmethod defined.

I was able to insert the record in itemcommand event.  

The problem is

1. While exiting out the Item_command event it gives the following error
      Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: FormView 'FormViewInsertApplication'
                must be in insert mode to insert a new record.
2. After insert, I tried setting the default mode readonly. It does not work

How do I by pass the above problems or is there other better way of accomplishing the same.

Thanks
Suresh

Sections of Code
----------------------
  protected void FormViewInsertApplication_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        FormView fvApp = (FormView)FindControl("FormViewInsertApplication");
        if (e.CommandName == "Insert")
        {
            if (!doValidate()) { return; }
            // Call Insert Procedure
            //Check return status . If return > 0 set the formview to readonly
 
            dataMaint psMaint = new  dataMaint();

            newID  = psMaint.InsertApp(parameter list)  // This works
 
            if (Convert.ToInt32(newID) > 0)
            {
                fvApp.ChangeMode(FormViewMode.ReadOnly);
               return;  // error after this
            }          
        }


  <asp:FormView ID="FormViewInsertApplication" runat="server"  
            DefaultMode="Insert" DataKeyName="id"
            DataSourceID="ObjectDataSource1"
            OnItemCommand="FormViewInsertApplication_ItemCommand"
            OnItemCreated="FormViewInsertApplication_ItemCreated">
</asp:FormView>

 <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
        SelectMethod="GetApplicationListByID"
        InsertMethod="InsertApp"
        TypeName="dataMaint">
        <SelectParameters>
            <asp:SessionParameter Name="id" SessionField="sid"
                Type="String" />
        </SelectParameters>
  </asp:ObjectDataSource>

0
Comment
Question by:arvee2003
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
existenz2 earned 500 total points
ID: 33689230
You should use  the InsertItemTemplate from the FormView when doing inserts, else that error will be thrown.
0
 

Author Closing Comment

by:arvee2003
ID: 33698312
None. Not Useful
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question