Showing posts with label occurred. Show all posts
Showing posts with label occurred. Show all posts

Thursday, March 29, 2012

Object reference

Object reference not set to an instance of an object.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 40: dtagrdReviewDisplay.DataBind();Line 41: //dropdownlistLine 42: drpdwnRevRating.Items[0].Selected=true;Line 43: drpdwnProRating.Items[0].Selected=true;Line 44:

Is there anything loaded into the dropDown?

You may want to make your code like this to prevent the error:

if(drpdwnRevRating.Items.Count > 0)

drpdwnRevRating.Items[0].Selected = true;

if(drpdwnProRating.Items.Count > 0)

drpdwnProRating.Items[0].Selected = true;


the rating dropdown has ratings 1 to 10,Autopostback property is set to true.

so when the user selects the rating,the new rating is shown in the label and when the forms reloads i want to make Select one as the item to be diplayed.


How about trying the code I sent just to get the page to load. Then you can see if there is actually anything in your dropdownlist. I tried to recreate your error and the only way I can is if I don't put anything into the dropdownlist.

Let me know what happens when you try those 'if' statements.


i have datagrid ,in datagrid i have one drop down,this dropdown has 1 to 10 as listitems

i want to catch the rating what the user has selected so

.aspx

<asp:DropDownList id="drpdwnRevRating" AutoPostBack="True" Runat="server">
<asp:ListItem Selected="True" Value="Select One">Select One</asp:ListItem>
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
<asp:ListItem Value="6">6</asp:ListItem>
<asp:ListItem Value="7">7</asp:ListItem>
<asp:ListItem Value="8">8</asp:ListItem>
<asp:ListItem Value="9">9</asp:ListItem>
<asp:ListItem Value="10">10</asp:ListItem>
</asp:DropDownList>
<br>
Rate the Product:
<asp:DropDownList>
<asp:ListItem Value="1">1</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>

.cs

privatevoid dtagrdReviewDisplay_SelectedIndexChanged(object sender, System.EventArgs e)

{

string strRevRating;

strRevRating=Request["drpdwnRevRating"];

Response.Write(strRevRating);

}

Output notthing is coming in strRevRating and i used break point here,the comilation is not coming into this eventhandler itself.


is their is any problem in this event handler of dropdownlist control what i wrote

protected System.Web.UI.WebControls.DropDownList drpdwnRevRating;

this.drpdwnRevRating.SelectedIndexChanged += new System.EventHandler(this.drpdwnRevRating_SelectedIndexChanged);


private void drpdwnRevRating_SelectedIndexChanged(object sender, System.EventArgs e)
{
string strRevRating;
strRevRating=Request["drpdwnRevRating"];
Response.Write(strRevRating);

}

Object reference not set to an instance of an object.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 65: { Line 66: this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);Line 67: this.drpdwnRevRating.SelectedIndexChanged += new System.EventHandler(this.drpdwnRevRating_SelectedIndexChanged);Line 68: this.Load += new System.EventHandler(this.Page_Load);Line 69:


I think the issues you are having is because the DropDownList does not belong to the page, it belongs to the datagrid. The null exception is because there is no "this.drpdwnRevRating".

To work with the dropdownlists, you must find the control on the line of the datagrid and cast it to a DropDownList. I assume you are using ASP.Net 1.1 which I don't have installed on this computer or I would type up a quick sample, but you can refer to this article.http://www.codeproject.com/aspnet/DataGridDropDownList.asp

Pay attention to how they are doing:

DropDownList dl = (DropDownList)(dgi.Cells[2].Controls[1]);

You can also do:

