Solved

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

Posted on 2013-01-14
2
410 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:Tom 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:Tom 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

680 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