asp.net how can ObjectDataSource access System.Web.UI.Page objects - c#

I use ObjectDataSource as below.
<asp:ObjectDataSource ID="Item" runat="server"
SelectMethod="Grid_DataBind" TypeName="XXX.XXX.XXX"
DataObjectTypeName="Controller.Items" UpdateMethod="UpdateRow_Grid"
InsertMethod="InsertRow_Grid">
When InsertMethod fire, everything work fine but ...
public IList<Items> InsertRow_Grid(Items item)
{
item.ID = System.Guid.NewGuid().ToString();
bool contains = GridSource.AsEnumerable()
.Any(row => item.JobID == row.JobID);
if (!contains)
{
GridSource.Add(item);
}
else
{
lblMsg.Text= "This record has already exists.";
}
return GridSource;
}
It doesn't know my label object which is presented in my aspx file.
I had read this so that I can search proper solution.
But I still don't get how to do.
Every suggestion will be appreciated.

This is because asp:ObjectDataSource creates new instance of object you specified in "TypeName" property
To use current page object instead of creating new, you need this code:
YourObjectDataSource.ObjectCreating += (s, a) => { a.ObjectInstance = this; };
Place it in Page_Load or Page_Init

You can add this code to your page
...
<asp:Label id="lblMsg" runat="server"/>
<asp:ObjectDataSource ID="Item" runat="server"
SelectMethod="Grid_DataBind" TypeName="XXX.XXX.XXX"
DataObjectTypeName="Controller.Items" UpdateMethod="UpdateRow_Grid"
InsertMethod="InsertRow_Grid">
.....

Related

Wrestling with ObjectDataSource - other controls and variables not defined

