This is a migrated thread and some comments may be shown as answers.

Inherited Page Classes Problem

3 Answers 28 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Joshua
Top achievements
Rank 1
Joshua asked on 08 Dec 2008, 11:21 PM
I have two different connection strings that are loaded into SessionState upon successful login. One connection string has the connection from a general database while the other connection string stores the string for the specific, logged-in user.

My inherited class simply returns the Session Data to all of my pages.  I did it this way so that I wouldn't have to copy/paste code into all of my application's pages and if the Session Data does not exist, my user would be forced to log back in.

The problem is, some of the Grids are really screwed up.

Here are some of the cases:
   1) A grid on one page, shows 21 rows of blank lines, but there's NO data in that particular database table. (Screenshot)
   2) Grids on a few other pages, when I click on the InsertCommand button (Inline Edit Mode), I get the textboxes, but blank data is inserted into the database and I get an exception stating that object not set to a reference.  THEN, the Grid doesn't show ANY rows - including the row that says "No records could be found." (Screenshot)

Please note, that everything worked when I was assigning the ConnectionStrings on every single page in the Page_Load event.

It seems that I'm only having a problem when I'm using an edit mode.  On a few of my pages in which I just have a grid that's binding and listing data (no edits), there doesn't seem to be a problem.

Am I missing something in the page cycle or what? I've tried putting the inherited code in the OnLoad, OnPreLoad, OnInit, and OnPreInit events, but all renders the same results.  What's going on?

Here's my code samples:

 
namespace Elevate.DBSchema   
{  
    public class DBStore : System.Web.UI.Page   
    {   
        private string _localConn;   
        private string _userConn;   
 
        public string userConn   
        {  
            get { return _userConn; }   
        }  
 
        public string localConn   
        {  
            get { return _localConn; }   
        }  
   
        protected override void OnLoad(EventArgs e)    
        {  
            if ((Session["userConn"] == null) || (Session["localConn"] == null))   
            {  
                FormsAuthentication.SignOut();   
                Response.Redirect("/login.aspx");   
            }  
            else   
            {   
                _localConn = Session["localConn"].ToString();   
                _userConn = Session["userConn"].ToString();   
            }  
 
            base.OnLoad(e);    
        }  
    }  
}  
 
   
namespace Elevate   
{  
    public partial class WebForm10 : DBSchema.DBStore   
    {  
        protected void loadGroups(object sender, GridNeedDataSourceEventArgs e)   
        {  
            SqlConnection conn = new SqlConnection(userConn);   
            SqlCommand comm = new SqlCommand("SELECT * FROM [elevate_marketing_Groups]", conn);   
            SqlDataReader reader;   
            DataTable dt = new DataTable();   
 
            try   
            {   
                conn.Open();  
                reader = comm.ExecuteReader();  
                dt.Load(reader);  
                reader.Close();  
                RadGrid1.DataSource = dt;  
            }  
            catch (Exception exc)   
            { }  
            finally   
            {   
                conn.Close();  
            }  
        }  
    }  



Thanks,
Joshua

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Joshua
Top achievements
Rank 1
answered on 09 Dec 2008, 01:20 AM
I temporarily disabled AJAX and on the InsertCommand event I programmed an exception to report what the contents of the edit form textboxes are upon PostBack.  It seems they're empty (which would explain why empty data is being inserted into the database).

I'm sure I'm doing something wrong, but I don't know what it is.

Why, when I inherit another class that inherits System.Web.UI.Page do my webforms not retain their values?

I would be grateful for any help.
Joshua
0
Joshua
Top achievements
Rank 1
answered on 09 Dec 2008, 05:24 AM
Actually, upon further exploration and stripping my app down, I realized that hardcoding the connectionstrings no longer worked either.  Therefore, I back-tracked and restored my code to last working model and guess what!?! That no longer worked. 

Why? Hmmm.  Then I realized the ONLY thing I didn't restore to last working and that was the Telerik.dll.

So then I tried the previous version of the DLL (v 2008.2.826.35) and then you know what happened!?!?  IT WORKED PERFECTLY!!!

Guys, I think there is a bug in your latest RadGrid (v. 2008.3.1125.35) - its not retaining the textbox values from the bound data field.  At least it wasn't for me. I'm not doing anything special with it, just look at the code above.

And here's the insert code:

        protected void insertTypes(object sender, GridCommandEventArgs e)  
        {  
            GridEditableItem item = (GridEditableItem)e.Item.OwnerTableView.GetInsertItem();  
 
            SqlConnection conn = new SqlConnection(userConn);  
            SqlCommand comm = new SqlCommand("INSERT [elevate_contacts_ContactTypes] " +  
                                             "(contactType, contactTypeDesc) " +  
                                             "VALUES " +  
                                             "(@contactType, @contactTypeDesc)", conn);  
              
            try 
            {  
                comm.Parameters.Add("contactType", SqlDbType.NVarChar, 50).Value = (item["contactType"].Controls[0] as TextBox).Text;  
                comm.Parameters.Add("contactTypeDesc", SqlDbType.NVarChar, 255).Value = (item["contactTypeDesc"].Controls[0] as TextBox).Text;  
                conn.Open();  
                comm.ExecuteNonQuery();  
            }  
            catch (Exception exc)  
            { }  
            finally 
            {  
                conn.Close();  
                RadGrid1.MasterTableView.IsItemInserted = false;  
            }  
        }  
 


And I just spent the last 6 hours trying to figure out why my app wasn't working.

You know, you guys ought to consider a team of software testers who are actually using your controls in the market.  You guys know every little detail of your controls and how they're suppose to work.  As a developer, myself, I know that this OFTEN creates a "blind spot" for bugs.  Then, your controls would be tested by users prior to you releasing them to the general public.  FYI, I would be glad to volunteer.
0
Pavel
Telerik team
answered on 11 Dec 2008, 12:01 PM
Hi Joshua,

Can you reproduce the problem on any of our online examples? Unfortunately the provided information is not sufficient for us to replicate the behavior. That is why I think it will be best if you open a support ticket and attach to it a small runnable sample which illustrates the issue. Thus we will get back to you right after we examine it.

Sincerely yours,
Pavel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Joshua
Top achievements
Rank 1
Answers by
Joshua
Top achievements
Rank 1
Pavel
Telerik team
Share this question
or