Unable to read user input from text control box .text

I have a web page that reads data from an SQL table and then displays the data on the web page.  After the web page is displayed, I allow the user to make changes to some of the fields on the screen.  If a user makes a change to a field the data that they key in is not being read when I attempt to save the changed data back to the SQL table.  Can someone show me where I am going wrong.  The field I am having a problem with is tbiStatData.text.
protected void btnSaveIstatLoc_Click(object sender, Infragistics.WebUI.WebDataInput.ButtonEventArgs e)
        {
            RadRelayDataClassDataContext dcRadRelay = new RadRelayDataClassDataContext();
            string test;
            test = tbiStatData.Text;
            string MPI;
            MPI = Session.Contents["MPI"].ToString();
            Guid ConvertedMPI = new Guid(MPI);
 
            var ReferralsResult = from referralsdata in dcRadRelay.PROVIDER_REFERRAL_QUEUEs
                                  where referralsdata.MPI == ConvertedMPI
                                  select new { referralsdata };
 
            int ReferralRecCount = Convert.ToInt32(ReferralsResult.Count());    // <===== Added this line to get total count here
 
            if (ReferralRecCount == 0)                    // <===== Changed this line so that the query does not get executed again
            {
                // No Referral record found
            }
            else
            {
                foreach (var ReferralsResultRecord in ReferralsResult)
                {
 
                    ReferralsResultRecord.referralsdata.iStat = tbiStatData.Text;
                    ReferralsResultRecord.referralsdata.LocationtForReferral = tbLocationData.Text;
                    
 
                    dcRadRelay.SubmitChanges();
                }
            }
        }

Open in new window

kwh3856Asked:
Who is Participating?
 
Ammar GaffarConnect With a Mentor Software EngineerCommented:
Dear kwh3856,
The Post Back code is to be added to the Page_Load event not in a button_click event!
What I guess, you bind the existing record when page is loaded, so you have a code in your page_load event and you didn't use Post back check. This scenario is happened to me and I lost a lot of time to figure out!

Good Luck
0
 
Ammar GaffarSoftware EngineerCommented:
Hi,
If you don't use If Not IsPostBack() in the Page_Load Event when you are binding the exsisting record from database then you will encounter this issue.

Add this condition in the Page_Load Event

If Not IsPostBack()
{
//write your code here
}

Open in new window

0
 
Richard LeeSoftware EnthusiastCommented:
This TextBox should have its value during page Initialisation and Load however it would be useful to run the application in debug mode Watch the and ensure that tbiStatData.Text property to ensure the value is there and at what point it gets lost. Place a break point also in your event handler.

I have improved your code which may help to resolve the problem
// Ensure the DataContext is destroyed
// after its no longer required
using (RadRelayDataClassDataContext dcRadRelay = new RadRelayDataClassDataContext())
{
	string MPI = Session.Contents["MPI"].ToString();
	Guid ConvertedMPI = new Guid(MPI);
 
	// Since ConvertedMPI is a GUID then 
	// most likely you will only get one or no
	// items back from the LINQ query
	var ReferralsResult = (from referralsdata in dcRadRelay.PROVIDER_REFERRAL_QUEUEs
	                       where referralsdata.MPI == ConvertedMPI
	                       select new {referralsdata}).FirstOrDefault();
 
	if (ReferralsResult != null)
	{
		ReferralsResultRecord.referralsdata.iStat = tbiStatData.Text;
		ReferralsResultRecord.referralsdata.LocationtForReferral = tbLocationData.Text;
		dcRadRelay.SubmitChanges();
	}
}

Open in new window

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
kwh3856Author Commented:
I tried using the post back but stil no luck.  Any other ideas? Here is the changed code.  Did I do it correctly?
protected void btnSaveIstatLoc_Click(object sender, Infragistics.WebUI.WebDataInput.ButtonEventArgs e)
        {
            if (!this.IsPostBack)
            {
                // done only during initializtion
            }
            else
            {
 
                // done only during postback
 
                RadRelayDataClassDataContext dcRadRelay = new RadRelayDataClassDataContext();
                string test;
                test = tbiStatData.Text;
                string MPI;
                MPI = Session.Contents["MPI"].ToString();
                Guid ConvertedMPI = new Guid(MPI);
 
                var ReferralsResult = from referralsdata in dcRadRelay.PROVIDER_REFERRAL_QUEUEs
                                      where referralsdata.MPI == ConvertedMPI
                                      select new { referralsdata };
 
                int ReferralRecCount = Convert.ToInt32(ReferralsResult.Count());    // <===== Added this line to get total count here
 
                if (ReferralRecCount == 0)                    // <===== Changed this line so that the query does not get executed again
                {
                    // No Referral record found
                }
                else
                {
                    foreach (var ReferralsResultRecord in ReferralsResult)
                    {
 
                        ReferralsResultRecord.referralsdata.iStat = tbiStatData.Text;
                        ReferralsResultRecord.referralsdata.LocationtForReferral = tbLocationData.Text;
 
 
                        dcRadRelay.SubmitChanges();
                    }
                }
            }
        }

Open in new window

0
 
kwh3856Author Commented:
Ok...I did not catch that part in the first post.  Let me give it a try.
Thanks
Kenny
 
0
 
kwh3856Author Commented:
Africans,
You were right on.  I did not catch that part in the beginning and that was exactly the problem.
Thanks
Kenny
0
All Courses

From novice to tech pro — start learning today.