I have a Gridview with an ObjectDataSource, sort of like this:
<asp:GridView ID="myGridView" runat="server" AllowSorting="True" ondatabound="myGridView_DataBound" cssClass="coolTable"
OnRowDataBound="myGridView_RowDataBound"
AllowPaging="True" AutoGenerateColumns="False" DataSourceID="myDataSource">
<PagerSettings mode="NextPreviousFirstLast">
</PagerSettings>
</asp:GridView>
<asp:ObjectDataSource ID="myDataSource" runat="server"
SelectMethod="GetSearchResults" EnablePaging="true"
StartRowIndexParameterName="startIndex"
MaximumRowsParameterName="pageSize"
SortParameterName="sortBy" SelectCountMethod="GetSearchCount" >
</asp:ObjectDataSource>
Andy my function, GetSearchResults, is called, so that's all good. The problem is that in GetSearchResults, I want to use other variables besides the ones passed to it, but they do not seem to have values when GetSearchResults runs. I stepped through in the debugger, and I can see that Page_Load is called before GetSearchResults - but referencing any of the controls on my page throws an error, and fields belonging to my page have no value (even though I set them at Page_Load).
I read ASP.Net Object Data Source - Data Binding and skimmed the Page Life Cycle Overview linked to there, but still do not understand why my other variables are not available.
But here is my real question - I don't really care why they aren't available; I would like to know a good pattern to make values available (that were set during Page_Load) to my GetSearchResults function. Currently I'm saving things in session, but that seems kind of ridiculous.
[EDIT to add background]
I am doing some database queries on Page_Load to set some values which in turn affect the layout and content of my page. Those values are also used to modify the selection criteria for the data in my GridView. I started using the ObjectDataSource because to allow me to efficently page through a lot of records (https://msdn.microsoft.com/en-us/library/bb445504.aspx) but didn't initially understand that a new instance of the Page is created and the method called after that - I was thinking it was handled like a postback. I was hoping to avoid saving those interim values in form fields, session variables, etc. It looks like maybe the only way to do that is to fill the Gridview during the normal page lifecycle, but it looks like that means giving up the automatic paging of the Gridview.
In this question Andy points why the page elements are not available in SelectMethod, here is the MSDN explanation :
If it is an instance method, the business object is created and
destroyed each time the method that is specified by the SelectMethod
property is called.
But, in my trials I can access the page variables by current context's Request.Forms collection. It's a little confusing. But if you define some html form elements, you can access them in SelectMethod by Request.Forms collection. Also you can access server variables' values, but, if you dig into it, you can see their name depends on the hierarchy in page control tree.
Here is my trial, in my aspx file :
<input name="txtCriteria"></input>
<asp:Button runat="server" ID="btnPostSearch" OnClick="btnPostSearch_Click"/>
<asp:GridView ID="myGridView" runat="server" AllowSorting="True"
AllowPaging="True" AutoGenerateColumns="False" DataSourceID="myDataSource">
<Columns>
<asp:BoundField DataField="Result" />
</Columns>
<PagerSettings mode="NextPreviousFirstLast">
</PagerSettings>
</asp:GridView>
<asp:ObjectDataSource ID="myDataSource" runat="server" TypeName=""
SelectMethod="GetSearchResults">
</asp:ObjectDataSource>
And this is the code behind file :
public List<SearchResult> GetSearchResults()
{
string criteria = string.Empty;
if (HttpContext.Current.Request["txtCriteria"] != null)
{
criteria = HttpContext.Current.Request["txtCriteria"];
}
List<SearchResult> searchResults = new List<SearchResult>();
searchResults.Add(new SearchResult() { Result = "trial 1 " + criteria });
searchResults.Add(new SearchResult() { Result = "trial 2 " + criteria });
return searchResults;
}
protected void btnPostSearch_Click(object sender, EventArgs e)
{
myGridView.DataBind();
}
When you start using ASP.NET's DataSourceControls (ObjectDataSource, SqlDataSource, AccessDataSource, etc.) and their counterparts DataBoundControls (DropDownList, DetailsView, ListView, FormView, GridView), you really want to forget about ASP.NET lifecycle (and stop pulling hair), and if you do it well, you can even forget about code-behind code (aspx.cs files) because now the system can be pretty automatic between datasources and databound controls.
In fact this paradigm (that has appeared only starting with .NET 2.0) really helps to focus on declarative HTML-like code.
A DataSourceControl uses a collection of objects of type Parameter as parameters to the methods it uses. For example, the ObjectDataSource's SelectMethod uses the SelectParameters property (of ParameterCollection type).
You can define these parameters declaratively. Let's take an example:
<form id="form1" runat="server">
<div>
<asp:TextBox ID="MyTextBox" Text="3" runat="server" />
<asp:Button runat="server" Text="Run" />
<asp:GridView ID="myGridView" runat="server" DataSourceID="myDataSource" />
<asp:ObjectDataSource ID="myDataSource" runat="server"
SelectMethod="GetSearchResults"
TypeName="WebApplication1.Code.MyModel">
<SelectParameters>
<asp:ControlParameter ControlID="MyTextBox" PropertyName="Text" Name="myCount" />
</SelectParameters>
</asp:ObjectDataSource>
</div>
</form>
Here, myDataSource defines a GetSearchResults as the SelectMethod (I've omitted your other parameters but the idea is the same) method on a MyModel class in some class. It also defines a parameter named myCount. This parameter is a ControlParameter (there are others): it will connect to the ASP.NET control MyTextBox which happens to be defined as a TextBox control, and will use the TextBox's Text property as the the value of the myCount parameter.
Here is the code of the object model:
namespace WebApplication1.Code
{
public class MyModel
{
public string Name { get; set; }
public static IEnumerable GetSearchResults(int myCount)
{
for (int i = 0; i < myCount; i++)
{
yield return new MyModel { Name = "item " + i };
}
}
}
}
As you see, the method also has a myCount parameter defined (it's case sensitive, and yes, ASP.NET will convert automatically from string to int, it's almost magic, it uses TypeConverters under the hood), so everything will work as expected, without any code-behind code. It's some kind of an MV pattern (M model V view) and DataSourceControl/DataBoundControl do the binding.
So, you have to think this way now, and use parameters. If the provided list of parameters (QueryString, Cookie, Form, Profile, Route, Session) is no enough, you can provide your own. For example I can define a special parameter that will get myCount randomly (it's just an example :-):
I can use it like this, and I can define custom arguments for this parameter:
<%# Register Namespace="WebApplication1.Code" TagPrefix="my" Assembly="WebApplication1" %>
...
<SelectParameters>
<my:RandomParameter Name="myCount" Min="10" Max="20" />
</SelectParameters>
The custom parameter type code:
public class RandomParameter : Parameter
{
protected override object Evaluate(HttpContext context, Control control)
{
// you can get to page or environment from here with 'context' and 'control' parameters
return new Random(Environment.TickCount).Next(Min, Max);
}
[DefaultValue(1)]
public int Min
{
get
{
object o = ViewState["Min"];
return o is int ? (int)o : 1;
}
set
{
if (Min != value)
{
ViewState["Min"] = value;
OnParameterChanged();
}
}
}
[DefaultValue(10)]
public int Max
{
get
{
object o = ViewState["Max"];
return o is int ? (int)o : 10;
}
set
{
if (Max != value)
{
ViewState["Max"] = value;
OnParameterChanged();
}
}
}
}

ASP.net Speeding up the dropdownlist load by preloading its data from table

I have a grid view that uses dropdownlist to select employees ID but displaying names.
<EditItemTemplate>
<asp:DropDownList ID="DropDownList5" runat="server" AppendDataBoundItems="True" DataSourceID="SqlDataSourceEmployees" DataTextField="name" DataValueField="empID" SelectedValue='<%# Bind("employee") %>'>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
This works fine, but the SqlDataSourceEmployees is called the moment user clicks on the dropdownlist, which causes quite annoying delay, since as I understand first it fires a SQL command (simple SELECT empID,NAME FROM EMPLOYEES WHERE department=#department) and then the list is populated. It would be much better to bind the dropDowList to something that is already in memory, especially that I don't have to worry that the data in the list would change after page has been loaded.
I've thought about loading it to the DataTable on PageLoad and then binding such table to dropDownList but the list cannot find mentioned above table. I've even put the DataTable as public method of the webpage:
public partial class PlannersCurrentRoster : System.Web.UI.Page
{
private DataSet.employeesDataTable employeesTable;
public DataSet.employeesDataTable EmployeesTable
{
get { return employeesTable; }
set { employeesTable = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
DataSetTableAdapters.employeesTableAdapter TA = new DataSetTableAdapters.employeesTableAdapter();
DataSet.employeesDataTable empTable = TA.GetDataByDepartment(lblDepartment.Text);
EmployeesTable = empTable;
but then changing the bind of the list
<EditItemTemplate>
<asp:DropDownList ID="DropDownList5" runat="server" AppendDataBoundItems="True" DataSourceID="EmployeesTable" DataTextField="name" DataValueField="empID" SelectedValue='<%# Bind("employee") %>'>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
fails to find the "EmployesTable".
EDIT:
Following the solution below I've tried:
protected void GridView5_RowUpdating(object sender, GridViewUpdateEventArgs e)
{ ((DropDownList)GridView5.Rows[e.RowIndex].FindControl("DropDownList5")).DataSource = EmployeesTable;
((DropDownList)GridView5.Rows[e.RowIndex].FindControl("DropDownList5")).DataBind();
}
Which doesn't speed up things a bit, I'm sure that the DDL still takes data from SQL source (when I was trying to remove it, I had an error stating that SelevtedValue is invalid)
So I've tried to assign it one step earlier, during editing event
protected void GridView5_RowEditing(object sender, GridViewEditEventArgs e)
{
((DropDownList)GridView5.FindControl("DropDownList5")).DataSource = EmployeesTable;
((DropDownList)GridView5.FindControl("DropDownList5")).DataBind();
}
but then it fails to find dropdownlist5
EDIT: I give up. After reading this article I've simply changed SQLDataSource type to DataReader which indeed improved performance. Or maybe its the placebo effect for my tired mind.
You can't do it the way you have it since the your employeesTable variable is destroyed as soon as the page is served. Each postback then gets a new instance. If the list is not unique, instead store it into the Cache object. You can then set a timeout for it as well.
If it is based on data for the page, you can either store it in session which could carry it across pages but can degrade performance if you have a large number of objects storing in session across users.
If it's not too large you could store it in ViewState instead. It will then be serialised to the client. The downside is, the data can bloat the HTML sent to the client.
In your case, since the datatable seems to be dependent upon the a text field, it may be better to use the viewstate. In your case though, complexity is added due to the fact you need to know when the text value has changed as well so you can negate the data.
The following is a crude example of ViewState but you can also adapt for Session and the Cache.
private string SelectedDepartmentText
{
get
{
if(ViewState["SelectedDepartmentText"] != null)
return ViewState["SelectedDepartmentText"].ToString();
else
return string.Empty;
}
set{ViewState["SelectedDepartmentText"] = value;}
}
public DataSet.employeesDataTable EmployeesTable
{
get
{
if(!SelectedDepartmentText.Equals(lblDepartment.Text))
{
// if the SelectedDepartmentText isn't the same as the lblDepartment.Text, go fetch it
DataSetTableAdapters.employeesTableAdapter TA = new DataSetTableAdapters.employeesTableAdapter();
ViewState["EmployeesTable"] =TA.GetDataByDepartment(lblDepartment.Text);
// save the lblDepartment.Text value to the viewstate for next time.
SelectedDepartmentText = lblDepartment.Text;
return ViewState["EmployeesTable"];
}
else
{
// let's see if we have something already and return it
if(ViewState["EmployeesTable"] != null)
return (DataSet.employeesDataTable)ViewState["EmployeesTable"];
else
{
// if we don't, let's get it, this also handles an empty string for the
// lblDepartment.Text
DataSetTableAdapters.employeesTableAdapter TA = new DataSetTableAdapters.employeesTableAdapter();
// store it in the viewstate
ViewState["EmployeesTable"] =TA.GetDataByDepartment(lblDepartment.Text);
// and return whatever we got back
return (DataSet.employeesDataTable)ViewState["EmployeesTable"];
}
}
return null;
}
set{ ViewState["EmployeesTable"] = value;}
}

INT converted to boolean updateable in a checkbox

I have been programming for many years, about 10 in an older version of .NET, as a result I'm new to LINQ, UpdatePanels and Ajax and their way of doing things.
The following code works correctly.
The database field is defined as:
rptPriority INT NOT NULL DEFAULT(0)
A much simplified page stub which works is:
<asp:UpdatePanel ID="upReport" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<fieldset>
<asp:DetailsView ID="dvReport" runat="server" DataSourceID="ldsReport" CssClass="reset"
AutoGenerateRows="False" DefaultMode="Edit" Width="100%">
<Fields>
<asp:TemplateField>
<ItemTemplate>
<asp:DynamicControl ID="Priority" runat="server" DataField="rptPriority" Mode="Edit" CssClass="general" />
etc
What I need to do is change that Dynamic Control as a textbox to a checkbox which is updatable and driven by the same data. The following gives the correct data but doesn't update.
Were I doing this using straight SQL or PROCEDURES, this would not be a big problem. (also not an option)
<asp:CheckBox ID="Priority" runat="server" Checked='<%# Convert.ToBoolean(Eval("rptPriority")) %>' />
I changed "Eval" to "Bind" and got the "ERROR CS0103: The name 'Bind' does not exist in the current context"
I suspect that the "Convert.ToBoolean" is part of the problem.
There are many pages which I've perused trying to get the info I need. Among them How to add checkbox to datagrid in vb.net , Html.CheckBox returns false if disabled, even if seleced and Checkbox server/client events , How do you know to use Container.DataItem when data binding in ASP.NET? Is there a reference? , The databind bind() function belongs to which class? not to mention about 50 more outside of stack overflow which got me to where I am now.
Edit
As per Rob's suggestion, I added the following, but couldn't get / find any way to use "DetailsViewUpdateEventArgs".
protected void dvReport_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
DetailsView dv = sender as DetailsView;
CheckBox ctlPriority = dv.FindControl("Priority") as CheckBox;
e.NewValues["rptPriority"] = ctlPriority.Checked ? 1 : 0;
}
The following is a stub from the save / update code behind.
protected void btnSave_OnCLick(object sender, EventArgs e)
{
RadioButtonList rblReportStatus = (RadioButtonList)dvReport.FindControl("rblReportStatus");
using (RiderReportDataContext db = new RiderReportDataContext())
{
Report report = null;
Contact contact = null;
DateTime now = DateTime.Now;
bool doUpdate = false;
ldsContact.Updating += (o, ea) =>
{
Contact original = (Contact)ea.OriginalObject;
contact = (Contact)ea.NewObject;
if (
original.FirstName != contact.FirstName ||
...
original.Email != contact.Email)
{
doUpdate = true;
}
db.Contacts.Attach(contact, original);
ea.Cancel = true;
};
// force the update procedure
dvContact.UpdateItem(true);
ldsReport.Updating += (o, ea) =>
{
Report original = ea.OriginalObject as Report;
report = ea.NewObject as Report;
if (rblReportStatus.SelectedItem != null)
{
report.ReportStatusId = int.Parse(rblReportStatus.SelectedValue);
}
if (
original.ReportStatusId != report.ReportStatusId ||
original.SourceId != report.SourceId ||
...
original.ReportTypeID != report.ReportTypeID ||
original.rptPriority != report.rptPriority || // The value here doesn't change
original.SupervisorId != report.SupervisorId)
{
doUpdate = true;
}
db.Reports.Attach(report, original);
ea.Cancel = true;
};
// force the update procedure
dvReport.UpdateItem(true);
// Other Search For Updates
if (doUpdate)
{
contact.ChangedOn = now;
report.ChangedOn = now;
Log log = new Log();
log.ReportId = report.Id;
log.UserId = MembershipClass.User.Id;
log.Text = "The report updated.";
log.CreatedOn = now;
report.Logs.Add(log);
db.SubmitChanges();
}
}
if (Page.IsValid)
{
Response.Redirect("~/default.aspx" /*table.ListActionPath */);
}
}
As you've discovered, Bind() doesn't provide an easy way to convert a data type. You will find other answers which suggest changing the type of the data you are binding to, but I understand this isn't an option in your case.
I think your best solution is to go back to one-way binding. e.g. use your existing code:
<asp:CheckBox ID="Priority" runat="server"
Checked='<%# Convert.ToBoolean(Eval("rptPriority")) %>' />
Which will correctly set the value of the checkbox when the DetailsView is rendered, but will not provide a value for rptPriority when the details are updated. For this you'll need to add an OnItemUpdating event handler to your DetailsView, which will allow you to perform the custom conversion your need. e.g.
<asp:DetailsView ID="dvReport" runat="server"
onitemupdating="dvReport_ItemUpdating"
And the implementation in your code-behind will look like this:-
protected void dvReport_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
DetailsView dv = sender as DetailsView;
CheckBox ctlPriority = dv.FindControl("Priority") as CheckBox;
e.NewValues["rptPriority"] = ctlPriority.Checked ? 1 : 0;
}
Hope this helps.

How to change button css on pageload

Hi and thanks in advance...
I have a button that I want change the css on pageload in c# and asp.net. Right now, on pageload, I am only able to change the text. When the text contains "ADD" I need it to be green, else blue.
Inside of a gridview I have this:
ASP.NET
<asp:TemplateField HeaderText="Tower">
<ItemTemplate>
<asp:Button ID="Button_Detail" CssClass="page-btn blue" CausesValidation="false"
CommandArgument='<%#Eval("idRangeList") %> ' CommandName="Detail" runat="server"
Text='<%# getButtonText(Eval("idRangeList")) %>' OnClick="btnDetails_Click">
</asp:Button>
</ItemTemplate>
</asp:TemplateField>
c#
protected string getButtonText(object o)
{
String btnText;
int rID = Convert.ToInt32(o);
WISSModel.WISSEntities context = new WISSModel.WISSEntities();
var text = (from t in context.Towers
where t.isDeleted == false && t.fkRangeList == rID
select t);
if (text.Count() == 0)
{
btnText = "3. ADD";
}
else
btnText = "Details";
return btnText;
}
I am up for either a jquery or c# solution.
I have tried both and I am stuck. On the C# side, I am not able to access the ButtonID.
For JS I tried this, but its not doing anything:
function textCheck() {
//var buttonDetails = $("Button_Detail");
if($("Button_Detail:contains('ADD')")){
$("Button_Detail").css("green v2");
}
}
you need to try:
if($(".page-btn").val()=='ADD'){
$(this).removeClass().addClass('.page-btn green');
}
This line will not work:
$("Button_Detail").css("green v2");
It needs to be:
$("Button_Detail").addClass("green v2");
However this will still not work as your selector isn't correct. It either needs to have a # for IDs or a . for classes. Given that .NET's IDs are changable it's far easier to give your control a unique class and use that.
In your case:
$(".page-btn").addClass("green v2");
The jQuery css function is for adding specific CSS properties to an element.
http://api.jquery.com/css/
If you want to manipulate which classes an element has you should look at the class attribute documentation:
http://api.jquery.com/category/manipulation/class-attribute/

NullReferenceException when assigning a Session variable/value

I have in many places in my ASP.NET project used the Session variable for storing data. I usually write something like this:
public uint MyPropery
{
get
{
object o = Session["MyProperty"];
if (o != null)
return (uint)o;
else
return 0;
}
set
{
Session["MyProperty"] = value;
}
}
However, this time I get a NullReferenceException in the setter. As far as I know, it is valid to assign the Session variable in the manner above. Also, Session is not null and neither is value.
Any ideas on this?
Edit:
Adding the code for the UserControl in which the property exists. I am using ext.net but that shouldn't have anything to do with this. One thought that crossed my mind:
The UserControl (seen below) is added dynamically in code-behind of a page. Can that have anything to do with it?
I am adding UserControls like this (on a Page):
foreach(CoreCommons.System.Comment c in cg.Reply_Comments)
{
WebApplicationExtNetTest.Secure.UserControls.CoreComment cc = new UserControls.CoreComment();
cc._Comment = c; // here is where i get the NullRef
this.Panel1.ContentControls.Add(cc);
}
Markup:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="CoreComment.ascx.cs" Inherits="WebApplicationExtNetTest.Secure.UserControls.CoreComment" %>
<%# Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<ext:Panel runat="server" ID="CoreCommentOuterPanel" BodyStyle="background: #FFFDDE">
<Items>
<ext:ColumnLayout runat="server">
<Columns>
<ext:LayoutColumn ColumnWidth="0.8">
<ext:Image runat="server" ImageUrl="/Resources/bullet_triangle_green_16x16.png" Align="AbsMiddle"></ext:Image>
<ext:Label runat="server" ID="lblCommentInfo"></ext:Label>
</ext:LayoutColumn>
<ext:LayoutColumn ColumnWidth="0.2"><ext:Button runat="server" ID="btnDelete" Icon="Delete"></ext:Button></ext:LayoutColumn>
</Columns>
</ext:ColumnLayout>
<ext:Label runat="server" ID="lblComment"></ext:Label>
</Items>
</ext:Panel>
Code-behind:
namespace WebApplicationExtNetTest.Secure.UserControls
{
public partial class CoreComment : System.Web.UI.UserControl
{
public CoreCommons.System.Comment _Comment
{
get
{
object o = Session["CoreComment_ObjectId"];
if (o != null)
return (tWorks.Core.CoreCommons.System.Comment)o;
else
return null;
}
set
{
Session["CoreComment_ObjectId"] = value;
SetComment();
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
private void SetComment()
{
if (_Comment == null)
{
lblCommentInfo.Text = "";
lblComment.Text = "";
}
else
{
lblCommentInfo.Text = _Comment.Author + ", " + _Comment.TimeStamp.ToString("g");
lblComment.Text = _Comment.Text;
}
}
}
}
I'm almost completely sure the NullReferenceException is thrown in SetComment() because none of the CoreComment's child controls (lblComment, lblCommentInfo) are properly instantiated at the point you set the _Comment property.
The reason these child controls are not instantiated is indeed the way you currently add the CoreComment controls. For dynamically adding UserControls, you must use Page.LoadControl() (see: here) to create a new instance of the control, as it does some behind-the-scenes magic to ensure it is properly initialized, which includes the instantiation of the child controls.
On a sidenote, personally I'd change SetComment() to SetComment(CoreCommons.System.Comment comment) and use the parameter instead of repeatedly calling the getter, or, if staying with the original, at least call the getter only once and store the result in a local variable. With what I assume is probably InProc session storage it won't make much of a difference, but in any other storage mode you'd repeatedly deserialize the Comment object for no reason.
You need to use the Page.LoadControl() method instead , please look here
BTW:the problem is in adding the control programatically with that way.
Use:
return Session["MyProperty"] as uint? ?? 0;
and post somewhere full exception stack trace with inner exception(s)

Categories