I have a working page that I transplanted into master/content page arrangement. When running the page now, things that used to work, like inserting a record using a SQLDataSource, no longer work. SQL Server returns an error saying I cannot insert a null in a column, but the Insert parameters and such all work great in the old page with no master.
What could I have done wrong? Thanks in advance...
Code for content page:
Sample of code-file that does not work now:
Code from master page:
Jason
What could I have done wrong? Thanks in advance...
Code for content page:
Code:
<%@ Page Language="C#" MasterPageFile="~/masters/GradeBook.master" AutoEventWireup="true" CodeFile="TestStudent.aspx.cs" Inherits="TestStudent" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="main" Runat="Server">
<asp:SqlDataSource ID="datasrcStudent" runat="server" ConnectionString="<%$ ConnectionStrings:CR_GradeBookConnectionString %>"
InsertCommand="AddStudent" InsertCommandType="StoredProcedure"
SelectCommand="SELECT STU_FName, STU_LName, GL_UID FROM dbo.Student WHERE STU_UID = @STU_UID"
DataSourceMode="DataReader"
UpdateCommand="UpdateStudent" UpdateCommandType="StoredProcedure" >
<InsertParameters>
<asp:ControlParameter ControlID="txtFName" Name="STU_FName" Type="String" PropertyName="text" />
<asp:ControlParameter ControlID="txtLName" Name="STU_LName" Type="String" PropertyName="text" />
<asp:ControlParameter ControlID="ddlGradeLevel" Name="GL_UID" Type="Int32" PropertyName="SelectedValue" />
</InsertParameters>
<SelectParameters>
<asp:FormParameter Name="STU_UID" Type="Int32" FormField="txtUID" />
</SelectParameters>
<UpdateParameters>
<asp:FormParameter Name="STU_UID" Type="String" FormField="txtUID" />
<asp:FormParameter Name="STU_FName" Type="String" FormField="txtFName" />
<asp:FormParameter Name="STU_LName" Type="String" FormField="txtLName" />
<asp:FormParameter Name="GL_UID" Type="Int32" FormField="ddlGradeLevel"/>
</UpdateParameters>
</asp:SqlDataSource>
<div id="content">
<h1>
Add Student/Edit Student Info</h1>
<table border="1" cellpadding="5" style="width: 500px">
<tr>
<td class="tblLeftCol">
<div class="divLabel">*First Name</div>
</td>
<td class="tblRightCol">
<asp:TextBox ID="txtFName" runat="server"></asp:TextBox>
<asp:TextBox ID="txtUID" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td class="tblLeftCol">
<div class="divLabel">*Last Name</div>
</td>
<td class="tblRightCol">
<asp:TextBox ID="txtLName" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td class="tblLeftCol">
<div class="divLabel">*Grade Level</div>
</td>
<td class="tblRightCol">
<asp:DropDownList ID="ddlGradeLevel" runat="server" DataSourceID="datasrcGradeLevel" DataTextField="Level"
DataValueField="GL_UID">
</asp:DropDownList><asp:SqlDataSource ID="datasrcGradeLevel" runat="server" ConnectionString="<%$ ConnectionStrings:CR_GradeBookConnectionString %>"
SelectCommand="GetGradeLevels" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
</td>
</tr>
</table>
<span class="spanButtonRow">
<asp:Button ID="btnAdd" runat="server" Text="Add" CssClass="btnButton" OnClick="btnAdd_Click" />
<asp:Button ID="btnUpdate" runat="server" Text="Update" CssClass="btnButton" OnClick="btnUpdate_Click" />
</span>
<div>
<div class="divLabel">
Status:</div>
<asp:Label ID="lblStatus" runat="server" Text="Enter a new student or edit an existing one" CssClass="lblStatus"></asp:Label>
</div>
</div>
</asp:Content>
Sample of code-file that does not work now:
Code:
protected void btnAdd_Click(object sender, EventArgs e)
{
this.datasrcStudent.Insert();
}
Code:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="GradeBook.master.cs" Inherits="GradeBook" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head runat="server">
<title>Untitled Page</title>
<link href="~/styles/Styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div id="header">
<img src="~/images/cedar_ridge_logo_small.jpg" alt="logo" id="imgHeader" />
<div id="txtHeader">
<h1>Grade Book</h1>
<span>
<a class="globallinks" href="~/Index.aspx">Home</a>
<a class="globallinks" href="~/Students.aspx">Students</a>
<a class="globallinks" href="~/Courses.aspx">Courses</a>
<a class="globallinks" href="~/Classes.aspx">Classes</a>
<a class="globallinks" href="~/Assignments.aspx">Assignments</a>
<a class="globallinks" href="~/ClassRoster.aspx">Class Roster</a>
<a class="globallinks" href="~/Scores.aspx">Assignment Scores</a>
</span>
</div><br /><hr />
</div>
<asp:contentplaceholder id="main" runat="server">
</asp:contentplaceholder>
<div id="footer">
<hr />
<span>Cedar Ridge Ministries, 2006</span>
</div>
</form>
</body>
</html>
Jason