Solved

Unable to read user input from text control box .text

Posted on 2009-07-03
6
405 Views
Last Modified: 2013-12-17
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

0
Comment
Question by:kwh3856
[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
  • 3
  • 2
6 Comments
 
LVL 12

Expert Comment

by:Ammar Gaffar
ID: 24776787
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
 
LVL 18

Expert Comment

by:Richard Lee
ID: 24777666
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
 

Author Comment

by:kwh3856
ID: 24782265
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
Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

 
LVL 12

Accepted Solution

by:
Ammar Gaffar earned 500 total points
ID: 24782323
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
 

Author Comment

by:kwh3856
ID: 24782328
Ok...I did not catch that part in the first post.  Let me give it a try.
Thanks
Kenny
 
0
 

Author Closing Comment

by:kwh3856
ID: 31599558
Africans,
You were right on.  I did not catch that part in the beginning and that was exactly the problem.
Thanks
Kenny
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

626 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