DropDownList dl = (DropDownList)(dgi.Rows[e.SelectedIndex].FindControls("drpdwnProRating");

//I think that is the right syntax but I don't have the luxury of intellisense right now.

Then you can work with 'dl' instead of 'drpdwnProRating'

I hope that helps to move your forward a bit.

Monday, March 26, 2012

object reference not set to an instance of an object

I'm getting the following error:

Object reference not set to an instance of an object.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.NullReferenceException: Object reference not set to an instance of an object.

I have trace on, but still I'm having trouble detereming what exactly is wrong. Is there anything else you could recommend trying to do? I'm using a dll that was created by a former co-worker and I'm not exactly sure how it works, but trying to figure it out. Thanks

There are several reasons for this. But we are going to need more information. Could you narrow it down to at least where this is happening and posting the code?


If your having trouble finding it, make sure the dll is compiled in debug mode. Also you may want to enable breaking on all exceptions: In the debug menu select 'Exceptions' and check all the boxes under 'Thrown' then click ok and try debugging again. This way if the error is trapped, you'll still break on the line that through the exception.


Why not step through the code to see exactly where it's kicking out. This is a general error that occurs when an object is trying to be referenced that has not been instantiated. Like the other posters eluded to, this can happen in many places. Put some code up for more help.


try to use a breakpoints and see at which line exception is being threw and we can check the line.

Thursday, March 22, 2012

Object reference not set to an instance of an object.

Hello,

Here is the error message:
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object. (Line 175)

Source Error:

Line 172: private void myDataGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e) {
Line 173: DataRowView drv = (DataRowView) e.Item.DataItem;
Line 174: System.Web.UI.WebControls.Image thumb =
(System.Web.UI.WebControls.Image) e.Item.FindControl("thumbnail");
Line 175: thumb.Attributes.Add("OnClick", "window.close()");

Can somebody help me?

Thanks!Hi,

check that you get Image with "thumbnail" name.

Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
<asp:TemplateColumn>
<HeaderStyle CssClass="NormalBold"></HeaderStyle>
<ItemTemplate>
<asp:Image id="thumbnail" name="thumbnail" ImageUrl="<%=
GetBrowsePath((int) DataBinder.Eval(Container.DataItem,'itemId')) %>"
BorderWidth="0" Height="70" Width="100" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn
It still doesn't works.

"Natty Gur" <natty@.dao2com.com> schreef in bericht
news:#FLCVAkZDHA.2520@.TK2MSFTNGP09.phx.gbl...
> Hi,
> check that you get Image with "thumbnail" name.
> Natty Gur, CTO
> Dao2Com Ltd.
> 34th Elkalay st. Raanana
> Israel , 43000
> Phone Numbers:
> Office: +972-(0)9-7740261
> Fax: +972-(0)9-7740261
> Mobile: +972-(0)58-888377
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

Wednesday, March 21, 2012

Object reference not set to an instance of an object.

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

decimal price =
decimal.Parse(((TextBox)PropertyGridView.FooterRow .FindControl("PriceTextBox")).Text);

Any clue why this is happening?

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an
object.]
AllProperies.PropertyGridView_RowCommand(Object sender,
GridViewCommandEventArgs e) in c:\Documents and Settings\Flynn\My
Documents\My Webs\CVM Web Portal\AllProperies.aspx.cs:70
System.Web.UI.WebControls.GridView.OnRowCommand(Gr idViewCommandEventArgs
e) +75
System.Web.UI.WebControls.GridView.HandleEvent(Eve ntArgs e, Boolean
causesValidation, String validationGroup) +76
System.Web.UI.WebControls.GridView.OnBubbleEvent(O bject source, EventArgs
e) +88
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.GridViewRow.OnBubbleEven t(Object source,
EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +86
System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String
eventArgument) +153
System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +172
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919Best guess is that FindControl is failing to find a control wth the id of
"PriceTextBox" so ur getting a null object back.

Of course, the other option is that PropertyGridView.FooterRow is null...

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Microsoft News Group" <mflynn@.cvmediaonline.comwrote in message
news:OLgUH6%23uGHA.4472@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
>
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
>
>
>
decimal price =
decimal.Parse(((TextBox)PropertyGridView.FooterRow .FindControl("PriceTextBox")).Text);
>
Any clue why this is happening?
>
>
>
Stack Trace:
>
[NullReferenceException: Object reference not set to an instance of an
object.]
AllProperies.PropertyGridView_RowCommand(Object sender,
GridViewCommandEventArgs e) in c:\Documents and Settings\Flynn\My
Documents\My Webs\CVM Web Portal\AllProperies.aspx.cs:70
System.Web.UI.WebControls.GridView.OnRowCommand(Gr idViewCommandEventArgs
e) +75
System.Web.UI.WebControls.GridView.HandleEvent(Eve ntArgs e, Boolean
causesValidation, String validationGroup) +76
System.Web.UI.WebControls.GridView.OnBubbleEvent(O bject source,
EventArgs e) +88
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
+35
System.Web.UI.WebControls.GridViewRow.OnBubbleEven t(Object source,
EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
+35
System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +86
System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String
eventArgument) +153
>
System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +172
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919
>
>
>
>


