Solved

click on "Save" button not picking up changes on form

Posted on 2013-01-14
2
400 Views
Last Modified: 2013-01-14
I am guessing this is something simple.  I've not done any ASP.NET programming in about 9 months, so I am a little rusty.

Basically, I have a bunch of fields and drop down lists on a form that I am filling.  Then I can make changes to some of the values.  Then I want to save those changes.

The problem is when I go to save the changes, the changes are not getting picked-up.  According to the values of each control, they are the same as they were when the form first loaded the values.  It's as if I have made no changes, but I know I have.

Here is my code and markup:

code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.IO;
using System.Data.Linq;
using System.Data;

using Models;
using Framework.Business;
using Framework.Utilities;
using System.Xml.Linq;
using Framework.UIControls.Base;
using System.Configuration;
using System.Text;
using System.Data.OleDb;
using System.Data.Common;
using System.Threading;

namespace Reo.ContentControls
{
    //page created by Tom Knowlton - cr 1123

    public partial class AgentFormEdit : Reo.Base.BaseControl
    {
        private List<Models.AgentFormEdit_AgentForm_GetResult> getOneAgentForm;

        protected List<Models.AgentFormAdd_AgentFormTypes_SelectResult> showamfclientagentforms;

        protected void Page_Load(object sender, EventArgs e)
        {
            FillProductTypeDDL();
            FillAgentFormFields();
        }

//        private void FillTaskCodeDropDown()
//        {
////            SELECT t.code      
////from Task t
////where t.CategoryID in (935,930)
//        }

        
        private void FillAgentFormFields()
        {
            string[] aflidsid = Session["afa_agentformlistidsid"].ToString().Split('-');
            
            using (AgentFormsDataContext dc = new AgentFormsDataContext())
            {
                getOneAgentForm = dc.AgentFormEdit_AgentForm_Get(Convert.ToInt32(aflidsid[0]), Convert.ToInt32(aflidsid[1])).ToList<Models.AgentFormEdit_AgentForm_GetResult>();                
            }     

            foreach (Models.AgentFormEdit_AgentForm_GetResult agentfield in getOneAgentForm)
            {
                ddlLookupFormType.LookupID = agentfield.FormTypeID;
                TextBoxSequence.Text = agentfield.Sequence.ToString();
                TextBoxFormName.Text = agentfield.FormName;
                TextBoxColist.Text = agentfield.ColistFlag.ToString();
                RadioButtonAcceptanceRequiredFalse.Checked = agentfield.AcceptanceReqd == true ?  false : true;
                RadioButtonAcceptanceRequiredTrue.Checked = !RadioButtonAcceptanceRequiredFalse.Checked;
                RadioButtonDuplicatesAllowedFalse.Checked = agentfield.DuplicatesAllowed == true ? false : true;
                RadioButtonDuplicatesAllowedTrue.Checked = !RadioButtonDuplicatesAllowedFalse.Checked;                
                TextBoxExternalLink.Text = agentfield.ExternalLink;
                TextBoxTaskCode.Text = agentfield.TaskCode;
             //   TextBoxAMFirm.Text = agentfield.AMFID.ToString();
             //   TextBoxClient.Text = agentfield.ClientID.ToString();
                ddlProducts.SelectedValue = agentfield.ProductID.ToString();
                RadioButtonActiveFalse.Checked = agentfield.Active == true ? false : true;
                RadioButtonActiveTrue.Checked = !RadioButtonActiveFalse.Checked;

                //ternary operator syntax example
                //int ystep = y0 < y1 ? 1 : -1;
            }         
        }

        private void FillProductTypeDDL()
        {
            ProductTypeDataContext pdc = new ProductTypeDataContext();
            var result = pdc.ProductType_DropDown_Get(null, null, CurrentUser.UserID, CurrentUser.UserSID).ToList();
            this.ddlProducts.DataSource = result;
            ddlProducts.DataTextField = "Name";
            ddlProducts.DataValueField = "ProductTypeID";
            ddlProducts.DataBind();
        }

        protected void ButtonSave_Click(object sender, EventArgs e)
        {
            SaveChanges();
            Session["afa_returnfromchild"] = true;
            string prevPage = Session["afa_parent"].ToString();
            Response.Redirect(prevPage);
        }

