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:
Thanks,
Joshua
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