When you're dealing with nulls/nothings, my advise is to break it down into
each piece, then rewrite the uber-single statement.

something like

FooterRow fr = PropertyGridView.FooterRow;
object o = fr.FindControl("PriceTextBox");
TextBox tb = (TextBox)o;
string s = tb.Text;
decimal price = decimal.Parse(s);

You'll usually find it that way.

Its not bad to put a
if(null!= someObject)
{
//do something//
}

in once a while too.

decimal price =

Quote:

Originally Posted by

>


decimal.Parse(((TextBox)PropertyGridView.FooterRow .FindControl("PriceTextBox
")).Text);

"Microsoft News Group" <mflynn@.cvmediaonline.comwrote in message
news:OLgUH6%23uGHA.4472@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
>
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
>
>
>
decimal price =
>


decimal.Parse(((TextBox)PropertyGridView.FooterRow .FindControl("PriceTextBox
")).Text);

Quote:

Originally Posted by

>
Any clue why this is happening?
>
>
>
Stack Trace:
>
[NullReferenceException: Object reference not set to an instance of an
object.]
AllProperies.PropertyGridView_RowCommand(Object sender,
GridViewCommandEventArgs e) in c:\Documents and Settings\Flynn\My
Documents\My Webs\CVM Web Portal\AllProperies.aspx.cs:70
>


System.Web.UI.WebControls.GridView.OnRowCommand(Gr idViewCommandEventArgs

Quote:

Originally Posted by

e) +75
System.Web.UI.WebControls.GridView.HandleEvent(Eve ntArgs e, Boolean
causesValidation, String validationGroup) +76
System.Web.UI.WebControls.GridView.OnBubbleEvent(O bject source,


EventArgs

Quote:

Originally Posted by

e) +88
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)


+35

Quote:

Originally Posted by

System.Web.UI.WebControls.GridViewRow.OnBubbleEven t(Object source,
EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)


+35

Quote:

Originally Posted by

System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +86
System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String
eventArgument) +153
>


System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.Rai
sePostBackEvent(String

Quote:

Originally Posted by

eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)


+172

Quote:

Originally Posted by

System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919
>
>
>
>


Yea named the object wrong you are correct.

"Karl Seguin [MVP]" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME
netwrote in message news:%23nXsqL$uGHA.4612@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Best guess is that FindControl is failing to find a control wth the id of
"PriceTextBox" so ur getting a null object back.
>
Of course, the other option is that PropertyGridView.FooterRow is null...
>
Karl
>
--
http://www.openmymind.net/
http://www.fuelindustries.com/
>
>
"Microsoft News Group" <mflynn@.cvmediaonline.comwrote in message
news:OLgUH6%23uGHA.4472@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

>Object reference not set to an instance of an object.
>Description: An unhandled exception occurred during the execution of the
>current web request. Please review the stack trace for more information
>about the error and where it originated in the code.
>>
>Exception Details: System.NullReferenceException: Object reference not
>set to an instance of an object.
>>
>>
>>
>decimal price =
>decimal.Parse(((TextBox)PropertyGridView.FooterRow .FindControl("PriceTextBox")).Text);
>>
>Any clue why this is happening?
>>
>>
>>
>Stack Trace:
>>
>[NullReferenceException: Object reference not set to an instance of an
>object.]
> AllProperies.PropertyGridView_RowCommand(Object sender,
>GridViewCommandEventArgs e) in c:\Documents and Settings\Flynn\My
>Documents\My Webs\CVM Web Portal\AllProperies.aspx.cs:70
>>
>System.Web.UI.WebControls.GridView.OnRowCommand(Gr idViewCommandEventArgs
>e) +75
> System.Web.UI.WebControls.GridView.HandleEvent(Eve ntArgs e, Boolean
>causesValidation, String validationGroup) +76
> System.Web.UI.WebControls.GridView.OnBubbleEvent(O bject source,
>EventArgs e) +88
> System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
>+35
> System.Web.UI.WebControls.GridViewRow.OnBubbleEven t(Object source,
>EventArgs e) +117
> System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
>+35
> System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +86
> System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String
>eventArgument) +153
>>
>System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String
>eventArgument) +7
> System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
>sourceControl, String eventArgument) +11
> System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
>+172
> System.Web.UI.Page.ProcessRequestMain(Boolean
>includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
>+4919
>>
>>
>>
>>


>
>

Friday, March 16, 2012

Object reference not set to an instance of an object.

Hello could someone please help me with this error?
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

<code>
Line 99: Else
Line 100: '####################
Line 101: Dim objCommand As OdbcCommand = New OdbcCommand("SELECT AuthKey FROM online_user WHERE Username='" & HttpContext.Current.Session("usr_Username").ToString() & "'", objConnection)
Line 102:
Line 103: objConnection.Open()
</code>


Thanks in adavnce

Hello,
The error is in this line HttpContext.Current.Session("usr_Username").ToString()
If the session is empty you will get that type of error. You can solve this problem by removing tostring method to be like this
HttpContext.Current.Session("usr_Username")

HTH
regards
Thanks smiling4ever,
The Session object was indeed empty.

Object reference not set to an instance of an object.

I am getting the following Error

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 12: Dim profile As DataSet
Line 13: Profile = get_profile(UID)
Line 14: TB_FName.Text = profile.Tables.Item("uprofile").Rows.Item(0).Item("fname").ToString

Source File: c:\inetpub\wwwroot\createuser.aspx.vb Line: 14

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
createuser_aspx.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\createuser.aspx.vb:14
System.Web.UI.Control.OnLoad(EventArgs e) +102
System.Web.UI.Control.LoadRecursive() +45
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +952

aspx file imports the class profile
I am using a function get_profile

Imports Microsoft.VisualBasic
Imports system.data
Imports system.data.Odbc

Public class profile
public shared function get_profile (ByVal uid as Integer) as DataSet
Dim myConn As OdbcConnection = New OdbcConnection("connectionstring")
myConn.Open()
Dim SQL As String
SQL = "SELECT * from uprofile WHERE uid=" & uid
Dim DS_Profile As New DataSet
Dim DA_Profile As New OdbcDataAdapter
DA_Profile.SelectCommand = New OdbcCommand(SQL, myConn)
DA_Profile.Fill(DS_Profile)
Return DS_Profile
End Function

I assume that the profile variable will pick up the dataset as a return value
I do not really understand why the error is coming.

Thanks for the helpMake sure the Select statement really return a value based on the uid. If you are 100% sure that the select statement returns rows, make sure the "fname" field is not a DBNull.

Object reference not set to an instance of an object.

When I click button the following error occurs. What does this mean and how to remove it. Please help.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 25: MsgBox("Hi there")
Line 26: 'Put user code to initialize the page here
Line 27: End Sub
Line 28:
Line 29: Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ServerClick

Source File: c:\inetpub\wwwroot\WebForm1.aspx.vb Line: 27

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
localhost.WebForm1.Button1_ServerClick(Object sender, EventArgs e) in c:\inetpub\wwwroot\WebForm1.aspx.vb:27
System.Web.UI.HtmlControls.HtmlInputButton.OnServerClick(EventArgs e) +108
System.Web.UI.HtmlControls.HtmlInputButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138
System.Web.UI.Page.ProcessRequestMain() +1263Can you post lines 1 to 30 of WebForm1.aspx.vb? Because your error message suggests that you've mistakenly deleted some lines of code. Before you post the code, pleaseread this.

Even beyond that, there seems to be a number of problems with your code. I don't think that you can use the MsgBox function in ASP.NET. And having WebForm1.aspx.vb directly within your wwwroot folder seems problematic. Are you working through a book that introduces ASP.NET, or gone through theonline tutorials? If not, you should, aseveryone new to ASP.NET needs to go through the basics.
There is something in your code behind file that is told to do something. The problem is, it is not on your aspx page to do it. It has something to do with that MsgBox. I am not sure of the entire procedure though.
See, Since this is the direct VB code there is no question of "<>" code blocks coming into picture. Since I have been working on VB6 for last 2 years so I find VB code very easy. When I was going through the Help File of ASP.net on creating web page I came across this code. It says that when You double click on the control the "...aspx.vb" file opens and You can write your code for button click or any such events there.
When I run the Page the code behind (in the aspx.vb module) doesn't run but when I put them in html it runs.
So my problem is how to run the code from aspx.vb module of Visualstudio.net package which seems so easy to code and understand for me.
Sounds like you are not telling the aspx page where the codebehind source is located. Top line should read something like this:
<%@. Page language="vb" CodeBehind="DesktopDefault.aspx.vb" AutoEventWireup="false" Explicit="True"Inherits="DotNetNuke.DesktopDefault" %>
which is thenamespace.classname