        private void SaveChanges()
        {
            using (AgentFormsDataContext dc = new AgentFormsDataContext())
            {
                string[] aflidsid = Session["afa_agentformlistidsid"].ToString().Split('-');

                int agentformlistid = Convert.ToInt32(aflidsid[0]);
                int agentformlistsid = Convert.ToInt32(aflidsid[1]);
                int formtypeid = Convert.ToInt32(ddlLookupFormType.LookupID);
                int sequence = Convert.ToInt32(TextBoxSequence.Text);
                string formname = TextBoxFormName.Text;
                int colist = Convert.ToInt32(TextBoxColist.Text);
                bool rbAcceptReqd = RadioButtonAcceptanceRequiredFalse.Checked == true ? false : true;
                bool rbDupAllowed = RadioButtonDuplicatesAllowedFalse.Checked == true ? false : true;
                string extlink = TextBoxExternalLink.Text;
                string taskCode = TextBoxTaskCode.Text;
                int productid = Convert.ToInt32(ddlProducts.SelectedValue);
                bool rbActive = RadioButtonActiveFalse.Checked == true ? false : true;

                dc.AgentFormEdit_AgentForm_Update(agentformlistid, agentformlistsid, formtypeid, sequence, formname, colist, rbAcceptReqd, rbDupAllowed, extlink, taskCode, productid, rbActive);

                
                //dc.AgentFormEdit_AgentForm_Update(Convert.ToInt32(aflidsid[0]), Convert.ToInt32(aflidsid[1])).ToList<Models.AgentFormEdit_AgentForm_GetResult>();
                //dc.AgentFormEdit_AgentForm_Update(Convert.ToInt32(aflidsid[0]), Convert.ToInt32(aflidsid[1])).ToList<Models.AgentFormEdit_AgentForm_GetResult>();
            }  
        }

        protected void ButtonCancel_Click(object sender, EventArgs e)
        {
            Session["afa_returnfromchild"] = true;
            string prevPage = Session["afa_parent"].ToString();
            Response.Redirect(prevPage);
        }

    }
}

Open in new window







markup:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AgentFormEdit.ascx.cs" Inherits="Reo.ContentControls.AgentFormEdit" %>
<%@ Register Assembly="Framework" Namespace="Framework.UIControls" TagPrefix="cc1" %>

<%--page created by Tom Knowlton - cr 1123--%>


<script type="text/javascript" src="Scripts/jQueryDatePicker/jquery-ui-1.8.5.custom.min.js"></script>

<script type="text/javascript">

   
     $(document).ready(function () {
         $('div[id="agentformfields"]').css('position', 'relative');
         //$('div[id="agentformfields"]').css('background-color', 'red');
         $('div[id="agentformfields"]').css('height', '500px');
         $('div[id="agentformfields"]').css('width', '800px');

         $('div[class="afa_label"]').css('position', 'relative');
         $('div[class="afa_label"]').css('width', '120px');
      //   $('div[class="afa_label"]').css('background-color', 'red');
         $('div[class="afa_label"]').css('float', 'left');
         $('div[class="afa_label"]').css('clear', 'left');
         $('div[class="afa_label"]').css('text-align', 'right');
         $('div[class="afa_label"]').css('margin-right', '5px');
         $('div[class="afa_label"]').css('padding-top', '5px');


         $('div[class="afa_control"]').css('position', 'relative');
         $('div[class="afa_control"]').css('width', '280px');      
         $('div[class="afa_control"]').css('float', 'left'); 
         
         $('input').css('width', '30px');
         $('input[name*="TextBoxExternalLink"]').css('width', '200px');
         $('input[name*="TextBoxFormName"]').css('width', '200px');
         $('select[name*="TextBoxExternalLink"]').css('width', '200px');

         $('div[class="afa_controlrb"]').css('position', 'relative');
         $('div[class="afa_controlrb"]').css('width', '80px');
         $('div[class="afa_controlrb"]').css('float', 'left');

         $('div[class="afa_button"]').css('position', 'relative');
         $('div[class="afa_button"]').css('width', '150px');
         $('div[class="afa_button"]').css('float', 'left');


         $('input[type="submit"]').css('width', '80px');
         $('input[type="submit"]').css('position', 'relative');
         $('input[type="submit"]').css('float', 'left');       
     });

     

     		
    </script>


