Web Forms :: Code-Behind Null Reference Exception Accessing Controls With Derived PageBase?
Feb 16, 2010
I have a class that derives from System.Web.UI.Page and have set my pages to derive from this custom page class instead of Page. At runtime, the controls are never initialized and throw a NullReferenceException. I've changed some class names and namespaces in the pasted code to protect the innocent. The only thing that I currently override in my PageBase is OnPreLoad and I do call the base.OnPreLoad. I'll eventually add more functionality to this PageBase but for now all that it has is this:
[Code]....
I've tried putting this into a class library (with System.Web referenced) and I've also tried moving the class into the web application and had the same results either way. As another strange twist, I have another class with derives from PageBase called IndexPageBase and it doesn't have this problem:
[Code]....
[Code]....
[Code]....
View 7 Replies
Similar Messages:
Nov 13, 2010
i get a null reference exception for this code.//was trying to retrieve cookie, who's name is attached as query string.
string cookieName = Request.QueryString["CookieName"].ToString();
View 1 Replies
Sep 2, 2010
Null Reference Exception was not handled by user Object Reference not set to instance of an object
View 2 Replies
May 19, 2010
i have null reference exception in grid view, in the
string s = ((Label)GridView1.FindControl("Label6")).Text;
i tryed this to e.Values["EventId"].ToString()
but still the some why is that?
the full code :
[Code]....
View 1 Replies
Dec 10, 2010
I am getting the Null reference exception in
[Code]....
also when I used the Quickwatch, I get this error message.
getElementById The name 'getElementById' does not exist in the current context
I am also using Master Pages.
View 5 Replies
Jul 9, 2012
This is my button event code
protected void ImageButton2_Click1(object sender, ImageClickEventArgs e)
{
string data = Server.UrlDecode(Request.QueryString["BehCode3"]);
string filename = System.IO.Path.GetFileName(fup1.PostedFile.FileName);
string filename1 = System.IO.Path.GetFileName(fup2.PostedFile.FileName);
string filename2 = System.IO.Path.GetFileName(fup3.PostedFile.FileName);
[Code]...
View 1 Replies
Jan 20, 2011
I have a .ascx file residing in another page which has a button on it. On click I run a select statement that accesses the textbox for a value.
However, it keeps returning a Null Exception Error. I am trying access the textbox and its text through
[Code]....
I also tried -[Code]....
I also tried -[Code]....
But none of them work. Please can someone advise me how I find the textbox and then access its text?I have looked round the forums / google and cant find a way of doing this!
View 4 Replies
Dec 15, 2010
let me see if I can explain this clearly. I have a gridview control
and I am trying to use the Edit function. In my gridview, there are numerous rows. I pick one to change and click Edit. I then see the boss name in my gridview and click "Change". When I click Change, I'm expecting two fields to appear, one is a label, the other is a DropDownList. I get this error when I click:
System.NullReferenceException was unhandled by user code
Message=Object reference not set to an instance of an object.
Source=App_Web_lzmklgbg
StackTrace:
at Training_TRManageOrg.LinkButton1_Click(Object sender, EventArgs e) in d:projectsediting.aspx.cs:line 108
at System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e)
at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
Gridview HTML:
<asp:TemplateField HeaderText="Director">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("director") %>'></asp:Label>
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Change</asp:LinkButton>
<asp:Label ID="Label4" runat="server" Text="Director" Visible="False"></asp:Label>
-
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="trDirector"
DataTextField="name" DataValueField="id" onselectedindexchanged="DropDownList2_SelectedIndexChanged"
Visible="False"></asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("director") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Code Behind:
protected void LinkButton1_Click(object sender, EventArgs e)
{
DropDownList DropDownList1 = ((DropDownList)FindControl("DropDownList1"));
DropDownList1.Visible = true; // this line is where the exception occurs
Label3.Visible = true;
}
I figure I must be overlooking something so I'm asking what am I missing?
View 4 Replies
Oct 19, 2010
I am stuck into a problem, i have a user control ProductListing.ascx that contains ListView binded to an object datasource, SelectMethod and SelectCountmethod are provided as well. Everything works fine but the problem started when i add another user control declarativlly Filter.ascx in the productListing.ascx. I want to assign value to a public property MaxPrice in Filter.ascx. I am trying to set this property in the SelectMethod of ObjectDataSource. Usercontrol "Filter.ascx" throws null reference exception when i try to set its MaxPrice Property.
I tried to acced the usercontrol in Databind method of ListView , it is accessible here but viewstate is empty at this point, i saved the value in viewstate in SelectMethod of objectDatasource but i cant access viewstate in ListView Databind. Its empty. Its a simple code and no rewriting to viewstate elsewhere.
Important: My Codebehind files are in a seperate project and .ascx files in seperate project
View 1 Replies
Aug 20, 2010
I developed a page in VWD 2008 and it works perfectly locally, but when I deployed it on the server every Page.FindControl() call is causing the NullReference Exception "Object reference not set to an instance of an object. " Can anyone help me out? Code is below
[Code]....
View 1 Replies
Sep 1, 2010
I'm getting a null reference exception whenever I try to databind this datatable to the Gridview. I know for sure that the datatable has data. I've checked it.
[Code]....
I get the error when it gets to the last line here..
View 8 Replies
Apr 29, 2010
I have a TextArea html helper method I'm calling in a foreach loop. Basically, when I initially load the View it works fine, but when i reload the View and load postback data, the same TextArea throws a NullReferencException and yet the variable I'm using in the TextArea as the name of the TextArea is not null. I've attached a picture below for demonstration:
if it's difficult to see, the blue arrow below is pointing to the variable used to name the TextArea. Again, it works on initial load, but it errors out on postback when the page is reloaded. I'm not sure what's going on.
View 2 Replies
Jul 15, 2010
I am getting this exception even though no values to my knowledge are null, apart from the model.SuburbID itself.
Here is controller code for getting the suburbs:
[Code]....
Here is the view code:
[Code]...
View 3 Replies
Sep 2, 2010
I have an Asp.net web service that I created using Visual Studio 2005. I can acess the web service in my test environment, call methods and return data as expected. If this web service is published to the outside world (Outside of the company firewall), it will return a null why this might be happening? The same code is being used,against the same database. The only difference is that the published website is giving back the null reference exception. If I type in the URL for the web service "https://secure.theSiteGeist.com/wsIndigo.asmx" a list of methods for the web service is displayed in my browser. Yet if I try and call any methods on the web service I get back the null reference exception. Note that the URL I posted above is not the real name of my web service, but is just used for reference sake.
View 3 Replies
Jan 19, 2010
My controller calls a class in my model which is getting data from a REST web service. The class in the model then passes the data back to the controller using an IList, like so:
[Code]....
My problem is this: The data that is held in the IList isn't there until the user has done a search in the View, submiting a form. This is a basic search function with 2 textboxes and a submit button in a form. When the user clicks submit, the controller action is called, the web service is then called, and the data in the IList gets populated. The problem is that in the View I am using a strongly typed view and my model reference in the foreach loop throws a Null Reference Exception because there is no data in it, because a search has not been conducted yet...
[Code]....
So, how can I have the above foreach loop in my view if there isn't any data in the model until a search has been conducted? Is there a better way that I should be doing this?
Essentially, what's the best method for passing data back to a view that is based on a form submittion?
View 6 Replies
Dec 6, 2010
We have a chart on a page that current is hard coded with test data, client likes and we are trying to now link to live data.I have tried different things in the code behind to build the url and keep getting Null Reference Exception even though when i debug the url is there and complete. I can take the value that i get in debug and paste directly to the browser and the chart works. so i know that im building the url correctly, but setting the .Src of the image in the page_load event doesnt seem to be the correct way to populate the image..Here is the complete link that is built in the code behind that is passed to the src of the image control.http://chart.apis.google.com/chart?hs=300x265&chd=s:bD&chdl=DVDs|DVDs+with+Scracthes&chdlp=b&chl=44|5&chma=40,60,0,40&chtt=DVD+Report&cht=p3&chco=751010|FFCC33 In the page load event i have the following:
[Code]....
[Code]....
I place a break point on the line where i set the src and as i step thru everything is correct and the src is being populate with the correct link, but when i step past that line, then i get the null reference.Now why is it that i can paste that link to the browser and it works.. and if i hardcode that link in the image src on my aspx page and comment out the code behind it works there also..
View 17 Replies
May 26, 2010
I am tring to access a custom property on my Master page in a custom PageBase that resides in the App_Code folder. I can get this to work no problem in a web app but im having trouble doing it in the website project.
PageBase:
public abstract class PageBase : ClientSidePageBase
{
public WebMessage Message
{
get
[code]...
The above sample is what is in my web application and works fine but if i try and put this in the App_Code it doesnt pick up the MasterPage class so I cant access the property.
View 1 Replies
Jun 30, 2010
I am using httpcontext.Current in one my action method and i created the ms test method for testing this action and also i created the Mock object for httpcontect,but when i am trying to run the MS test script i am getting null reference exception from the line which i am using httpcontext.current in the action method.
View 1 Replies
Jul 10, 2010
I have created a masterpage where I require user login. The content pages are only displayed if the user is authenticated.
<LoggedInTemplate>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</LoggedInTemplate>
On my content page I have
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:DropDownList ID="dropdown1" runat="server"></asp:DropDownList>
</asp:Content>
When run, I can successfully authenticate and then when I attempt to view this particular content page I get an error on the page load where I'm trying to populate the dropdownlist. The error I get is a Null Reference exception. I don't fully understand the page lifecycle of an asp.net page, but I also don't understand why the page compiles successfully and its only when run that I get this exception. It seems that the control is not created when the page_load command is called. How can I change the contents of a dropdownlist on page load of a content page that requires authentication?
View 6 Replies
Mar 8, 2010
I' m using a web custom control to upload images and mark them as primary. all the flow is working fine but it fails to mark images as primary in a diffrent category(there are four categories in which we can load a image-,catalog,primary,misc).It works in - category but not in others when I debug it is failing at a condition in grey . If it is not an element of the Datalist item it would not even enter the loop. I' m lost and unable to find the reason.
View 2 Replies
Dec 25, 2010
I am trying to access unmanaged code(C++) dll in my asp.net web application project. I created a class to access library functions to be able to use in my application. The DLL is located in Bin Folder of my project. I was able to work with it fine on my localhost server but when I try it on the server where the application is hosted, it gives me this error:
Security Exception:
Description:
The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException:
System.Security.Permissions.SecurityPermission
View 4 Replies
Nov 15, 2010
In a recent post, I expressed a need to access the properties for the body using declarative syntax, see
Contentplaceholder for replacing attributes?
But, the syntax confuses the editor which is not acceptable.
My hypothesis for a workable solution is to make the change in code. To derive a class from System.Web.UI.Page with extended functionality. However, I want for the designer to be able to still use declarative syntax to set the body tag.
I do not want to have to change any code in my aspx web pages except that they derive from base I want to be able to set these properties using declarative syntax, merely by adding a tag in the derived page I'm not immediately sure how to go about doing this because it doesn't exactly fit the OOP paradigm and I'm not sure where the changes need to be made.
I can use a findcontrol in the base to see if the placeholder has been added. But, not sure exactly at what point in the page processing lifecycle that I can use this findcontrol. I need to set the body before it renders but also be able to grab something from the declarative code.
View 2 Replies
Oct 27, 2010
I have a GridView with the following columns
<asp:TemplateField HeaderText="Name">
<FooterTemplate>
<asp:TextBox ID="txt_Name" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lbl_name" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "t_Name") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txt_name" runat="server" Width="100px" Text='<%#DataBinder.Eval(Container.DataItem,"t_Name") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Created By">
<ItemTemplate>
<asp:Label ID="lbl_tabcreatedby" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "t_CreatedBy") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Modify" ShowEditButton="True" />
<asp:CommandField HeaderText="Delete" ShowDeleteButton="True" />
<asp:TemplateField HeaderText="Add a New Name">
<FooterTemplate>
<asp:LinkButton ID="lnkbtn_AddName" runat="server" CommandName="Insert">Add Name</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
And then in the Code Behind I am trying to access the txt_Name Textbox as
protected void gv_Name_RowCommand(object sender, GridViewCommandEventArgs e)
{
string t_Name = ((TextBox)(gv_Name.FooterRow.FindControl("txt_Name"))).Text;
// Insert Code
}
But I am getting null in the string t_Name everytime irrespective of what is the current Text of txt_Name.
However I can get the text if I disable the ViewState for the page.
View 3 Replies
Jan 16, 2010
I downloaded a sample Rolodex from here: [URL] the file to download is at the bottom of the page and it is called 'RolodexDatalist.zip (6.71 kb)' So I changed the HTML to it points to my SQL Server DB. I changed the ConnectionString to this:
<connectionStrings>
<add name="CustomersConnectionString" connectionString="Data Source=EXCEL-4J2W8KYNPSQLEXPRESS;Initial Catalog=Customers;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
Now, everything points to my DB! I thought, ok great, this should be pretty easy. However, when I debug, I get this error message: 'Null reference was unhandled by user code. Object reference not set to instance of an object. Troubleshooting Tips: use the "new" keyword to set an instance of an object.' This line is yellow:
Dim conStr As String = ConfigurationManager _
.ConnectionStrings("conStr").ConnectionString
Here is the code-behind:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections.Generic
Partial Class VB
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
ViewState("CurrentAlphabet") = "ALL"
Me.GenerateAlphabets()
Me.BindDataList()
End If
End Sub
Private Sub BindDataList()
Dim conStr As String = ConfigurationManager _
.ConnectionStrings("conStr").ConnectionString
Dim con As New SqlConnection(conStr)
Dim cmd As New SqlCommand("spx_GetContacts")
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@Alphabet", ViewState("CurrentAlphabet"))
con.Open()
dlContacts.DataSource = cmd.ExecuteReader()
dlContacts.DataBind()
con.Close()
If ViewState("CurrentAlphabet").ToString().Equals("ALL") Then
lblView.Text = "all Contacts."
Else
lblView.Text = "Contacts whose name starts with " & _
ViewState("CurrentAlphabet").ToString()
End If
End Sub
Private Sub GenerateAlphabets()
Dim alphabets As New List(Of Alphabet)()
Dim alphabet As New Alphabet()
alphabet.Value = "ALL"
alphabet.isNotSelected = Not alphabet.Value _
.Equals(ViewState("CurrentAlphabet"))
alphabets.Add(alphabet)
For i As Integer = 65 To 90
alphabet = New Alphabet()
alphabet.Value = [Char].ConvertFromUtf32(i)
alphabet.isNotSelected = Not alphabet.Value _
.Equals(ViewState("CurrentAlphabet"))
alphabets.Add(alphabet)
Next
rptAlphabets.DataSource = alphabets
rptAlphabets.DataBind()
End Sub
Protected Sub Alphabet_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim lnkAlphabet As LinkButton = DirectCast(sender, LinkButton)
ViewState("CurrentAlphabet") = lnkAlphabet.Text
Me.GenerateAlphabets()
Me.BindDataList()
End Sub
End Class
View 8 Replies
Nov 24, 2010
I have created one itemtemplate to display one button in subgrid(grid in grid) in .ascx page:
<asp:datagrid id="grid1" runat="server>
<columns>
<asp:TemplateColumn HeaderText="Close Manually" ItemStyle-HorizontalAlign="left">
[code]...
View 2 Replies