<div id="frame">
    <div id="frame_header">
        <div id="frame_title">
            <h1>
                Edit Agent Form</h1>
        </div>
    </div>

   <%-- <asp:UpdatePanel ID="UpdatePanelAgentFormAdd" runat="server" 
        ChildrenAsTriggers="False">
    <ContentTemplate>--%>
    <div id="corpus">
        <div id = "agentformfields">
            <div>
                <div id="formtype" class="afa_label">Form Type</div>
                <div id="formtypeddl" class="afa_control"><cc1:DdlLookup runat="server" HeaderCode="DocType" ID="ddlLookupFormType"></cc1:DdlLookup></div>
            </div>
            <div>
                <div id="sequence" class="afa_label">Sequence</div>
                <div id="tbsequence" class="afa_control"><asp:TextBox ID="TextBoxSequence" runat="server"></asp:TextBox></div>
            </div>
            <div>
                <div id="formname" class="afa_label">Form Name</div>
                <div class="afa_control"><asp:TextBox ID="TextBoxFormName" runat="server"></asp:TextBox></div>
            </div>
            <div>
                <div id="colist" class="afa_label">Colist</div>
                <div class="afa_control"><asp:TextBox ID="TextBoxColist" runat="server"></asp:TextBox></div>
            </div>
            <div>
                <div id="accptreqd" class="afa_label">Acceptance Reqd</div>
                <div class="afa_controlrb" id="radiobuttonaccptreqdtrue"><asp:RadioButton ID="RadioButtonAcceptanceRequiredTrue" GroupName="AccReqdGroup" runat="server" Text="True" /></div>
                <div id="radiobuttonaccptreqdfalse" class="afa_controlrb"><asp:RadioButton ID="RadioButtonAcceptanceRequiredFalse"  GroupName="AccReqdGroup" runat="server" Text="False"/></div>
            </div>
            <div>
                <div id="dupallow" class="afa_label">Duplicates Allowed</div>
                <div class="afa_controlrb" id="radiobuttondupallowedtrue"><asp:RadioButton ID="RadioButtonDuplicatesAllowedTrue" GroupName="DupAllowedGroup" runat="server" Text="True" /></div>
                <div id="radiobuttondupallowedfalse" class="afa_controlrb"><asp:RadioButton ID="RadioButtonDuplicatesAllowedFalse"  GroupName="DupAllowedGroup" runat="server" Text="False"/></div>
            </div>
            <div>
                <div id="extlink" class="afa_label">External Link</div>
                <div class="afa_control"><asp:TextBox ID="TextBoxExternalLink" runat="server"></asp:TextBox></div>
            </div>
            <div>
                <div id="taskcode" class="afa_label">Task Code</div>
                <div class="afa_control"><asp:TextBox ID="TextBoxTaskCode" runat="server"></asp:TextBox></div>
            </div>
            <%--<div>
                <div id="amfirm" class="afa_label">AM firm</div>
                <div class="afa_control"><asp:TextBox ID="TextBoxAMFirm" runat="server"></asp:TextBox></div>
            </div>
            <div>
                <div id="client" class="afa_label">Client</div>
                <div class="afa_control"><asp:TextBox ID="TextBoxClient" runat="server"></asp:TextBox></div>                
            </div>
            --%><div>
                <div id="product" class="afa_label">Product</div>
                <div class="afa_control"><asp:DropDownList ID="ddlProducts" runat="server"></asp:DropDownList></div>
            </div>
            <div>
                <div id="active" class="afa_label">Active</div>
                <div id="radiobuttonacttrue" class="afa_controlrb"><asp:RadioButton ID="RadioButtonActiveTrue" GroupName="ActiveGroup" runat="server" Text="True" /></div>
                <div id="radiobuttonactfalse" class="afa_controlrb"><asp:RadioButton ID="RadioButtonActiveFalse"  GroupName="ActiveGroup" runat="server" Text="False"/></div>
            </div>  
             <div>                
                <div id="Div2" class="afa_label"> </div>                
            </div>   
             <div>                
                <div id="Div3" class="afa_label"> </div>                
            </div>   
            <div>                
                <div id="Div1" class="afa_label"></div>
                <div id="divsave" ><asp:Button runat="server" ID="ButtonSave" Text="Save" 
                        Width="100px" onclick="ButtonSave_Click" /></div>
                <div id="divcancel"><asp:Button runat="server" ID="ButtonCancel" Text="Cancel" 
                        Width="100px" onclick="ButtonCancel_Click" /></div>
            </div>        
        </div>    
    </div>
 <%--   </ContentTemplate>
    </asp:UpdatePanel>--%>
    <div id="footer"></div>
<div id="end_cap"></div>
</div>

Open in new window

0
Comment
Question by:knowlton
2 Comments
 
LVL 8

Accepted Solution

by:
rpkhare earned 500 total points
ID: 38775204
I think you need to use:

       protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               FillProductTypeDDL();
               FillAgentFormFields();
             }
        }

Open in new window

0
 
LVL 5

Author Comment

by:knowlton
ID: 38775300
Concur!

Once I finally got a hold of my boss, he made the same suggestion.

Great minds think alike, right?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

759 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now