Showing posts with label button. Show all posts
Showing posts with label button. Show all posts

Monday, March 26, 2012

Object reference not set to an instance of an object

Hi,

I have button on a page, which when clicks gives this error message:

Object reference not set to an instance of an object

It is meant to response.redirect to a new page:

protected void Button2_Click(object sender, EventArgs e)
{
Int32 ProductId = Convert.ToInt32(Request.QueryString["proID"]);
bool result = Executeupdateclickedin(ProductId);
result = Executedeleteshipping(ProductId);
result = Executemassmail2(ProductId);
result = Executeupdatenumberclickedin(ProductId);

Response.Redirect("~/Buyers/defaultedbuyer.aspx?proID=productID");

}

Thanks if someone can help!

Jon

What could be causing this?

Thanks for any help,

Jon

Hi there

To me, it sounds like it doesn't have the value that it is expecting.

Have you debugged and checked that your variables contain values?

Are your queries and methods returning the correct values?


Did you debug it?

Did you see if productid is not coming to null


Hi

I have debugged it - it doesnt show anything up. productid isn't coming null.

Here is the stack trace -

[NullReferenceException: Object reference not set to an instance of an object.]
Sellers_managelisting.Executeupdateclickedin(Int32 ProductId) +143
Sellers_managelisting.Button2_Click(Object sender, EventArgs e) +114
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +75
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +97
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4886
I bolded a line - does that mean the problem is with the updateclickedin section?

Thanks,

Jon


sure the problem looks in that section itself...


Got it!

Thursday, March 22, 2012

Object reference not set to an instance of an object ERROR.

Hi there,

I have a DataList with multiple images in which I want to toggle on and off with a button using the visible property. However I get an error when clicking the button.

Here is my button code:


Private Sub btnImage1_Click(sender As Object, e As EventArgs)

Dim imgPropertyListing1 As Image = Ctype(Findcontrol("imgPropertyListing1"), Image)

Dim imgPropertyListing2 As Image = Ctype(Findcontrol("imgPropertyListing2"), Image)

Dim imgPropertyListing3 As Image = Ctype(Findcontrol("imgPropertyListing3"), Image)

imgPropertyListing1.Visible = True

imgPropertyListing2.Visible = False

imgPropertyListing3.Visible = False

End Sub

Here is the 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 105: Dim imgPropertyListing3 As Image = Ctype(Findcontrol("imgPropertyListing3"), Image)

Line 106:

Line 107: imgPropertyListing1.Visible = True

Line 108: imgPropertyListing2.Visible = False

Line 109: imgPropertyListing3.Visible = False

Source File: K:\details\fullpropertylisting.aspx Line: 107

Any suggestions would be greatly appreciated.

Regards and thanks in advance,

TCMUse the ItemCommand Method. Set your Button Command , e.g. to 'Hide'. The ItemCommand Method is extremely versatile. You may use it for many different purposes. here is one little example. I'm sure u understand:


private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if (e.CommandName == "newmodel")
{
TextBox tb = (TextBox)e.Item.FindControl("txtModel");

if (tb.Text.Trim() == string.Empty)
{
this.trMessage.Visible = true;
this.lblMessage.ForeColor = Color.Red;
this.lblMessage.Text = "** You cannot register an empty string **";
return;
}

int id = (int)this.DataGrid1.DataKeys[e.Item.ItemIndex];
string model = Utilities.HandleRestrictedChars(tb.Text, CharCheck.FromWeb);

int chk = SqlHelper.ExecuteNonQuery(DbConn.Con, CommandType.StoredProcedure,
"AV_InsertModel",
new SqlParameter("@.model", model),
new SqlParameter("@.id", id));

if (chk > 0)
{
this.trMessage.Visible = true;
this.lblMessage.ForeColor = Color.Green;
this.lblMessage.Text = "** The model is registered! **";
tb.Text = "";

DataGrid dg = (DataGrid)e.Item.FindControl("DataGrid2");

this.BindInnerGrid(dg, id);
}
else
{
this.trMessage.Visible = true;
this.lblMessage.ForeColor = Color.Red;
this.lblMessage.Text = "** An error occured! (nothing was registered) **";
}

}
elseif(e.CommandName == "whatever"))
{

// Do something to handle the Commandname 'WhatEver'
}
}
}


You get the point.

Object reference not set to an instance of an object.

Hi All,

I have a webform with a button to add record into the database. When the
button is being clicked, the program will assign initial value controls in a
detailsview control. When the first time, the button being click, the program
works as expected. However, the next click on the button, the program showed
the following error message:

System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_Web_xogepfrv"
StackTrace:
at Inv_Maint.GetDefaultValue(String objMainType) in
C:\Data\OITRS\Inv_Upd.aspx.vb:line 842
at Inv_Maint.btnAddInventory_Click(Object sender, EventArgs e) in
C:\Data\OITRS\Inv_Upd.aspx.vb:line 1132
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEven t(String
eventArgument)
at
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Below is the code for the button:

Protected Sub btnAddInventory_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnAddInventory.Click

HideAll()
btnAddInventory.Visible = False
Select Case UCase(ddlMainType.SelectedItem.Value)
Case "MONITOR"
dvInventory_Monitor.Visible = True
dvInventory_Monitor.ChangeMode(DetailsViewMode.Ins ert)

Case "COMPUTER"
dvInventory_Computer.Visible = True
dvInventory_Computer.ChangeMode(DetailsViewMode.In sert)
GetDefaultValue("dvInventory_Computer")

....

Below is the the code for GetDefaultValue :
Private Sub GetDefaultValue(ByVal objMainType As String)
Select Case (objMainType)
Case "dvInventory_Computer"
CType(dvInventory_Computer.FindControl("txtMainType"),
TextBox).Text = ddlMainType.SelectedValue.ToString
CType(dvInventory_Computer.FindControl("ddlSubType"),
DropDownList).SelectedValue = ddlSubType.SelectedValue.ToString
CType(dvInventory_Computer.FindControl("txtUnitPrice"),
TextBox).Text = "0.00"
CType(dvInventory_Computer.FindControl("txtQuantity"),
TextBox).Text = "1"
CType(dvInventory_Computer.FindControl("ddlRAMType"),
DropDownList).SelectedValue = "NONE"

CType(dvInventory_Computer.FindControl("ddlNICManufacturer"),
DropDownList).SelectedValue = "NONE"
CType(dvInventory_Computer.FindControl("ddlOpticalDrive"),
DropDownList).SelectedValue = "NONE"
CType(dvInventory_Computer.FindControl("txtHDDSpace"),
TextBox).Text = Nothing
CType(dvInventory_Computer.FindControl("ddlGCManufacturer"),
DropDownList).SelectedValue = "NONE"

CType(dvInventory_Computer.FindControl("ddlModemManufacturer"),
DropDownList).SelectedValue = "NONE"

...
Please advise

Regards,
SBWhich one is "line 842"?

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"Seok Bee" <seokbee@.yahoo.com> wrote in message
news:FC2C952C-DAB3-4C99-9E9C-6C25578CD4C2@.microsoft.com...
> Hi All,
> I have a webform with a button to add record into the database. When the
> button is being clicked, the program will assign initial value controls in
> a
> detailsview control. When the first time, the button being click, the
> program
> works as expected. However, the next click on the button, the program
> showed
> the following error message:
> System.NullReferenceException was unhandled by user code
> Message="Object reference not set to an instance of an object."
> Source="App_Web_xogepfrv"
> StackTrace:
> at Inv_Maint.GetDefaultValue(String objMainType) in
> C:\Data\OITRS\Inv_Upd.aspx.vb:line 842
> at Inv_Maint.btnAddInventory_Click(Object sender, EventArgs e) in
> C:\Data\OITRS\Inv_Upd.aspx.vb:line 1132
> at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
> at System.Web.UI.WebControls.Button.RaisePostBackEven t(String
> eventArgument)
> at
> System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
> eventArgument)
> at System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
> sourceControl, String eventArgument)
> at System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection
> postData)
> at System.Web.UI.Page.ProcessRequestMain(Boolean
> includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
>
> Below is the code for the button:
> Protected Sub btnAddInventory_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles btnAddInventory.Click
> HideAll()
> btnAddInventory.Visible = False
> Select Case UCase(ddlMainType.SelectedItem.Value)
> Case "MONITOR"
> dvInventory_Monitor.Visible = True
> dvInventory_Monitor.ChangeMode(DetailsViewMode.Ins ert)
> Case "COMPUTER"
> dvInventory_Computer.Visible = True
> dvInventory_Computer.ChangeMode(DetailsViewMode.In sert)
> GetDefaultValue("dvInventory_Computer")
> ....
> Below is the the code for GetDefaultValue :
> Private Sub GetDefaultValue(ByVal objMainType As String)
> Select Case (objMainType)
> Case "dvInventory_Computer"
> CType(dvInventory_Computer.FindControl("txtMainType"),
> TextBox).Text = ddlMainType.SelectedValue.ToString
> CType(dvInventory_Computer.FindControl("ddlSubType"),
> DropDownList).SelectedValue = ddlSubType.SelectedValue.ToString
> CType(dvInventory_Computer.FindControl("txtUnitPrice"),
> TextBox).Text = "0.00"
> CType(dvInventory_Computer.FindControl("txtQuantity"),
> TextBox).Text = "1"
> CType(dvInventory_Computer.FindControl("ddlRAMType"),
> DropDownList).SelectedValue = "NONE"
> CType(dvInventory_Computer.FindControl("ddlNICManufacturer"),
> DropDownList).SelectedValue = "NONE"
> CType(dvInventory_Computer.FindControl("ddlOpticalDrive"),
> DropDownList).SelectedValue = "NONE"
> CType(dvInventory_Computer.FindControl("txtHDDSpace"),
> TextBox).Text = Nothing
> CType(dvInventory_Computer.FindControl("ddlGCManufacturer"),
> DropDownList).SelectedValue = "NONE"
> CType(dvInventory_Computer.FindControl("ddlModemManufacturer"),
> DropDownList).SelectedValue = "NONE"
> ...
> Please advise
> Regards,
> SB
Private Sub ShowError(ByVal strMainType As String, ByVal strField As
String)
Select Case UCase(strMainType)
Case "COMPUTER"
If strField = "Manufacturer" Then

CType(dvInventory_Computer.FindControl("lblManufacturer_ErrMsg"),
Label).Visible = True
ElseIf strField = "Model" Then

CType(dvInventory_Computer.FindControl("lblModel_ErrMsg"), Label).Visible =
True
ElseIf strField = "SubType" Then

CType(dvInventory_Computer.FindControl("lblSubType_ErrMsg"), Label).Visible =
True
Else
CType(dvInventory_Computer.FindControl("lblKey_ErrMsg"),
Label).Visible = True
End If
dvInventory_Computer.Visible = True

Case "NIC"
If strField = "Manufacturer" Then

CType(dvInventory_NIC.FindControl("lblManufacturer_ErrMsg"), Label).Visible =
True
ElseIf strField = "Model" Then
CType(dvInventory_NIC.FindControl("lblModel_ErrMsg"),
Label).Visible = True
ElseIf strField = "SubType" Then
CType(dvInventory_NIC.FindControl("lblSubType_ErrMsg"),
Label).Visible = True
Else
CType(dvInventory_NIC.FindControl("lblKey_ErrMsg"),
Label).Visible = True
End If
dvInventory_NIC.Visible = True

Case "OPTICALDRIVE"
If strField = "Manufacturer" Then

CType(dvInventory_ExtOD.FindControl("lblManufacturer_ErrMsg"), Label).Visible
= True
ElseIf strField = "Model" Then
CType(dvInventory_ExtOD.FindControl("lblModel_ErrMsg"),
Label).Visible = True
ElseIf strField = "SubType" Then

CType(dvInventory_ExtOD.FindControl("lblSubType_ErrMsg"), Label).Visible =
True
Else
CType(dvInventory_ExtOD.FindControl("lblKey_ErrMsg"),
Label).Visible = True
End If
dvInventory_ExtOD.Visible = True

Case "MONITOR"
If strField = "Manufacturer" Then

CType(dvInventory_Monitor.FindControl("lblManufacturer_ErrMsg"),
Label).Visible = True
ElseIf strField = "Model" Then

CType(dvInventory_Monitor.FindControl("lblModel_ErrMsg"), Label).Visible =
True
ElseIf strField = "SubType" Then

CType(dvInventory_Monitor.FindControl("lblSubType_ErrMsg"), Label).Visible =
True
Else
CType(dvInventory_Monitor.FindControl("lblKey_ErrMsg"),
Label).Visible = True
End If
dvInventory_Monitor.Visible = True

Case "PRINTER/SCANNER"
If strField = "Manufacturer" Then

CType(dvInventory_PrinterScanner.FindControl("lblManufacturer_ErrMsg"),
Label).Visible = True
ElseIf strField = "Model" Then

CType(dvInventory_PrinterScanner.FindControl("lblModel_ErrMsg"),
Label).Visible = True
ElseIf strField = "SubType" Then

CType(dvInventory_PrinterScanner.FindControl("lblSubType_ErrMsg"),
Label).Visible = True
Else

CType(dvInventory_PrinterScanner.FindControl("lblKey_ErrMsg"), Label).Visible
= True
End If
dvInventory_PrinterScanner.Visible = True

Case "UPS"
If strField = "Manufacturer" Then

CType(dvInventory_UPS.FindControl("lblManufacturer_ErrMsg"), Label).Visible =
True
ElseIf strField = "Model" Then
CType(dvInventory_UPS.FindControl("lblModel_ErrMsg"),
Label).Visible = True
ElseIf strField = "SubType" Then
CType(dvInventory_UPS.FindControl("lblSubType_ErrMsg"),
Label).Visible = True
Else
CType(dvInventory_UPS.FindControl("lblKey_ErrMsg"),
Label).Visible = True
End If
dvInventory_UPS.Visible = True

Case "SOFTWARE"
If strField = "Manufacturer" Then

CType(dvInventory_Software.FindControl("lblManufacturer_ErrMsg"),
Label).Visible = True
ElseIf strField = "Model" Then

CType(dvInventory_Software.FindControl("lblModel_ErrMsg"), Label).Visible =
True
ElseIf strField = "SubType" Then

CType(dvInventory_Software.FindControl("lblSubType_ErrMsg"), Label).Visible =
True
Else
CType(dvInventory_Software.FindControl("lblKey_ErrMsg"),
Label).Visible = True
End If
dvInventory_Software.Visible = True

Case "NETWORKING"
If strField = "Manufacturer" Then

CType(dvInventory_Networking.FindControl("lblManufacturer_ErrMsg"),
Label).Visible = True
ElseIf strField = "Model" Then

CType(dvInventory_Networking.FindControl("lblModel_ErrMsg"), Label).Visible =
True
ElseIf strField = "SubType" Then

CType(dvInventory_Networking.FindControl("lblSubType_ErrMsg"), Label).Visible
= True
Else

CType(dvInventory_Networking.FindControl("lblKey_ErrMsg"), Label).Visible =
True
End If
dvInventory_Networking.Visible = True

Case "MODEM"
If strField = "Manufacturer" Then

CType(dvInventory_Modem.FindControl("lblManufacturer_ErrMsg"), Label).Visible
= True
ElseIf strField = "Model" Then
CType(dvInventory_Modem.FindControl("lblModel_ErrMsg"),
Label).Visible = True
ElseIf strField = "SubType" Then

CType(dvInventory_Modem.FindControl("lblSubType_ErrMsg"), Label).Visible =
True
Else
CType(dvInventory_Modem.FindControl("lblKey_ErrMsg"),
Label).Visible = True
End If
dvInventory_Modem.Visible = True

Case "ACCESSORIES"
If strField = "Manufacturer" Then

CType(dvInventory_Accessories.FindControl("lblManufacturer_ErrMsg"),
Label).Visible = True
ElseIf strField = "Model" Then

CType(dvInventory_Accessories.FindControl("lblModel_ErrMsg"), Label).Visible
= True
ElseIf strField = "SubType" Then

CType(dvInventory_Accessories.FindControl("lblSubType_ErrMsg"),
Label).Visible = True
Else

CType(dvInventory_Accessories.FindControl("lblKey_ErrMsg"), Label).Visible =
True
End If
dvInventory_Accessories.Visible = True

Case "STORAGE"
If strField = "Manufacturer" Then

CType(dvInventory_Storage.FindControl("lblManufacturer_ErrMsg"),
Label).Visible = True
ElseIf strField = "Model" Then

CType(dvInventory_Storage.FindControl("lblModel_ErrMsg"), Label).Visible =
True
ElseIf strField = "SubType" Then

CType(dvInventory_Storage.FindControl("lblSubType_ErrMsg"), Label).Visible =
True
Else
CType(dvInventory_Storage.FindControl("lblKey_ErrMsg"),
Label).Visible = True
End If
dvInventory_Storage.Visible = True

Case "OTHERS"
If strField = "Manufacturer" Then

CType(dvInventory_Others.FindControl("lblManufacturer_ErrMsg"),
Label).Visible = True
ElseIf strField = "Model" Then
CType(dvInventory_Others.FindControl("lblModel_ErrMsg"),
Label).Visible = True
ElseIf strField = "SubType" Then

CType(dvInventory_Others.FindControl("lblSubType_ErrMsg"), Label).Visible =
True
Else
CType(dvInventory_Others.FindControl("lblKey_ErrMsg"),
Label).Visible = True
End If
Line 842: dvInventory_Others.Visible = True

End Select
End Sub

"Kevin Spencer" wrote:

> Which one is "line 842"?
> --
> HTH,
> Kevin Spencer
> Microsoft MVP
> Professional Numbskull
> Hard work is a medication for which
> there is no placebo.
> "Seok Bee" <seokbee@.yahoo.com> wrote in message
> news:FC2C952C-DAB3-4C99-9E9C-6C25578CD4C2@.microsoft.com...
> > Hi All,
> > I have a webform with a button to add record into the database. When the
> > button is being clicked, the program will assign initial value controls in
> > a
> > detailsview control. When the first time, the button being click, the
> > program
> > works as expected. However, the next click on the button, the program
> > showed
> > the following error message:
> > System.NullReferenceException was unhandled by user code
> > Message="Object reference not set to an instance of an object."
> > Source="App_Web_xogepfrv"
> > StackTrace:
> > at Inv_Maint.GetDefaultValue(String objMainType) in
> > C:\Data\OITRS\Inv_Upd.aspx.vb:line 842
> > at Inv_Maint.btnAddInventory_Click(Object sender, EventArgs e) in
> > C:\Data\OITRS\Inv_Upd.aspx.vb:line 1132
> > at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
> > at System.Web.UI.WebControls.Button.RaisePostBackEven t(String
> > eventArgument)
> > at
> > System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
> > eventArgument)
> > at System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
> > sourceControl, String eventArgument)
> > at System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection
> > postData)
> > at System.Web.UI.Page.ProcessRequestMain(Boolean
> > includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
> > Below is the code for the button:
> > Protected Sub btnAddInventory_Click(ByVal sender As Object, ByVal e As
> > System.EventArgs) Handles btnAddInventory.Click
> > HideAll()
> > btnAddInventory.Visible = False
> > Select Case UCase(ddlMainType.SelectedItem.Value)
> > Case "MONITOR"
> > dvInventory_Monitor.Visible = True
> > dvInventory_Monitor.ChangeMode(DetailsViewMode.Ins ert)
> > Case "COMPUTER"
> > dvInventory_Computer.Visible = True
> > dvInventory_Computer.ChangeMode(DetailsViewMode.In sert)
> > GetDefaultValue("dvInventory_Computer")
> > ....
> > Below is the the code for GetDefaultValue :
> > Private Sub GetDefaultValue(ByVal objMainType As String)
> > Select Case (objMainType)
> > Case "dvInventory_Computer"
> > CType(dvInventory_Computer.FindControl("txtMainType"),
> > TextBox).Text = ddlMainType.SelectedValue.ToString
> > CType(dvInventory_Computer.FindControl("ddlSubType"),
> > DropDownList).SelectedValue = ddlSubType.SelectedValue.ToString
> > CType(dvInventory_Computer.FindControl("txtUnitPrice"),
> > TextBox).Text = "0.00"
> > CType(dvInventory_Computer.FindControl("txtQuantity"),
> > TextBox).Text = "1"
> > CType(dvInventory_Computer.FindControl("ddlRAMType"),
> > DropDownList).SelectedValue = "NONE"
> > CType(dvInventory_Computer.FindControl("ddlNICManufacturer"),
> > DropDownList).SelectedValue = "NONE"
> > CType(dvInventory_Computer.FindControl("ddlOpticalDrive"),
> > DropDownList).SelectedValue = "NONE"
> > CType(dvInventory_Computer.FindControl("txtHDDSpace"),
> > TextBox).Text = Nothing
> > CType(dvInventory_Computer.FindControl("ddlGCManufacturer"),
> > DropDownList).SelectedValue = "NONE"
> > CType(dvInventory_Computer.FindControl("ddlModemManufacturer"),
> > DropDownList).SelectedValue = "NONE"
> > ...
> > Please advise
> > Regards,
> > SB
>
Interesting. So, you're telling me that *all* of this is "line 842"?

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"Seok Bee" <seokbee@.yahoo.com> wrote in message
news:C061723B-3DC1-42EA-A392-B88E8B3F092C@.microsoft.com...
> Private Sub ShowError(ByVal strMainType As String, ByVal strField As
> String)
> Select Case UCase(strMainType)
> Case "COMPUTER"
> If strField = "Manufacturer" Then
> CType(dvInventory_Computer.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "Model" Then
> CType(dvInventory_Computer.FindControl("lblModel_ErrMsg"), Label).Visible
> =
> True
> ElseIf strField = "SubType" Then
> CType(dvInventory_Computer.FindControl("lblSubType_ErrMsg"),
> Label).Visible =
> True
> Else
> CType(dvInventory_Computer.FindControl("lblKey_ErrMsg"),
> Label).Visible = True
> End If
> dvInventory_Computer.Visible = True
> Case "NIC"
> If strField = "Manufacturer" Then
> CType(dvInventory_NIC.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible =
> True
> ElseIf strField = "Model" Then
> CType(dvInventory_NIC.FindControl("lblModel_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "SubType" Then
> CType(dvInventory_NIC.FindControl("lblSubType_ErrMsg"),
> Label).Visible = True
> Else
> CType(dvInventory_NIC.FindControl("lblKey_ErrMsg"),
> Label).Visible = True
> End If
> dvInventory_NIC.Visible = True
> Case "OPTICALDRIVE"
> If strField = "Manufacturer" Then
> CType(dvInventory_ExtOD.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible
> = True
> ElseIf strField = "Model" Then
> CType(dvInventory_ExtOD.FindControl("lblModel_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "SubType" Then
> CType(dvInventory_ExtOD.FindControl("lblSubType_ErrMsg"), Label).Visible =
> True
> Else
> CType(dvInventory_ExtOD.FindControl("lblKey_ErrMsg"),
> Label).Visible = True
> End If
> dvInventory_ExtOD.Visible = True
> Case "MONITOR"
> If strField = "Manufacturer" Then
> CType(dvInventory_Monitor.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "Model" Then
> CType(dvInventory_Monitor.FindControl("lblModel_ErrMsg"), Label).Visible =
> True
> ElseIf strField = "SubType" Then
> CType(dvInventory_Monitor.FindControl("lblSubType_ErrMsg"), Label).Visible
> =
> True
> Else
> CType(dvInventory_Monitor.FindControl("lblKey_ErrMsg"),
> Label).Visible = True
> End If
> dvInventory_Monitor.Visible = True
> Case "PRINTER/SCANNER"
> If strField = "Manufacturer" Then
> CType(dvInventory_PrinterScanner.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "Model" Then
> CType(dvInventory_PrinterScanner.FindControl("lblModel_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "SubType" Then
> CType(dvInventory_PrinterScanner.FindControl("lblSubType_ErrMsg"),
> Label).Visible = True
> Else
> CType(dvInventory_PrinterScanner.FindControl("lblKey_ErrMsg"),
> Label).Visible
> = True
> End If
> dvInventory_PrinterScanner.Visible = True
> Case "UPS"
> If strField = "Manufacturer" Then
> CType(dvInventory_UPS.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible =
> True
> ElseIf strField = "Model" Then
> CType(dvInventory_UPS.FindControl("lblModel_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "SubType" Then
> CType(dvInventory_UPS.FindControl("lblSubType_ErrMsg"),
> Label).Visible = True
> Else
> CType(dvInventory_UPS.FindControl("lblKey_ErrMsg"),
> Label).Visible = True
> End If
> dvInventory_UPS.Visible = True
> Case "SOFTWARE"
> If strField = "Manufacturer" Then
> CType(dvInventory_Software.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "Model" Then
> CType(dvInventory_Software.FindControl("lblModel_ErrMsg"), Label).Visible
> =
> True
> ElseIf strField = "SubType" Then
> CType(dvInventory_Software.FindControl("lblSubType_ErrMsg"),
> Label).Visible =
> True
> Else
> CType(dvInventory_Software.FindControl("lblKey_ErrMsg"),
> Label).Visible = True
> End If
> dvInventory_Software.Visible = True
> Case "NETWORKING"
> If strField = "Manufacturer" Then
> CType(dvInventory_Networking.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "Model" Then
> CType(dvInventory_Networking.FindControl("lblModel_ErrMsg"),
> Label).Visible =
> True
> ElseIf strField = "SubType" Then
> CType(dvInventory_Networking.FindControl("lblSubType_ErrMsg"),
> Label).Visible
> = True
> Else
> CType(dvInventory_Networking.FindControl("lblKey_ErrMsg"), Label).Visible
> =
> True
> End If
> dvInventory_Networking.Visible = True
> Case "MODEM"
> If strField = "Manufacturer" Then
> CType(dvInventory_Modem.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible
> = True
> ElseIf strField = "Model" Then
> CType(dvInventory_Modem.FindControl("lblModel_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "SubType" Then
> CType(dvInventory_Modem.FindControl("lblSubType_ErrMsg"), Label).Visible =
> True
> Else
> CType(dvInventory_Modem.FindControl("lblKey_ErrMsg"),
> Label).Visible = True
> End If
> dvInventory_Modem.Visible = True
> Case "ACCESSORIES"
> If strField = "Manufacturer" Then
> CType(dvInventory_Accessories.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "Model" Then
> CType(dvInventory_Accessories.FindControl("lblModel_ErrMsg"),
> Label).Visible
> = True
> ElseIf strField = "SubType" Then
> CType(dvInventory_Accessories.FindControl("lblSubType_ErrMsg"),
> Label).Visible = True
> Else
> CType(dvInventory_Accessories.FindControl("lblKey_ErrMsg"), Label).Visible
> =
> True
> End If
> dvInventory_Accessories.Visible = True
> Case "STORAGE"
> If strField = "Manufacturer" Then
> CType(dvInventory_Storage.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "Model" Then
> CType(dvInventory_Storage.FindControl("lblModel_ErrMsg"), Label).Visible =
> True
> ElseIf strField = "SubType" Then
> CType(dvInventory_Storage.FindControl("lblSubType_ErrMsg"), Label).Visible
> =
> True
> Else
> CType(dvInventory_Storage.FindControl("lblKey_ErrMsg"),
> Label).Visible = True
> End If
> dvInventory_Storage.Visible = True
> Case "OTHERS"
> If strField = "Manufacturer" Then
> CType(dvInventory_Others.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "Model" Then
> CType(dvInventory_Others.FindControl("lblModel_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "SubType" Then
> CType(dvInventory_Others.FindControl("lblSubType_ErrMsg"), Label).Visible
> =
> True
> Else
> CType(dvInventory_Others.FindControl("lblKey_ErrMsg"),
> Label).Visible = True
> End If
> Line 842: dvInventory_Others.Visible = True
> End Select
> End Sub
>
> "Kevin Spencer" wrote:
>> Which one is "line 842"?
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> Professional Numbskull
>>
>> Hard work is a medication for which
>> there is no placebo.
>>
>> "Seok Bee" <seokbee@.yahoo.com> wrote in message
>> news:FC2C952C-DAB3-4C99-9E9C-6C25578CD4C2@.microsoft.com...
>> > Hi All,
>>> > I have a webform with a button to add record into the database. When
>> > the
>> > button is being clicked, the program will assign initial value controls
>> > in
>> > a
>> > detailsview control. When the first time, the button being click, the
>> > program
>> > works as expected. However, the next click on the button, the program
>> > showed
>> > the following error message:
>>> > System.NullReferenceException was unhandled by user code
>> > Message="Object reference not set to an instance of an object."
>> > Source="App_Web_xogepfrv"
>> > StackTrace:
>> > at Inv_Maint.GetDefaultValue(String objMainType) in
>> > C:\Data\OITRS\Inv_Upd.aspx.vb:line 842
>> > at Inv_Maint.btnAddInventory_Click(Object sender, EventArgs e) in
>> > C:\Data\OITRS\Inv_Upd.aspx.vb:line 1132
>> > at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
>> > at System.Web.UI.WebControls.Button.RaisePostBackEven t(String
>> > eventArgument)
>> > at
>> > System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
>> > eventArgument)
>> > at System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
>> > sourceControl, String eventArgument)
>> > at System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection
>> > postData)
>> > at System.Web.UI.Page.ProcessRequestMain(Boolean
>> > includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
>>>> > Below is the code for the button:
>>> > Protected Sub btnAddInventory_Click(ByVal sender As Object, ByVal e
>> > As
>> > System.EventArgs) Handles btnAddInventory.Click
>>> > HideAll()
>> > btnAddInventory.Visible = False
>> > Select Case UCase(ddlMainType.SelectedItem.Value)
>> > Case "MONITOR"
>> > dvInventory_Monitor.Visible = True
>> > dvInventory_Monitor.ChangeMode(DetailsViewMode.Ins ert)
>>> > Case "COMPUTER"
>> > dvInventory_Computer.Visible = True
>> > dvInventory_Computer.ChangeMode(DetailsViewMode.In sert)
>> > GetDefaultValue("dvInventory_Computer")
>>> > ....
>>> > Below is the the code for GetDefaultValue :
>> > Private Sub GetDefaultValue(ByVal objMainType As String)
>> > Select Case (objMainType)
>> > Case "dvInventory_Computer"
>> > CType(dvInventory_Computer.FindControl("txtMainType"),
>> > TextBox).Text = ddlMainType.SelectedValue.ToString
>> > CType(dvInventory_Computer.FindControl("ddlSubType"),
>> > DropDownList).SelectedValue = ddlSubType.SelectedValue.ToString
>> > CType(dvInventory_Computer.FindControl("txtUnitPrice"),
>> > TextBox).Text = "0.00"
>> > CType(dvInventory_Computer.FindControl("txtQuantity"),
>> > TextBox).Text = "1"
>> > CType(dvInventory_Computer.FindControl("ddlRAMType"),
>> > DropDownList).SelectedValue = "NONE"
>>> > CType(dvInventory_Computer.FindControl("ddlNICManufacturer"),
>> > DropDownList).SelectedValue = "NONE"
>>> > CType(dvInventory_Computer.FindControl("ddlOpticalDrive"),
>> > DropDownList).SelectedValue = "NONE"
>> > CType(dvInventory_Computer.FindControl("txtHDDSpace"),
>> > TextBox).Text = Nothing
>>> > CType(dvInventory_Computer.FindControl("ddlGCManufacturer"),
>> > DropDownList).SelectedValue = "NONE"
>>> > CType(dvInventory_Computer.FindControl("ddlModemManufacturer"),
>> > DropDownList).SelectedValue = "NONE"
>>> > ...
>> > Please advise
>>> > Regards,
>> > SB
>>
>>
>
No, he actually marked the line with "Line 842:". I just saw it by
chance. It's the third line from the end in the large chunk of code.

Kevin Spencer wrote:
> Interesting. So, you're telling me that *all* of this is "line 842"?
Okay. That line reads:

dvInventory_Others.Visible = True

Apparently, dvInventory_Others is null (Nothing).

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> wrote in message
news:ODcvfcEdGHA.3888@.TK2MSFTNGP02.phx.gbl...
> Interesting. So, you're telling me that *all* of this is "line 842"?
> --
> HTH,
> Kevin Spencer
> Microsoft MVP
> Professional Numbskull
> Hard work is a medication for which
> there is no placebo.
> "Seok Bee" <seokbee@.yahoo.com> wrote in message
> news:C061723B-3DC1-42EA-A392-B88E8B3F092C@.microsoft.com...
>> Private Sub ShowError(ByVal strMainType As String, ByVal strField As
>> String)
>> Select Case UCase(strMainType)
>> Case "COMPUTER"
>> If strField = "Manufacturer" Then
>>
>> CType(dvInventory_Computer.FindControl("lblManufacturer_ErrMsg"),
>> Label).Visible = True
>> ElseIf strField = "Model" Then
>>
>> CType(dvInventory_Computer.FindControl("lblModel_ErrMsg"), Label).Visible
>> =
>> True
>> ElseIf strField = "SubType" Then
>>
>> CType(dvInventory_Computer.FindControl("lblSubType_ErrMsg"),
>> Label).Visible =
>> True
>> Else
>>
>> CType(dvInventory_Computer.FindControl("lblKey_ErrMsg"),
>> Label).Visible = True
>> End If
>> dvInventory_Computer.Visible = True
>>
>> Case "NIC"
>> If strField = "Manufacturer" Then
>>
>> CType(dvInventory_NIC.FindControl("lblManufacturer_ErrMsg"),
>> Label).Visible =
>> True
>> ElseIf strField = "Model" Then
>> CType(dvInventory_NIC.FindControl("lblModel_ErrMsg"),
>> Label).Visible = True
>> ElseIf strField = "SubType" Then
>>
>> CType(dvInventory_NIC.FindControl("lblSubType_ErrMsg"),
>> Label).Visible = True
>> Else
>> CType(dvInventory_NIC.FindControl("lblKey_ErrMsg"),
>> Label).Visible = True
>> End If
>> dvInventory_NIC.Visible = True
>>
>> Case "OPTICALDRIVE"
>> If strField = "Manufacturer" Then
>>
>> CType(dvInventory_ExtOD.FindControl("lblManufacturer_ErrMsg"),
>> Label).Visible
>> = True
>> ElseIf strField = "Model" Then
>>
>> CType(dvInventory_ExtOD.FindControl("lblModel_ErrMsg"),
>> Label).Visible = True
>> ElseIf strField = "SubType" Then
>>
>> CType(dvInventory_ExtOD.FindControl("lblSubType_ErrMsg"), Label).Visible
>> =
>> True
>> Else
>> CType(dvInventory_ExtOD.FindControl("lblKey_ErrMsg"),
>> Label).Visible = True
>> End If
>> dvInventory_ExtOD.Visible = True
>>
>> Case "MONITOR"
>> If strField = "Manufacturer" Then
>>
>> CType(dvInventory_Monitor.FindControl("lblManufacturer_ErrMsg"),
>> Label).Visible = True
>> ElseIf strField = "Model" Then
>>
>> CType(dvInventory_Monitor.FindControl("lblModel_ErrMsg"), Label).Visible
>> =
>> True
>> ElseIf strField = "SubType" Then
>>
>> CType(dvInventory_Monitor.FindControl("lblSubType_ErrMsg"),
>> Label).Visible =
>> True
>> Else
>>
>> CType(dvInventory_Monitor.FindControl("lblKey_ErrMsg"),
>> Label).Visible = True
>> End If
>> dvInventory_Monitor.Visible = True
>>
>> Case "PRINTER/SCANNER"
>> If strField = "Manufacturer" Then
>>
>> CType(dvInventory_PrinterScanner.FindControl("lblManufacturer_ErrMsg"),
>> Label).Visible = True
>> ElseIf strField = "Model" Then
>>
>> CType(dvInventory_PrinterScanner.FindControl("lblModel_ErrMsg"),
>> Label).Visible = True
>> ElseIf strField = "SubType" Then
>>
>> CType(dvInventory_PrinterScanner.FindControl("lblSubType_ErrMsg"),
>> Label).Visible = True
>> Else
>>
>> CType(dvInventory_PrinterScanner.FindControl("lblKey_ErrMsg"),
>> Label).Visible
>> = True
>> End If
>> dvInventory_PrinterScanner.Visible = True
>>
>> Case "UPS"
>> If strField = "Manufacturer" Then
>>
>> CType(dvInventory_UPS.FindControl("lblManufacturer_ErrMsg"),
>> Label).Visible =
>> True
>> ElseIf strField = "Model" Then
>> CType(dvInventory_UPS.FindControl("lblModel_ErrMsg"),
>> Label).Visible = True
>> ElseIf strField = "SubType" Then
>>
>> CType(dvInventory_UPS.FindControl("lblSubType_ErrMsg"),
>> Label).Visible = True
>> Else
>> CType(dvInventory_UPS.FindControl("lblKey_ErrMsg"),
>> Label).Visible = True
>> End If
>> dvInventory_UPS.Visible = True
>>
>> Case "SOFTWARE"
>> If strField = "Manufacturer" Then
>>
>> CType(dvInventory_Software.FindControl("lblManufacturer_ErrMsg"),
>> Label).Visible = True
>> ElseIf strField = "Model" Then
>>
>> CType(dvInventory_Software.FindControl("lblModel_ErrMsg"), Label).Visible
>> =
>> True
>> ElseIf strField = "SubType" Then
>>
>> CType(dvInventory_Software.FindControl("lblSubType_ErrMsg"),
>> Label).Visible =
>> True
>> Else
>>
>> CType(dvInventory_Software.FindControl("lblKey_ErrMsg"),
>> Label).Visible = True
>> End If
>> dvInventory_Software.Visible = True
>>
>> Case "NETWORKING"
>> If strField = "Manufacturer" Then
>>
>> CType(dvInventory_Networking.FindControl("lblManufacturer_ErrMsg"),
>> Label).Visible = True
>> ElseIf strField = "Model" Then
>>
>> CType(dvInventory_Networking.FindControl("lblModel_ErrMsg"),
>> Label).Visible =
>> True
>> ElseIf strField = "SubType" Then
>>
>> CType(dvInventory_Networking.FindControl("lblSubType_ErrMsg"),
>> Label).Visible
>> = True
>> Else
>>
>> CType(dvInventory_Networking.FindControl("lblKey_ErrMsg"), Label).Visible
>> =
>> True
>> End If
>> dvInventory_Networking.Visible = True
>>
>> Case "MODEM"
>> If strField = "Manufacturer" Then
>>
>> CType(dvInventory_Modem.FindControl("lblManufacturer_ErrMsg"),
>> Label).Visible
>> = True
>> ElseIf strField = "Model" Then
>>
>> CType(dvInventory_Modem.FindControl("lblModel_ErrMsg"),
>> Label).Visible = True
>> ElseIf strField = "SubType" Then
>>
>> CType(dvInventory_Modem.FindControl("lblSubType_ErrMsg"), Label).Visible
>> =
>> True
>> Else
>> CType(dvInventory_Modem.FindControl("lblKey_ErrMsg"),
>> Label).Visible = True
>> End If
>> dvInventory_Modem.Visible = True
>>
>> Case "ACCESSORIES"
>> If strField = "Manufacturer" Then
>>
>> CType(dvInventory_Accessories.FindControl("lblManufacturer_ErrMsg"),
>> Label).Visible = True
>> ElseIf strField = "Model" Then
>>
>> CType(dvInventory_Accessories.FindControl("lblModel_ErrMsg"),
>> Label).Visible
>> = True
>> ElseIf strField = "SubType" Then
>>
>> CType(dvInventory_Accessories.FindControl("lblSubType_ErrMsg"),
>> Label).Visible = True
>> Else
>>
>> CType(dvInventory_Accessories.FindControl("lblKey_ErrMsg"),
>> Label).Visible =
>> True
>> End If
>> dvInventory_Accessories.Visible = True
>>
>> Case "STORAGE"
>> If strField = "Manufacturer" Then
>>
>> CType(dvInventory_Storage.FindControl("lblManufacturer_ErrMsg"),
>> Label).Visible = True
>> ElseIf strField = "Model" Then
>>
>> CType(dvInventory_Storage.FindControl("lblModel_ErrMsg"), Label).Visible
>> =
>> True
>> ElseIf strField = "SubType" Then
>>
>> CType(dvInventory_Storage.FindControl("lblSubType_ErrMsg"),
>> Label).Visible =
>> True
>> Else
>>
>> CType(dvInventory_Storage.FindControl("lblKey_ErrMsg"),
>> Label).Visible = True
>> End If
>> dvInventory_Storage.Visible = True
>>
>> Case "OTHERS"
>> If strField = "Manufacturer" Then
>>
>> CType(dvInventory_Others.FindControl("lblManufacturer_ErrMsg"),
>> Label).Visible = True
>> ElseIf strField = "Model" Then
>>
>> CType(dvInventory_Others.FindControl("lblModel_ErrMsg"),
>> Label).Visible = True
>> ElseIf strField = "SubType" Then
>>
>> CType(dvInventory_Others.FindControl("lblSubType_ErrMsg"), Label).Visible
>> =
>> True
>> Else
>> CType(dvInventory_Others.FindControl("lblKey_ErrMsg"),
>> Label).Visible = True
>> End If
>> Line 842: dvInventory_Others.Visible = True
>>
>> End Select
>> End Sub
>>
>>
>> "Kevin Spencer" wrote:
>>
>>> Which one is "line 842"?
>>>
>>> --
>>> HTH,
>>>
>>> Kevin Spencer
>>> Microsoft MVP
>>> Professional Numbskull
>>>
>>> Hard work is a medication for which
>>> there is no placebo.
>>>
>>> "Seok Bee" <seokbee@.yahoo.com> wrote in message
>>> news:FC2C952C-DAB3-4C99-9E9C-6C25578CD4C2@.microsoft.com...
>>> > Hi All,
>>>>> > I have a webform with a button to add record into the database. When
>>> > the
>>> > button is being clicked, the program will assign initial value
>>> > controls in
>>> > a
>>> > detailsview control. When the first time, the button being click, the
>>> > program
>>> > works as expected. However, the next click on the button, the program
>>> > showed
>>> > the following error message:
>>>>> > System.NullReferenceException was unhandled by user code
>>> > Message="Object reference not set to an instance of an object."
>>> > Source="App_Web_xogepfrv"
>>> > StackTrace:
>>> > at Inv_Maint.GetDefaultValue(String objMainType) in
>>> > C:\Data\OITRS\Inv_Upd.aspx.vb:line 842
>>> > at Inv_Maint.btnAddInventory_Click(Object sender, EventArgs e)
>>> > in
>>> > C:\Data\OITRS\Inv_Upd.aspx.vb:line 1132
>>> > at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
>>> > at System.Web.UI.WebControls.Button.RaisePostBackEven t(String
>>> > eventArgument)
>>> > at
>>> > System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
>>> > eventArgument)
>>> > at System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
>>> > sourceControl, String eventArgument)
>>> > at System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection
>>> > postData)
>>> > at System.Web.UI.Page.ProcessRequestMain(Boolean
>>> > includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
>>>>>>> > Below is the code for the button:
>>>>> > Protected Sub btnAddInventory_Click(ByVal sender As Object, ByVal e
>>> > As
>>> > System.EventArgs) Handles btnAddInventory.Click
>>>>> > HideAll()
>>> > btnAddInventory.Visible = False
>>> > Select Case UCase(ddlMainType.SelectedItem.Value)
>>> > Case "MONITOR"
>>> > dvInventory_Monitor.Visible = True
>>> > dvInventory_Monitor.ChangeMode(DetailsViewMode.Ins ert)
>>>>> > Case "COMPUTER"
>>> > dvInventory_Computer.Visible = True
>>> > dvInventory_Computer.ChangeMode(DetailsViewMode.In sert)
>>> > GetDefaultValue("dvInventory_Computer")
>>>>> > ....
>>>>> > Below is the the code for GetDefaultValue :
>>> > Private Sub GetDefaultValue(ByVal objMainType As String)
>>> > Select Case (objMainType)
>>> > Case "dvInventory_Computer"
>>> > CType(dvInventory_Computer.FindControl("txtMainType"),
>>> > TextBox).Text = ddlMainType.SelectedValue.ToString
>>> > CType(dvInventory_Computer.FindControl("ddlSubType"),
>>> > DropDownList).SelectedValue = ddlSubType.SelectedValue.ToString
>>> > CType(dvInventory_Computer.FindControl("txtUnitPrice"),
>>> > TextBox).Text = "0.00"
>>> > CType(dvInventory_Computer.FindControl("txtQuantity"),
>>> > TextBox).Text = "1"
>>> > CType(dvInventory_Computer.FindControl("ddlRAMType"),
>>> > DropDownList).SelectedValue = "NONE"
>>>>> > CType(dvInventory_Computer.FindControl("ddlNICManufacturer"),
>>> > DropDownList).SelectedValue = "NONE"
>>>>> > CType(dvInventory_Computer.FindControl("ddlOpticalDrive"),
>>> > DropDownList).SelectedValue = "NONE"
>>> > CType(dvInventory_Computer.FindControl("txtHDDSpace"),
>>> > TextBox).Text = Nothing
>>>>> > CType(dvInventory_Computer.FindControl("ddlGCManufacturer"),
>>> > DropDownList).SelectedValue = "NONE"
>>>>> > CType(dvInventory_Computer.FindControl("ddlModemManufacturer"),
>>> > DropDownList).SelectedValue = "NONE"
>>>>> > ...
>>> > Please advise
>>>>> > Regards,
>>> > SB
>>>
>>>
>>>

Friday, March 16, 2012

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

Object reference not set to an instance of an object.

Hi All,
I have a webform with a button to add record into the database. When the
button is being clicked, the program will assign initial value controls in a
detailsview control. When the first time, the button being click, the progra
m
works as expected. However, the next click on the button, the program showed
the following error message:
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_Web_xogepfrv"
StackTrace:
at Inv_Maint.GetDefaultValue(String objMainType) in
C:\Data\OITRS\Inv_Upd.aspx.vb:line 842
at Inv_Maint.btnAddInventory_Click(Object sender, EventArgs e) in
C:\Data\OITRS\Inv_Upd.aspx.vb:line 1132
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument)
at
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
stBackEvent(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)
Below is the code for the button:
Protected Sub btnAddInventory_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnAddInventory.Click
HideAll()
btnAddInventory.Visible = False
Select Case UCase(ddlMainType.SelectedItem.Value)
Case "MONITOR"
dvInventory_Monitor.Visible = True
dvInventory_Monitor.ChangeMode(DetailsViewMode.Insert)
Case "COMPUTER"
dvInventory_Computer.Visible = True
dvInventory_Computer.ChangeMode(DetailsViewMode.Insert)
GetDefaultValue("dvInventory_Computer")
...
Below is the the code for GetDefaultValue :
Private Sub GetDefaultValue(ByVal objMainType As String)
Select Case (objMainType)
Case "dvInventory_Computer"
CType(dvInventory_Computer.FindControl("txtMainType"),
TextBox).Text = ddlMainType.SelectedValue.ToString
CType(dvInventory_Computer.FindControl("ddlSubType"),
DropDownList).SelectedValue = ddlSubType.SelectedValue.ToString
CType(dvInventory_Computer.FindControl("txtUnitPrice"),
TextBox).Text = "0.00"
CType(dvInventory_Computer.FindControl("txtQuantity"),
TextBox).Text = "1"
CType(dvInventory_Computer.FindControl("ddlRAMType"),
DropDownList).SelectedValue = "NONE"
CType(dvInventory_Computer.FindControl("ddlNICManufacturer"),
DropDownList).SelectedValue = "NONE"
CType(dvInventory_Computer.FindControl("ddlOpticalDrive"),
DropDownList).SelectedValue = "NONE"
CType(dvInventory_Computer.FindControl("txtHDDSpace"),
TextBox).Text = Nothing
CType(dvInventory_Computer.FindControl("ddlGCManufacturer"),
DropDownList).SelectedValue = "NONE"
CType(dvInventory_Computer.FindControl("ddlModemManufacturer"),
DropDownList).SelectedValue = "NONE"
...
Please advise
Regards,
SBWhich one is "line 842"?
HTH,
Kevin Spencer
Microsoft MVP
Professional Numbskull
Hard work is a medication for which
there is no placebo.
"Seok Bee" <seokbee@.yahoo.com> wrote in message
news:FC2C952C-DAB3-4C99-9E9C-6C25578CD4C2@.microsoft.com...
> Hi All,
> I have a webform with a button to add record into the database. When the
> button is being clicked, the program will assign initial value controls in
> a
> detailsview control. When the first time, the button being click, the
> program
> works as expected. However, the next click on the button, the program
> showed
> the following error message:
> System.NullReferenceException was unhandled by user code
> Message="Object reference not set to an instance of an object."
> Source="App_Web_xogepfrv"
> StackTrace:
> at Inv_Maint.GetDefaultValue(String objMainType) in
> C:\Data\OITRS\Inv_Upd.aspx.vb:line 842
> at Inv_Maint.btnAddInventory_Click(Object sender, EventArgs e) in
> C:\Data\OITRS\Inv_Upd.aspx.vb:line 1132
> at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
> at System.Web.UI.WebControls.Button.RaisePostBackEvent(String
> eventArgument)
> at
> System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.Raise
PostBackEvent(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)
>
> Below is the code for the button:
> Protected Sub btnAddInventory_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles btnAddInventory.Click
> HideAll()
> btnAddInventory.Visible = False
> Select Case UCase(ddlMainType.SelectedItem.Value)
> Case "MONITOR"
> dvInventory_Monitor.Visible = True
> dvInventory_Monitor.ChangeMode(DetailsViewMode.Insert)
> Case "COMPUTER"
> dvInventory_Computer.Visible = True
> dvInventory_Computer.ChangeMode(DetailsViewMode.Insert)
> GetDefaultValue("dvInventory_Computer")
> ....
> Below is the the code for GetDefaultValue :
> Private Sub GetDefaultValue(ByVal objMainType As String)
> Select Case (objMainType)
> Case "dvInventory_Computer"
> CType(dvInventory_Computer.FindControl("txtMainType"),
> TextBox).Text = ddlMainType.SelectedValue.ToString
> CType(dvInventory_Computer.FindControl("ddlSubType"),
> DropDownList).SelectedValue = ddlSubType.SelectedValue.ToString
> CType(dvInventory_Computer.FindControl("txtUnitPrice"),
> TextBox).Text = "0.00"
> CType(dvInventory_Computer.FindControl("txtQuantity"),
> TextBox).Text = "1"
> CType(dvInventory_Computer.FindControl("ddlRAMType"),
> DropDownList).SelectedValue = "NONE"
> CType(dvInventory_Computer.FindControl("ddlNICManufacturer"),
> DropDownList).SelectedValue = "NONE"
> CType(dvInventory_Computer.FindControl("ddlOpticalDrive"),
> DropDownList).SelectedValue = "NONE"
> CType(dvInventory_Computer.FindControl("txtHDDSpace"),
> TextBox).Text = Nothing
> CType(dvInventory_Computer.FindControl("ddlGCManufacturer"),
> DropDownList).SelectedValue = "NONE"
> CType(dvInventory_Computer.FindControl("ddlModemManufacturer"),
> DropDownList).SelectedValue = "NONE"
> ...
> Please advise
> Regards,
> SB
Private Sub ShowError(ByVal strMainType As String, ByVal strField As
String)
Select Case UCase(strMainType)
Case "COMPUTER"
If strField = "Manufacturer" Then
CType(dvInventory_Computer.FindControl("lblManufacturer_ErrMsg"),
Label).Visible = True
ElseIf strField = "Model" Then
CType(dvInventory_Computer.FindControl("lblModel_ErrMsg"), Label).Visible =
True
ElseIf strField = "SubType" Then
CType(dvInventory_Computer.FindControl("lblSubType_ErrMsg"), Label).Visible
=
True
Else
CType(dvInventory_Computer.FindControl("lblKey_ErrMsg"),
Label).Visible = True
End If
dvInventory_Computer.Visible = True
Case "NIC"
If strField = "Manufacturer" Then
CType(dvInventory_NIC.FindControl("lblManufacturer_ErrMsg"), Label).Visible
=
True
ElseIf strField = "Model" Then
CType(dvInventory_NIC.FindControl("lblModel_ErrMsg"),
Label).Visible = True
ElseIf strField = "SubType" Then
CType(dvInventory_NIC.FindControl("lblSubType_ErrMsg"),
Label).Visible = True
Else
CType(dvInventory_NIC.FindControl("lblKey_ErrMsg"),
Label).Visible = True
End If
dvInventory_NIC.Visible = True
Case "OPTICALDRIVE"
If strField = "Manufacturer" Then
CType(dvInventory_ExtOD.FindControl("lblManufacturer_ErrMsg"), Label).Visibl
e
= True
ElseIf strField = "Model" Then
CType(dvInventory_ExtOD.FindControl("lblModel_ErrMsg"),
Label).Visible = True
ElseIf strField = "SubType" Then
CType(dvInventory_ExtOD.FindControl("lblSubType_ErrMsg"), Label).Visible =
True
Else
CType(dvInventory_ExtOD.FindControl("lblKey_ErrMsg"),
Label).Visible = True
End If
dvInventory_ExtOD.Visible = True
Case "MONITOR"
If strField = "Manufacturer" Then
CType(dvInventory_Monitor.FindControl("lblManufacturer_ErrMsg"),
Label).Visible = True
ElseIf strField = "Model" Then
CType(dvInventory_Monitor.FindControl("lblModel_ErrMsg"), Label).Visible =
True
ElseIf strField = "SubType" Then
CType(dvInventory_Monitor.FindControl("lblSubType_ErrMsg"), Label).Visible =
True
Else
CType(dvInventory_Monitor.FindControl("lblKey_ErrMsg"),
Label).Visible = True
End If
dvInventory_Monitor.Visible = True
Case "PRINTER/SCANNER"
If strField = "Manufacturer" Then
CType(dvInventory_PrinterScanner.FindControl("lblManufacturer_ErrMsg"),
Label).Visible = True
ElseIf strField = "Model" Then
CType(dvInventory_PrinterScanner.FindControl("lblModel_ErrMsg"),
Label).Visible = True
ElseIf strField = "SubType" Then
CType(dvInventory_PrinterScanner.FindControl("lblSubType_ErrMsg"),
Label).Visible = True
Else
CType(dvInventory_PrinterScanner.FindControl("lblKey_ErrMsg"), Label).Visibl
e
= True
End If
dvInventory_PrinterScanner.Visible = True
Case "UPS"
If strField = "Manufacturer" Then
CType(dvInventory_UPS.FindControl("lblManufacturer_ErrMsg"), Label).Visible
=
True
ElseIf strField = "Model" Then
CType(dvInventory_UPS.FindControl("lblModel_ErrMsg"),
Label).Visible = True
ElseIf strField = "SubType" Then
CType(dvInventory_UPS.FindControl("lblSubType_ErrMsg"),
Label).Visible = True
Else
CType(dvInventory_UPS.FindControl("lblKey_ErrMsg"),
Label).Visible = True
End If
dvInventory_UPS.Visible = True
Case "SOFTWARE"
If strField = "Manufacturer" Then
CType(dvInventory_Software.FindControl("lblManufacturer_ErrMsg"),
Label).Visible = True
ElseIf strField = "Model" Then
CType(dvInventory_Software.FindControl("lblModel_ErrMsg"), Label).Visible =
True
ElseIf strField = "SubType" Then
CType(dvInventory_Software.FindControl("lblSubType_ErrMsg"), Label).Visible
=
True
Else
CType(dvInventory_Software.FindControl("lblKey_ErrMsg"),
Label).Visible = True
End If
dvInventory_Software.Visible = True
Case "NETWORKING"
If strField = "Manufacturer" Then
CType(dvInventory_Networking.FindControl("lblManufacturer_ErrMsg"),
Label).Visible = True
ElseIf strField = "Model" Then
CType(dvInventory_Networking.FindControl("lblModel_ErrMsg"), Label).Visible
=
True
ElseIf strField = "SubType" Then
CType(dvInventory_Networking.FindControl("lblSubType_ErrMsg"), Label).Visibl
e
= True
Else
CType(dvInventory_Networking.FindControl("lblKey_ErrMsg"), Label).Visible =
True
End If
dvInventory_Networking.Visible = True
Case "MODEM"
If strField = "Manufacturer" Then
CType(dvInventory_Modem.FindControl("lblManufacturer_ErrMsg"), Label).Visibl
e
= True
ElseIf strField = "Model" Then
CType(dvInventory_Modem.FindControl("lblModel_ErrMsg"),
Label).Visible = True
ElseIf strField = "SubType" Then
CType(dvInventory_Modem.FindControl("lblSubType_ErrMsg"), Label).Visible =
True
Else
CType(dvInventory_Modem.FindControl("lblKey_ErrMsg"),
Label).Visible = True
End If
dvInventory_Modem.Visible = True
Case "ACCESSORIES"
If strField = "Manufacturer" Then
CType(dvInventory_Accessories.FindControl("lblManufacturer_ErrMsg"),
Label).Visible = True
ElseIf strField = "Model" Then
CType(dvInventory_Accessories.FindControl("lblModel_ErrMsg"), Label).Visible
= True
ElseIf strField = "SubType" Then
CType(dvInventory_Accessories.FindControl("lblSubType_ErrMsg"),
Label).Visible = True
Else
CType(dvInventory_Accessories.FindControl("lblKey_ErrMsg"), Label).Visible =
True
End If
dvInventory_Accessories.Visible = True
Case "STORAGE"
If strField = "Manufacturer" Then
CType(dvInventory_Storage.FindControl("lblManufacturer_ErrMsg"),
Label).Visible = True
ElseIf strField = "Model" Then
CType(dvInventory_Storage.FindControl("lblModel_ErrMsg"), Label).Visible =
True
ElseIf strField = "SubType" Then
CType(dvInventory_Storage.FindControl("lblSubType_ErrMsg"), Label).Visible =
True
Else
CType(dvInventory_Storage.FindControl("lblKey_ErrMsg"),
Label).Visible = True
End If
dvInventory_Storage.Visible = True
Case "OTHERS"
If strField = "Manufacturer" Then
CType(dvInventory_Others.FindControl("lblManufacturer_ErrMsg"),
Label).Visible = True
ElseIf strField = "Model" Then
CType(dvInventory_Others.FindControl("lblModel_ErrMsg"),
Label).Visible = True
ElseIf strField = "SubType" Then
CType(dvInventory_Others.FindControl("lblSubType_ErrMsg"), Label).Visible =
True
Else
CType(dvInventory_Others.FindControl("lblKey_ErrMsg"),
Label).Visible = True
End If
Line 842: dvInventory_Others.Visible = True
End Select
End Sub
"Kevin Spencer" wrote:

> Which one is "line 842"?
> --
> HTH,
> Kevin Spencer
> Microsoft MVP
> Professional Numbskull
> Hard work is a medication for which
> there is no placebo.
> "Seok Bee" <seokbee@.yahoo.com> wrote in message
> news:FC2C952C-DAB3-4C99-9E9C-6C25578CD4C2@.microsoft.com...
>
>
Interesting. So, you're telling me that *all* of this is "line 842"?
HTH,
Kevin Spencer
Microsoft MVP
Professional Numbskull
Hard work is a medication for which
there is no placebo.
"Seok Bee" <seokbee@.yahoo.com> wrote in message
news:C061723B-3DC1-42EA-A392-B88E8B3F092C@.microsoft.com...
> Private Sub ShowError(ByVal strMainType As String, ByVal strField As
> String)
> Select Case UCase(strMainType)
> Case "COMPUTER"
> If strField = "Manufacturer" Then
> CType(dvInventory_Computer.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "Model" Then
> CType(dvInventory_Computer.FindControl("lblModel_ErrMsg"), Label).Visible
> =
> True
> ElseIf strField = "SubType" Then
> CType(dvInventory_Computer.FindControl("lblSubType_ErrMsg"),
> Label).Visible =
> True
> Else
> CType(dvInventory_Computer.FindControl("lblKey_ErrMsg"),
> Label).Visible = True
> End If
> dvInventory_Computer.Visible = True
> Case "NIC"
> If strField = "Manufacturer" Then
> CType(dvInventory_NIC.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible =
> True
> ElseIf strField = "Model" Then
> CType(dvInventory_NIC.FindControl("lblModel_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "SubType" Then
> CType(dvInventory_NIC.FindControl("lblSubType_ErrMsg"),
> Label).Visible = True
> Else
> CType(dvInventory_NIC.FindControl("lblKey_ErrMsg"),
> Label).Visible = True
> End If
> dvInventory_NIC.Visible = True
> Case "OPTICALDRIVE"
> If strField = "Manufacturer" Then
> CType(dvInventory_ExtOD.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible
> = True
> ElseIf strField = "Model" Then
> CType(dvInventory_ExtOD.FindControl("lblModel_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "SubType" Then
> CType(dvInventory_ExtOD.FindControl("lblSubType_ErrMsg"), Label).Visible =
> True
> Else
> CType(dvInventory_ExtOD.FindControl("lblKey_ErrMsg"),
> Label).Visible = True
> End If
> dvInventory_ExtOD.Visible = True
> Case "MONITOR"
> If strField = "Manufacturer" Then
> CType(dvInventory_Monitor.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "Model" Then
> CType(dvInventory_Monitor.FindControl("lblModel_ErrMsg"), Label).Visible =
> True
> ElseIf strField = "SubType" Then
> CType(dvInventory_Monitor.FindControl("lblSubType_ErrMsg"), Label).Visible
> =
> True
> Else
> CType(dvInventory_Monitor.FindControl("lblKey_ErrMsg"),
> Label).Visible = True
> End If
> dvInventory_Monitor.Visible = True
> Case "PRINTER/SCANNER"
> If strField = "Manufacturer" Then
> CType(dvInventory_PrinterScanner.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "Model" Then
> CType(dvInventory_PrinterScanner.FindControl("lblModel_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "SubType" Then
> CType(dvInventory_PrinterScanner.FindControl("lblSubType_ErrMsg"),
> Label).Visible = True
> Else
> CType(dvInventory_PrinterScanner.FindControl("lblKey_ErrMsg"),
> Label).Visible
> = True
> End If
> dvInventory_PrinterScanner.Visible = True
> Case "UPS"
> If strField = "Manufacturer" Then
> CType(dvInventory_UPS.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible =
> True
> ElseIf strField = "Model" Then
> CType(dvInventory_UPS.FindControl("lblModel_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "SubType" Then
> CType(dvInventory_UPS.FindControl("lblSubType_ErrMsg"),
> Label).Visible = True
> Else
> CType(dvInventory_UPS.FindControl("lblKey_ErrMsg"),
> Label).Visible = True
> End If
> dvInventory_UPS.Visible = True
> Case "SOFTWARE"
> If strField = "Manufacturer" Then
> CType(dvInventory_Software.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "Model" Then
> CType(dvInventory_Software.FindControl("lblModel_ErrMsg"), Label).Visible
> =
> True
> ElseIf strField = "SubType" Then
> CType(dvInventory_Software.FindControl("lblSubType_ErrMsg"),
> Label).Visible =
> True
> Else
> CType(dvInventory_Software.FindControl("lblKey_ErrMsg"),
> Label).Visible = True
> End If
> dvInventory_Software.Visible = True
> Case "NETWORKING"
> If strField = "Manufacturer" Then
> CType(dvInventory_Networking.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "Model" Then
> CType(dvInventory_Networking.FindControl("lblModel_ErrMsg"),
> Label).Visible =
> True
> ElseIf strField = "SubType" Then
> CType(dvInventory_Networking.FindControl("lblSubType_ErrMsg"),
> Label).Visible
> = True
> Else
> CType(dvInventory_Networking.FindControl("lblKey_ErrMsg"), Label).Visible
> =
> True
> End If
> dvInventory_Networking.Visible = True
> Case "MODEM"
> If strField = "Manufacturer" Then
> CType(dvInventory_Modem.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible
> = True
> ElseIf strField = "Model" Then
> CType(dvInventory_Modem.FindControl("lblModel_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "SubType" Then
> CType(dvInventory_Modem.FindControl("lblSubType_ErrMsg"), Label).Visible =
> True
> Else
> CType(dvInventory_Modem.FindControl("lblKey_ErrMsg"),
> Label).Visible = True
> End If
> dvInventory_Modem.Visible = True
> Case "ACCESSORIES"
> If strField = "Manufacturer" Then
> CType(dvInventory_Accessories.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "Model" Then
> CType(dvInventory_Accessories.FindControl("lblModel_ErrMsg"),
> Label).Visible
> = True
> ElseIf strField = "SubType" Then
> CType(dvInventory_Accessories.FindControl("lblSubType_ErrMsg"),
> Label).Visible = True
> Else
> CType(dvInventory_Accessories.FindControl("lblKey_ErrMsg"), Label).Visible
> =
> True
> End If
> dvInventory_Accessories.Visible = True
> Case "STORAGE"
> If strField = "Manufacturer" Then
> CType(dvInventory_Storage.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "Model" Then
> CType(dvInventory_Storage.FindControl("lblModel_ErrMsg"), Label).Visible =
> True
> ElseIf strField = "SubType" Then
> CType(dvInventory_Storage.FindControl("lblSubType_ErrMsg"), Label).Visible
> =
> True
> Else
> CType(dvInventory_Storage.FindControl("lblKey_ErrMsg"),
> Label).Visible = True
> End If
> dvInventory_Storage.Visible = True
> Case "OTHERS"
> If strField = "Manufacturer" Then
> CType(dvInventory_Others.FindControl("lblManufacturer_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "Model" Then
> CType(dvInventory_Others.FindControl("lblModel_ErrMsg"),
> Label).Visible = True
> ElseIf strField = "SubType" Then
> CType(dvInventory_Others.FindControl("lblSubType_ErrMsg"), Label).Visible
> =
> True
> Else
> CType(dvInventory_Others.FindControl("lblKey_ErrMsg"),
> Label).Visible = True
> End If
> Line 842: dvInventory_Others.Visible = True
> End Select
> End Sub
>
> "Kevin Spencer" wrote:
>
No, he actually marked the line with "Line 842:". I just saw it by
chance. It's the third line from the end in the large chunk of code.
Kevin Spencer wrote:
> Interesting. So, you're telling me that *all* of this is "line 842"?
>
Okay. That line reads:
dvInventory_Others.Visible = True
Apparently, dvInventory_Others is null (Nothing).
HTH,
Kevin Spencer
Microsoft MVP
Professional Numbskull
Hard work is a medication for which
there is no placebo.
"Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> wrote in message
news:ODcvfcEdGHA.3888@.TK2MSFTNGP02.phx.gbl...
> Interesting. So, you're telling me that *all* of this is "line 842"?
> --
> HTH,
> Kevin Spencer
> Microsoft MVP
> Professional Numbskull
> Hard work is a medication for which
> there is no placebo.
> "Seok Bee" <seokbee@.yahoo.com> wrote in message
> news:C061723B-3DC1-42EA-A392-B88E8B3F092C@.microsoft.com...
>

Object reference not set to an instance of an object. -- Please Urgent

Hi There,
I am trying to write the selected value of a listcontrol when a button is
clicked and I keep getting the error "object not set to a reference of an
object". The libox itself is in a usercontrol and all i'm really needing to
do is get the selected value when the button is clicked on the form.
Can someone tell what I need to include in my page to get this working ?
Moe <><
!-- response.write
response.write (lstS.selectedItem.tostring())
response.end
!-- class function
Public Class CommonFunctions
Public Shared Function BindStates() as SqlDataReader
Dim myConnection as New
SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
Const strSQL as String = "SELECT LocationID, Location AS
Location " & _
"FROM tbLocation ORDER BY
Location"
Dim myCommand as New SqlCommand(strSQL, myConnection)
myConnection.Open()
Dim objDR as SqlDataReader
objDR = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
Return objDr
End Function
End Class
!-- bind the contro
lstS.DataSource = CommonFunctions.BindStates
lstS.DataBind()
lstS.Items.Insert(0, new ListItem("By State","0"))
!- lisbox on page
<asp:listbox id="lstS" runat="server" rows=1
DataTextField="Location" DataValueField="LocationID"/>Moe,
First I am assuming that you aren't trying to repsponse.write the value
until after it's selected. You'll get the object reference error right away
otherwise since no value has been selected yet.
Second, you need to make certain that the code populating the list only
fires on page load. If not, it is resetting the list every time. Do this
with the following if then:
If Not Page.IsPostBack Then
'--Populate list only once here
End If
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Moe Sizlak" <moe@.moe.com> wrote in message
news:%23LjercQeEHA.3552@.tk2msftngp13.phx.gbl...
> Hi There,
> I am trying to write the selected value of a listcontrol when a button is
> clicked and I keep getting the error "object not set to a reference of an
> object". The libox itself is in a usercontrol and all i'm really needing
to
> do is get the selected value when the button is clicked on the form.
> Can someone tell what I need to include in my page to get this working ?
> Moe <><
> !-- response.write
> response.write (lstS.selectedItem.tostring())
> response.end
>
> !-- class function
> Public Class CommonFunctions
> Public Shared Function BindStates() as SqlDataReader
> Dim myConnection as New
> SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
> Const strSQL as String = "SELECT LocationID, Location AS
> Location " & _
> "FROM tbLocation ORDER BY
> Location"
> Dim myCommand as New SqlCommand(strSQL, myConnection)
> myConnection.Open()
> Dim objDR as SqlDataReader
> objDR = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
> Return objDr
> End Function
> End Class
> !-- bind the contro
> lstS.DataSource = CommonFunctions.BindStates
> lstS.DataBind()
> lstS.Items.Insert(0, new ListItem("By State","0"))
> !- lisbox on page
> <asp:listbox id="lstS" runat="server" rows=1
> DataTextField="Location" DataValueField="LocationID"/>
>
Hi Justin,
I have the listmenu on the page and I do make sure that the menu is selected
before clicking the button, the load sud where I bind the list is in the
user control. Would this make a difference?
Moe
Sub Page_Load(byVal obj As Object, byVal e As EventArgs)
If Not Page.IsPostBack Then
lstS.DataSource = CommonFunctions.BindStates
lstS.DataBind()
lstS.Items.Insert(0, new ListItem("By State","0"))
End If
End Sub
"S. Justin Gengo" <sjgengo@.aboutfortunate[no-spam].com> wrote in message
news:10gu2o4t1gmb294@.corp.supernews.com...
> Moe,
> First I am assuming that you aren't trying to repsponse.write the value
> until after it's selected. You'll get the object reference error right
away
> otherwise since no value has been selected yet.
> Second, you need to make certain that the code populating the list only
> fires on page load. If not, it is resetting the list every time. Do this
> with the following if then:
> If Not Page.IsPostBack Then
> '--Populate list only once here
> End If
>
> --
> Sincerely,
> S. Justin Gengo, MCP
> Web Developer / Programmer
> www.aboutfortunate.com
> "Out of chaos comes order."
> Nietzsche
> "Moe Sizlak" <moe@.moe.com> wrote in message
> news:%23LjercQeEHA.3552@.tk2msftngp13.phx.gbl...
is
an
> to
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
>
Moe,
No, that looks good. It shouldn't make a difference that it's in a user
control.
Are you adding the user control to the page dynamically?
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Moe Sizlak" <moe@.moe.com> wrote in message
news:e%23ckR9QeEHA.3684@.TK2MSFTNGP09.phx.gbl...
> Hi Justin,
> I have the listmenu on the page and I do make sure that the menu is
selected
> before clicking the button, the load sud where I bind the list is in the
> user control. Would this make a difference?
> Moe
> Sub Page_Load(byVal obj As Object, byVal e As EventArgs)
> If Not Page.IsPostBack Then
> lstS.DataSource = CommonFunctions.BindStates
> lstS.DataBind()
> lstS.Items.Insert(0, new ListItem("By State","0"))
> End If
> End Sub
>
> "S. Justin Gengo" <sjgengo@.aboutfortunate[no-spam].com> wrote in message
> news:10gu2o4t1gmb294@.corp.supernews.com...
> away
> is
> an
needing
?
AS
> myCommand.ExecuteReader(CommandBehavior.CloseConnection)
>
Hi Justin,
The control I am using is "includes/_control_content.ascx" and I just
include it in the main page. What else could it be?
Sean
<% @.Import Namespace="System.Data" %>
<% @.Import Namespace="System.Data.SqlClient" %>
<% @.Import Namespace="System.Web.UI.WebControls.DropDownList" %>
<%@. Import Namespace="System.Web.UI.WebControls.CheckBox" %>
<%@. Register TagPrefix="UserControl2" TagName="PlaceHeader"
Src="includes/_placelistingsuser_header.ascx" %>
<%@. Register TagPrefix="UserControl3" TagName="Control"
Src="includes/_control_content.ascx" %>
<%@. Register TagPrefix="UserControl4" TagName="FormList"
Src="includes/_formlist_content.ascx" %>
<link rel="stylesheet" type="text/css" href="http://links.10026.com/?link=>
<script language="vb" runat="server">
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="distribution" content="global">
<meta name="revisit-after" content="14 days">
<meta name="ROBOTS" content="ALL">
<title>title</title>
</head>
<form enctype="multipart/form-data" runat="server">
<body topmargin="0" marginheight="0" marginwidth="0">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<td colspan="2" valign=top><UserControl2:PlaceHeader runat="server"
/></td>
<tr>
<td width="563" valign=top style="padding-left:40px "><div align=left
class=formtext sty style="padding-left:8px "></div><br><UserControl3:Control
runat="server" /></td>
<td>2</td>
</tr>
<TR>
<td colspan=2> </td>
<td>
</tr>
</table>
</form>
</body>
</html>
"S. Justin Gengo" <sjgengo@.aboutfortunate[no-spam].com> wrote in message
news:10gu5g8q5cnksf0@.corp.supernews.com...
> Moe,
> No, that looks good. It shouldn't make a difference that it's in a user
> control.
> Are you adding the user control to the page dynamically?
> --
> Sincerely,
> S. Justin Gengo, MCP
> Web Developer / Programmer
> www.aboutfortunate.com
> "Out of chaos comes order."
> Nietzsche
> "Moe Sizlak" <moe@.moe.com> wrote in message
> news:e%23ckR9QeEHA.3684@.TK2MSFTNGP09.phx.gbl...
> selected
value
only
this
button
of
> needing
working
> ?
> AS
BY
DataValueField="LocationID"/>
>
Hi Justin,
Any other ideas? have a forgotten to declare something in my page?
"Moe Sizlak" <moe@.moe.com> wrote in message
news:uD27XQReEHA.2848@.TK2MSFTNGP10.phx.gbl...
> Hi Justin,
> The control I am using is "includes/_control_content.ascx" and I just
> include it in the main page. What else could it be?
> Sean
> <% @.Import Namespace="System.Data" %>
> <% @.Import Namespace="System.Data.SqlClient" %>
> <% @.Import Namespace="System.Web.UI.WebControls.DropDownList" %>
> <%@. Import Namespace="System.Web.UI.WebControls.CheckBox" %>
> <%@. Register TagPrefix="UserControl2" TagName="PlaceHeader"
> src="http://pics.10026.com/?src=includes/_placelistingsuser_header.ascx" %>
> <%@. Register TagPrefix="UserControl3" TagName="Control"
> src="http://pics.10026.com/?src=includes/_control_content.ascx" %>
> <%@. Register TagPrefix="UserControl4" TagName="FormList"
> src="http://pics.10026.com/?src=includes/_formlist_content.ascx" %>
> <link rel="stylesheet" type="text/css" href="http://links.10026.com/?link=>
> <script language="vb" runat="server">
>
> </script>
>
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> <meta name="distribution" content="global">
> <meta name="revisit-after" content="14 days">
> <meta name="ROBOTS" content="ALL">
> <title>title</title>
> </head>
> <form enctype="multipart/form-data" runat="server">
> <body topmargin="0" marginheight="0" marginwidth="0">
> <table width="100%" border="0" cellpadding="0" cellspacing="0">
> <td colspan="2" valign=top><UserControl2:PlaceHeader runat="server"
> /></td>
> <tr>
> <td width="563" valign=top style="padding-left:40px "><div align=left
> class=formtext sty style="padding-left:8px
"></div><br><UserControl3:Control
> runat="server" /></td>
> <td>2</td>
> </tr>
> <TR>
> <td colspan=2> </td>
> <td>
> </tr>
> </table>
> </form>
> </body>
> </html>
>
> "S. Justin Gengo" <sjgengo@.aboutfortunate[no-spam].com> wrote in message
> news:10gu5g8q5cnksf0@.corp.supernews.com...
the
message
> value
right
> only
> this
> button
reference
> of
form.
> working
SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
Location
ORDER
> BY
> DataValueField="LocationID"/>
>
Moe,
Are you trying to response.write the value from the user control itself or
from the page the control is on?
If you are trying to write it from the page the control is on you can't
refer to it directly. You have to refer to it through the user control
itself.
You could do this two ways:
One would be to just response.write the value from the control itself using
the data list's OnSelectedValueChanged handler
The other would be to use FindControl on the main page to get a reference to
the user control object and then use that to refer to the datalist.
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Moe Sizlak" <moe@.moe.com> wrote in message
news:eDpjmkReEHA.3916@.TK2MSFTNGP11.phx.gbl...
> Hi Justin,
> Any other ideas? have a forgotten to declare something in my page?
>
>
> "Moe Sizlak" <moe@.moe.com> wrote in message
> news:uD27XQReEHA.2848@.TK2MSFTNGP10.phx.gbl...
align=left
> "></div><br><UserControl3:Control
user
> the
> message
> right
Do
> reference
> form.
> SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
> Location
> ORDER
>
Hi Justin,
I am trying to use the response.write from the user control itself, I
managed to create a class in a code behind then reference the control in the
usercontrol page. The control displays correctly but when I try to catch the
value from the listbox it gives me the message "text is not a member of
string". I know that I'm almost there!!
Once I have the basic framework with this piece of code I will be able to
rollon from there.
Sean
"S. Justin Gengo" <sjgengo@.aboutfortunate[no-spam].com> wrote in message
news:10gv3867d7uot23@.corp.supernews.com...
> Moe,
> Are you trying to response.write the value from the user control itself or
> from the page the control is on?
> If you are trying to write it from the page the control is on you can't
> refer to it directly. You have to refer to it through the user control
> itself.
> You could do this two ways:
> One would be to just response.write the value from the control itself
using
> the data list's OnSelectedValueChanged handler
> The other would be to use FindControl on the main page to get a reference
to
> the user control object and then use that to refer to the datalist.
> --
> Sincerely,
> S. Justin Gengo, MCP
> Web Developer / Programmer
> www.aboutfortunate.com
> "Out of chaos comes order."
> Nietzsche
> "Moe Sizlak" <moe@.moe.com> wrote in message
> news:eDpjmkReEHA.3916@.TK2MSFTNGP11.phx.gbl...
charset=iso-8859-1">
runat="server"
> align=left
message
> user
is
in
the
list
> Do
a
really
myConnection)
>
Hi.
Did anyone manage to find the solution to this problem?
I'm having a similar issue with populating a drop-down list menu from
a SQLDataReader.
Here is my function:-
Function SelectOptions(ByVal queryString) As
System.Data.SqlClient.SqlDataReader
' Application("ConnectionString") is set in our global.asax file
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New
System.Data.SqlClient.SqlConnection(Application("ConnectionString"))
Dim sqlCommand As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlConnection.Open()
Dim dataReader As System.Data.SqlClient.SqlDataReader =
sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
Return dataReader
End Function
If I call this function directly in my aspx page it works fine, no
problem.
However, if i attempt to call it via my own custom web user control
ascx page, it causes a "Object reference not set to an instance of an
object." error.
Here is my non-working code:-
Dim func As New CommonFunctions
dropdownlist.DataSource = func.SelectOptions("SELECT colname FROM
table")
dropdownlist.DataBind()
Any help is much appreciated.
Thanks in advance
Dan Williams.
It appears that my web user control didn't like my
Application("ConnectionString") setting.
As soon as i referenced it using
System.Web.HttpContext.Current.Application("connectionString"), it
worked straight away, no problem.
Cheers
Dan.
dan_williams@.newcross-nursing.com (Dan Williams) wrote in message news:<2eac5d02.0408250258
.287751@.posting.google.com>...
> Hi.
> Did anyone manage to find the solution to this problem?
> I'm having a similar issue with populating a drop-down list menu from
> a SQLDataReader.
> Here is my function:-
> Function SelectOptions(ByVal queryString) As
> System.Data.SqlClient.SqlDataReader
> ' Application("ConnectionString") is set in our global.asax file
> Dim sqlConnection As System.Data.SqlClient.SqlConnection = New
> System.Data.SqlClient.SqlConnection(Application("ConnectionString"))
> Dim sqlCommand As System.Data.SqlClient.SqlCommand = New
> System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
> sqlConnection.Open()
> Dim dataReader As System.Data.SqlClient.SqlDataReader =
> sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
> Return dataReader
> End Function
> If I call this function directly in my aspx page it works fine, no
> problem.
> However, if i attempt to call it via my own custom web user control
> ascx page, it causes a "Object reference not set to an instance of an
> object." error.
> Here is my non-working code:-
> Dim func As New CommonFunctions
> dropdownlist.DataSource = func.SelectOptions("SELECT colname FROM
> table")
> dropdownlist.DataBind()
> Any help is much appreciated.
> Thanks in advance
> Dan Williams.

Object reference not set to an instance of an object. -- Please Urgent

Hi There,

I am trying to write the selected value of a listcontrol when a button is
clicked and I keep getting the error "object not set to a reference of an
object". The libox itself is in a usercontrol and all i'm really needing to
do is get the selected value when the button is clicked on the form.

Can someone tell what I need to include in my page to get this working ?

Moe <><

!-- response.write

response.write (lstS.selectedItem.tostring())

response.end

!-- class function

Public Class CommonFunctions
Public Shared Function BindStates() as SqlDataReader

Dim myConnection as New
SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
Const strSQL as String = "SELECT LocationID, Location AS
Location " & _
"FROM tbLocation ORDER BY
Location"
Dim myCommand as New SqlCommand(strSQL, myConnection)
myConnection.Open()
Dim objDR as SqlDataReader
objDR = myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
Return objDr
End Function
End Class

!-- bind the contro

lstS.DataSource = CommonFunctions.BindStates
lstS.DataBind()
lstS.Items.Insert(0, new ListItem("By State","0"))

!- lisbox on page

<asp:listbox id="lstS" runat="server" rows=1
DataTextField="Location" DataValueField="LocationID"/Moe,

First I am assuming that you aren't trying to repsponse.write the value
until after it's selected. You'll get the object reference error right away
otherwise since no value has been selected yet.

Second, you need to make certain that the code populating the list only
fires on page load. If not, it is resetting the list every time. Do this
with the following if then:

If Not Page.IsPostBack Then
'--Populate list only once here
End If

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Moe Sizlak" <moe@.moe.com> wrote in message
news:%23LjercQeEHA.3552@.tk2msftngp13.phx.gbl...
> Hi There,
> I am trying to write the selected value of a listcontrol when a button is
> clicked and I keep getting the error "object not set to a reference of an
> object". The libox itself is in a usercontrol and all i'm really needing
to
> do is get the selected value when the button is clicked on the form.
> Can someone tell what I need to include in my page to get this working ?
> Moe <><
> !-- response.write
> response.write (lstS.selectedItem.tostring())
> response.end
>
> !-- class function
> Public Class CommonFunctions
> Public Shared Function BindStates() as SqlDataReader
> Dim myConnection as New
> SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
> Const strSQL as String = "SELECT LocationID, Location AS
> Location " & _
> "FROM tbLocation ORDER BY
> Location"
> Dim myCommand as New SqlCommand(strSQL, myConnection)
> myConnection.Open()
> Dim objDR as SqlDataReader
> objDR = myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
> Return objDr
> End Function
> End Class
> !-- bind the contro
> lstS.DataSource = CommonFunctions.BindStates
> lstS.DataBind()
> lstS.Items.Insert(0, new ListItem("By State","0"))
> !- lisbox on page
> <asp:listbox id="lstS" runat="server" rows=1
> DataTextField="Location" DataValueField="LocationID"/>
Hi Justin,

I have the listmenu on the page and I do make sure that the menu is selected
before clicking the button, the load sud where I bind the list is in the
user control. Would this make a difference?

Moe

Sub Page_Load(byVal obj As Object, byVal e As EventArgs)
If Not Page.IsPostBack Then
lstS.DataSource = CommonFunctions.BindStates
lstS.DataBind()
lstS.Items.Insert(0, new ListItem("By State","0"))
End If
End Sub

"S. Justin Gengo" <sjgengo@.aboutfortunate[no-spam].com> wrote in message
news:10gu2o4t1gmb294@.corp.supernews.com...
> Moe,
> First I am assuming that you aren't trying to repsponse.write the value
> until after it's selected. You'll get the object reference error right
away
> otherwise since no value has been selected yet.
> Second, you need to make certain that the code populating the list only
> fires on page load. If not, it is resetting the list every time. Do this
> with the following if then:
> If Not Page.IsPostBack Then
> '--Populate list only once here
> End If
>
> --
> Sincerely,
> S. Justin Gengo, MCP
> Web Developer / Programmer
> www.aboutfortunate.com
> "Out of chaos comes order."
> Nietzsche
> "Moe Sizlak" <moe@.moe.com> wrote in message
> news:%23LjercQeEHA.3552@.tk2msftngp13.phx.gbl...
> > Hi There,
> > I am trying to write the selected value of a listcontrol when a button
is
> > clicked and I keep getting the error "object not set to a reference of
an
> > object". The libox itself is in a usercontrol and all i'm really needing
> to
> > do is get the selected value when the button is clicked on the form.
> > Can someone tell what I need to include in my page to get this working ?
> > Moe <><
> > !-- response.write
> > response.write (lstS.selectedItem.tostring())
> > response.end
> > !-- class function
> > Public Class CommonFunctions
> > Public Shared Function BindStates() as SqlDataReader
> > Dim myConnection as New
> > SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
> > Const strSQL as String = "SELECT LocationID, Location AS
> > Location " & _
> > "FROM tbLocation ORDER BY
> > Location"
> > Dim myCommand as New SqlCommand(strSQL, myConnection)
> > myConnection.Open()
> > Dim objDR as SqlDataReader
> > objDR =
myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
> > Return objDr
> > End Function
> > End Class
> > !-- bind the contro
> > lstS.DataSource = CommonFunctions.BindStates
> > lstS.DataBind()
> > lstS.Items.Insert(0, new ListItem("By State","0"))
> > !- lisbox on page
> > <asp:listbox id="lstS" runat="server" rows=1
> > DataTextField="Location" DataValueField="LocationID"/>
Moe,

No, that looks good. It shouldn't make a difference that it's in a user
control.

Are you adding the user control to the page dynamically?

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Moe Sizlak" <moe@.moe.com> wrote in message
news:e%23ckR9QeEHA.3684@.TK2MSFTNGP09.phx.gbl...
> Hi Justin,
> I have the listmenu on the page and I do make sure that the menu is
selected
> before clicking the button, the load sud where I bind the list is in the
> user control. Would this make a difference?
> Moe
> Sub Page_Load(byVal obj As Object, byVal e As EventArgs)
> If Not Page.IsPostBack Then
> lstS.DataSource = CommonFunctions.BindStates
> lstS.DataBind()
> lstS.Items.Insert(0, new ListItem("By State","0"))
> End If
> End Sub
>
> "S. Justin Gengo" <sjgengo@.aboutfortunate[no-spam].com> wrote in message
> news:10gu2o4t1gmb294@.corp.supernews.com...
> > Moe,
> > First I am assuming that you aren't trying to repsponse.write the value
> > until after it's selected. You'll get the object reference error right
> away
> > otherwise since no value has been selected yet.
> > Second, you need to make certain that the code populating the list only
> > fires on page load. If not, it is resetting the list every time. Do this
> > with the following if then:
> > If Not Page.IsPostBack Then
> > '--Populate list only once here
> > End If
> > --
> > Sincerely,
> > S. Justin Gengo, MCP
> > Web Developer / Programmer
> > www.aboutfortunate.com
> > "Out of chaos comes order."
> > Nietzsche
> > "Moe Sizlak" <moe@.moe.com> wrote in message
> > news:%23LjercQeEHA.3552@.tk2msftngp13.phx.gbl...
> > > Hi There,
> > > > I am trying to write the selected value of a listcontrol when a button
> is
> > > clicked and I keep getting the error "object not set to a reference of
> an
> > > object". The libox itself is in a usercontrol and all i'm really
needing
> > to
> > > do is get the selected value when the button is clicked on the form.
> > > > Can someone tell what I need to include in my page to get this working
?
> > > > Moe <><
> > > > !-- response.write
> > > > response.write (lstS.selectedItem.tostring())
> > > > response.end
> > > > > !-- class function
> > > > Public Class CommonFunctions
> > > Public Shared Function BindStates() as SqlDataReader
> > > > Dim myConnection as New
> > > SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
> > > Const strSQL as String = "SELECT LocationID, Location
AS
> > > Location " & _
> > > "FROM tbLocation ORDER BY
> > > Location"
> > > Dim myCommand as New SqlCommand(strSQL, myConnection)
> > > myConnection.Open()
> > > Dim objDR as SqlDataReader
> > > objDR =
> myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
> > > Return objDr
> > > End Function
> > > End Class
> > > > !-- bind the contro
> > > > lstS.DataSource = CommonFunctions.BindStates
> > > lstS.DataBind()
> > > lstS.Items.Insert(0, new ListItem("By State","0"))
> > > > !- lisbox on page
> > > > <asp:listbox id="lstS" runat="server" rows=1
> > > DataTextField="Location" DataValueField="LocationID"/>
> >
Hi Justin,

The control I am using is "includes/_control_content.ascx" and I just
include it in the main page. What else could it be?

Sean

<% @.Import Namespace="System.Data" %>
<% @.Import Namespace="System.Data.SqlClient" %>
<% @.Import Namespace="System.Web.UI.WebControls.DropDownList" %>
<%@. Import Namespace="System.Web.UI.WebControls.CheckBox" %>
<%@. Register TagPrefix="UserControl2" TagName="PlaceHeader"
Src="includes/_placelistingsuser_header.ascx" %>
<%@. Register TagPrefix="UserControl3" TagName="Control"
Src="includes/_control_content.ascx" %>
<%@. Register TagPrefix="UserControl4" TagName="FormList"
Src="includes/_formlist_content.ascx" %>
<link rel="stylesheet" type="text/css" href="http://links.10026.com/?link=>
<script language="vb" runat="server"
</script
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="distribution" content="global">
<meta name="revisit-after" content="14 days">
<meta name="ROBOTS" content="ALL"
<title>title</title>
</head>
<form enctype="multipart/form-data" runat="server">
<body topmargin="0" marginheight="0" marginwidth="0">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<td colspan="2" valign=top><UserControl2:PlaceHeader runat="server"
/></td>
<tr>
<td width="563" valign=top style="padding-left:40px "><div align=left
class=formtext sty style="padding-left:8px "></div><br><UserControl3:Control
runat="server" /></td>
<td>2</td>
</tr
<TR>
<td colspan=2> </td>
<td>
</tr>
</table>
</form>
</body>
</html
"S. Justin Gengo" <sjgengo@.aboutfortunate[no-spam].com> wrote in message
news:10gu5g8q5cnksf0@.corp.supernews.com...
> Moe,
> No, that looks good. It shouldn't make a difference that it's in a user
> control.
> Are you adding the user control to the page dynamically?
> --
> Sincerely,
> S. Justin Gengo, MCP
> Web Developer / Programmer
> www.aboutfortunate.com
> "Out of chaos comes order."
> Nietzsche
> "Moe Sizlak" <moe@.moe.com> wrote in message
> news:e%23ckR9QeEHA.3684@.TK2MSFTNGP09.phx.gbl...
> > Hi Justin,
> > I have the listmenu on the page and I do make sure that the menu is
> selected
> > before clicking the button, the load sud where I bind the list is in the
> > user control. Would this make a difference?
> > Moe
> > Sub Page_Load(byVal obj As Object, byVal e As EventArgs)
> > If Not Page.IsPostBack Then
> > lstS.DataSource = CommonFunctions.BindStates
> > lstS.DataBind()
> > lstS.Items.Insert(0, new ListItem("By State","0"))
> > End If
> > End Sub
> > "S. Justin Gengo" <sjgengo@.aboutfortunate[no-spam].com> wrote in message
> > news:10gu2o4t1gmb294@.corp.supernews.com...
> > > Moe,
> > > > First I am assuming that you aren't trying to repsponse.write the
value
> > > until after it's selected. You'll get the object reference error right
> > away
> > > otherwise since no value has been selected yet.
> > > > Second, you need to make certain that the code populating the list
only
> > > fires on page load. If not, it is resetting the list every time. Do
this
> > > with the following if then:
> > > > If Not Page.IsPostBack Then
> > > '--Populate list only once here
> > > End If
> > > > > --
> > > Sincerely,
> > > > S. Justin Gengo, MCP
> > > Web Developer / Programmer
> > > > www.aboutfortunate.com
> > > > "Out of chaos comes order."
> > > Nietzsche
> > > "Moe Sizlak" <moe@.moe.com> wrote in message
> > > news:%23LjercQeEHA.3552@.tk2msftngp13.phx.gbl...
> > > > Hi There,
> > > > > > I am trying to write the selected value of a listcontrol when a
button
> > is
> > > > clicked and I keep getting the error "object not set to a reference
of
> > an
> > > > object". The libox itself is in a usercontrol and all i'm really
> needing
> > > to
> > > > do is get the selected value when the button is clicked on the form.
> > > > > > Can someone tell what I need to include in my page to get this
working
> ?
> > > > > > Moe <><
> > > > > > !-- response.write
> > > > > > response.write (lstS.selectedItem.tostring())
> > > > > > response.end
> > > > > > > > !-- class function
> > > > > > Public Class CommonFunctions
> > > > Public Shared Function BindStates() as SqlDataReader
> > > > > > Dim myConnection as New
> > > > SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
> > > > Const strSQL as String = "SELECT LocationID, Location
> AS
> > > > Location " & _
> > > > "FROM tbLocation ORDER
BY
> > > > Location"
> > > > Dim myCommand as New SqlCommand(strSQL, myConnection)
> > > > myConnection.Open()
> > > > Dim objDR as SqlDataReader
> > > > objDR =
> > myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
> > > > Return objDr
> > > > End Function
> > > > End Class
> > > > > > !-- bind the contro
> > > > > > lstS.DataSource = CommonFunctions.BindStates
> > > > lstS.DataBind()
> > > > lstS.Items.Insert(0, new ListItem("By State","0"))
> > > > > > !- lisbox on page
> > > > > > <asp:listbox id="lstS" runat="server" rows=1
> > > > DataTextField="Location"
DataValueField="LocationID"/>
> > > > > >
Hi Justin,

Any other ideas? have a forgotten to declare something in my page?

"Moe Sizlak" <moe@.moe.com> wrote in message
news:uD27XQReEHA.2848@.TK2MSFTNGP10.phx.gbl...
> Hi Justin,
> The control I am using is "includes/_control_content.ascx" and I just
> include it in the main page. What else could it be?
> Sean
> <% @.Import Namespace="System.Data" %>
> <% @.Import Namespace="System.Data.SqlClient" %>
> <% @.Import Namespace="System.Web.UI.WebControls.DropDownList" %>
> <%@. Import Namespace="System.Web.UI.WebControls.CheckBox" %>
> <%@. Register TagPrefix="UserControl2" TagName="PlaceHeader"
> src="http://pics.10026.com/?src=includes/_placelistingsuser_header.ascx" %>
> <%@. Register TagPrefix="UserControl3" TagName="Control"
> src="http://pics.10026.com/?src=includes/_control_content.ascx" %>
> <%@. Register TagPrefix="UserControl4" TagName="FormList"
> src="http://pics.10026.com/?src=includes/_formlist_content.ascx" %>
> <link rel="stylesheet" type="text/css" href="http://links.10026.com/?link=>
> <script language="vb" runat="server">
>
> </script>
>
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> <meta name="distribution" content="global">
> <meta name="revisit-after" content="14 days">
> <meta name="ROBOTS" content="ALL">
> <title>title</title>
> </head>
> <form enctype="multipart/form-data" runat="server">
> <body topmargin="0" marginheight="0" marginwidth="0">
> <table width="100%" border="0" cellpadding="0" cellspacing="0">
> <td colspan="2" valign=top><UserControl2:PlaceHeader runat="server"
> /></td>
> <tr>
> <td width="563" valign=top style="padding-left:40px "><div align=left
> class=formtext sty style="padding-left:8px
"></div><br><UserControl3:Control
> runat="server" /></td>
> <td>2</td>
> </tr>
> <TR>
> <td colspan=2> </td>
> <td>
> </tr>
> </table>
> </form>
> </body>
> </html>
>
> "S. Justin Gengo" <sjgengo@.aboutfortunate[no-spam].com> wrote in message
> news:10gu5g8q5cnksf0@.corp.supernews.com...
> > Moe,
> > No, that looks good. It shouldn't make a difference that it's in a user
> > control.
> > Are you adding the user control to the page dynamically?
> > --
> > Sincerely,
> > S. Justin Gengo, MCP
> > Web Developer / Programmer
> > www.aboutfortunate.com
> > "Out of chaos comes order."
> > Nietzsche
> > "Moe Sizlak" <moe@.moe.com> wrote in message
> > news:e%23ckR9QeEHA.3684@.TK2MSFTNGP09.phx.gbl...
> > > Hi Justin,
> > > > I have the listmenu on the page and I do make sure that the menu is
> > selected
> > > before clicking the button, the load sud where I bind the list is in
the
> > > user control. Would this make a difference?
> > > > Moe
> > > > Sub Page_Load(byVal obj As Object, byVal e As EventArgs)
> > > If Not Page.IsPostBack Then
> > > lstS.DataSource = CommonFunctions.BindStates
> > > lstS.DataBind()
> > > lstS.Items.Insert(0, new ListItem("By State","0"))
> > > End If
> > > End Sub
> > > > > "S. Justin Gengo" <sjgengo@.aboutfortunate[no-spam].com> wrote in
message
> > > news:10gu2o4t1gmb294@.corp.supernews.com...
> > > > Moe,
> > > > > > First I am assuming that you aren't trying to repsponse.write the
> value
> > > > until after it's selected. You'll get the object reference error
right
> > > away
> > > > otherwise since no value has been selected yet.
> > > > > > Second, you need to make certain that the code populating the list
> only
> > > > fires on page load. If not, it is resetting the list every time. Do
> this
> > > > with the following if then:
> > > > > > If Not Page.IsPostBack Then
> > > > '--Populate list only once here
> > > > End If
> > > > > > > > --
> > > > Sincerely,
> > > > > > S. Justin Gengo, MCP
> > > > Web Developer / Programmer
> > > > > > www.aboutfortunate.com
> > > > > > "Out of chaos comes order."
> > > > Nietzsche
> > > > "Moe Sizlak" <moe@.moe.com> wrote in message
> > > > news:%23LjercQeEHA.3552@.tk2msftngp13.phx.gbl...
> > > > > Hi There,
> > > > > > > > I am trying to write the selected value of a listcontrol when a
> button
> > > is
> > > > > clicked and I keep getting the error "object not set to a
reference
> of
> > > an
> > > > > object". The libox itself is in a usercontrol and all i'm really
> > needing
> > > > to
> > > > > do is get the selected value when the button is clicked on the
form.
> > > > > > > > Can someone tell what I need to include in my page to get this
> working
> > ?
> > > > > > > > Moe <><
> > > > > > > > !-- response.write
> > > > > > > > response.write (lstS.selectedItem.tostring())
> > > > > > > > response.end
> > > > > > > > > > > !-- class function
> > > > > > > > Public Class CommonFunctions
> > > > > Public Shared Function BindStates() as SqlDataReader
> > > > > > > > Dim myConnection as New
> > > SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
> > > > > Const strSQL as String = "SELECT LocationID,
Location
> > AS
> > > > > Location " & _
> > > > > "FROM tbLocation
ORDER
> BY
> > > > > Location"
> > > > > Dim myCommand as New SqlCommand(strSQL, myConnection)
> > > > > myConnection.Open()
> > > > > Dim objDR as SqlDataReader
> > > > > objDR =
> > > myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
> > > > > Return objDr
> > > > > End Function
> > > > > End Class
> > > > > > > > !-- bind the contro
> > > > > > > > lstS.DataSource = CommonFunctions.BindStates
> > > > > lstS.DataBind()
> > > > > lstS.Items.Insert(0, new ListItem("By State","0"))
> > > > > > > > !- lisbox on page
> > > > > > > > <asp:listbox id="lstS" runat="server" rows=1
> > > > > DataTextField="Location"
> DataValueField="LocationID"/>
> > > > > > > > > > > >
Moe,

Are you trying to response.write the value from the user control itself or
from the page the control is on?

If you are trying to write it from the page the control is on you can't
refer to it directly. You have to refer to it through the user control
itself.

You could do this two ways:

One would be to just response.write the value from the control itself using
the data list's OnSelectedValueChanged handler

The other would be to use FindControl on the main page to get a reference to
the user control object and then use that to refer to the datalist.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Moe Sizlak" <moe@.moe.com> wrote in message
news:eDpjmkReEHA.3916@.TK2MSFTNGP11.phx.gbl...
> Hi Justin,
> Any other ideas? have a forgotten to declare something in my page?
>
>
> "Moe Sizlak" <moe@.moe.com> wrote in message
> news:uD27XQReEHA.2848@.TK2MSFTNGP10.phx.gbl...
> > Hi Justin,
> > The control I am using is "includes/_control_content.ascx" and I just
> > include it in the main page. What else could it be?
> > Sean
> > <% @.Import Namespace="System.Data" %>
> > <% @.Import Namespace="System.Data.SqlClient" %>
> > <% @.Import Namespace="System.Web.UI.WebControls.DropDownList" %>
> > <%@. Import Namespace="System.Web.UI.WebControls.CheckBox" %>
> > <%@. Register TagPrefix="UserControl2" TagName="PlaceHeader"
> > src="http://pics.10026.com/?src=includes/_placelistingsuser_header.ascx" %>
> > <%@. Register TagPrefix="UserControl3" TagName="Control"
> > src="http://pics.10026.com/?src=includes/_control_content.ascx" %>
> > <%@. Register TagPrefix="UserControl4" TagName="FormList"
> > src="http://pics.10026.com/?src=includes/_formlist_content.ascx" %>
> > <link rel="stylesheet" type="text/css" href="http://links.10026.com/?link=>
> > <script language="vb" runat="server">
> > </script>
> > <html>
> > <head>
> > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> > <meta name="distribution" content="global">
> > <meta name="revisit-after" content="14 days">
> > <meta name="ROBOTS" content="ALL">
> > <title>title</title>
> > </head>
> > <form enctype="multipart/form-data" runat="server">
> > <body topmargin="0" marginheight="0" marginwidth="0">
> > <table width="100%" border="0" cellpadding="0" cellspacing="0">
> > <td colspan="2" valign=top><UserControl2:PlaceHeader runat="server"
> > /></td>
> > <tr>
> > <td width="563" valign=top style="padding-left:40px "><div
align=left
> > class=formtext sty style="padding-left:8px
> "></div><br><UserControl3:Control
> > runat="server" /></td>
> > <td>2</td>
> > </tr>
> > <TR>
> > <td colspan=2> </td>
> > <td>
> > </tr>
> > </table>
> > </form>
> > </body>
> > </html>
> > "S. Justin Gengo" <sjgengo@.aboutfortunate[no-spam].com> wrote in message
> > news:10gu5g8q5cnksf0@.corp.supernews.com...
> > > Moe,
> > > > No, that looks good. It shouldn't make a difference that it's in a
user
> > > control.
> > > > Are you adding the user control to the page dynamically?
> > > > --
> > > Sincerely,
> > > > S. Justin Gengo, MCP
> > > Web Developer / Programmer
> > > > www.aboutfortunate.com
> > > > "Out of chaos comes order."
> > > Nietzsche
> > > "Moe Sizlak" <moe@.moe.com> wrote in message
> > > news:e%23ckR9QeEHA.3684@.TK2MSFTNGP09.phx.gbl...
> > > > Hi Justin,
> > > > > > I have the listmenu on the page and I do make sure that the menu is
> > > selected
> > > > before clicking the button, the load sud where I bind the list is in
> the
> > > > user control. Would this make a difference?
> > > > > > Moe
> > > > > > Sub Page_Load(byVal obj As Object, byVal e As EventArgs)
> > > > If Not Page.IsPostBack Then
> > > > lstS.DataSource = CommonFunctions.BindStates
> > > > lstS.DataBind()
> > > > lstS.Items.Insert(0, new ListItem("By State","0"))
> > > > End If
> > > > End Sub
> > > > > > > > "S. Justin Gengo" <sjgengo@.aboutfortunate[no-spam].com> wrote in
> message
> > > > news:10gu2o4t1gmb294@.corp.supernews.com...
> > > > > Moe,
> > > > > > > > First I am assuming that you aren't trying to repsponse.write the
> > value
> > > > > until after it's selected. You'll get the object reference error
> right
> > > > away
> > > > > otherwise since no value has been selected yet.
> > > > > > > > Second, you need to make certain that the code populating the list
> > only
> > > > > fires on page load. If not, it is resetting the list every time.
Do
> > this
> > > > > with the following if then:
> > > > > > > > If Not Page.IsPostBack Then
> > > > > '--Populate list only once here
> > > > > End If
> > > > > > > > > > > --
> > > > > Sincerely,
> > > > > > > > S. Justin Gengo, MCP
> > > > > Web Developer / Programmer
> > > > > > > > www.aboutfortunate.com
> > > > > > > > "Out of chaos comes order."
> > > > > Nietzsche
> > > > > "Moe Sizlak" <moe@.moe.com> wrote in message
> > > > > news:%23LjercQeEHA.3552@.tk2msftngp13.phx.gbl...
> > > > > > Hi There,
> > > > > > > > > > I am trying to write the selected value of a listcontrol when a
> > button
> > > > is
> > > > > > clicked and I keep getting the error "object not set to a
> reference
> > of
> > > > an
> > > > > > object". The libox itself is in a usercontrol and all i'm really
> > > needing
> > > > > to
> > > > > > do is get the selected value when the button is clicked on the
> form.
> > > > > > > > > > Can someone tell what I need to include in my page to get this
> > working
> > > ?
> > > > > > > > > > Moe <><
> > > > > > > > > > !-- response.write
> > > > > > > > > > response.write (lstS.selectedItem.tostring())
> > > > > > > > > > response.end
> > > > > > > > > > > > > > !-- class function
> > > > > > > > > > Public Class CommonFunctions
> > > > > > Public Shared Function BindStates() as SqlDataReader
> > > > > > > > > > Dim myConnection as New
> > > > > SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
> > > > > > Const strSQL as String = "SELECT LocationID,
> Location
> > > AS
> > > > > > Location " & _
> > > > > > "FROM tbLocation
> ORDER
> > BY
> > > > > > Location"
> > > > > > Dim myCommand as New SqlCommand(strSQL, myConnection)
> > > > > > myConnection.Open()
> > > > > > Dim objDR as SqlDataReader
> > > > > > objDR =
> > > > myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
> > > > > > Return objDr
> > > > > > End Function
> > > > > > End Class
> > > > > > > > > > !-- bind the contro
> > > > > > > > > > lstS.DataSource = CommonFunctions.BindStates
> > > > > > lstS.DataBind()
> > > > > > lstS.Items.Insert(0, new ListItem("By State","0"))
> > > > > > > > > > !- lisbox on page
> > > > > > > > > > <asp:listbox id="lstS" runat="server" rows=1
> > > > > > DataTextField="Location"
> > DataValueField="LocationID"/>
> > > > > > > > > > > > > > > > > > > >
Hi Justin,

I am trying to use the response.write from the user control itself, I
managed to create a class in a code behind then reference the control in the
usercontrol page. The control displays correctly but when I try to catch the
value from the listbox it gives me the message "text is not a member of
string". I know that I'm almost there!!

Once I have the basic framework with this piece of code I will be able to
rollon from there.

Sean

"S. Justin Gengo" <sjgengo@.aboutfortunate[no-spam].com> wrote in message
news:10gv3867d7uot23@.corp.supernews.com...
> Moe,
> Are you trying to response.write the value from the user control itself or
> from the page the control is on?
> If you are trying to write it from the page the control is on you can't
> refer to it directly. You have to refer to it through the user control
> itself.
> You could do this two ways:
> One would be to just response.write the value from the control itself
using
> the data list's OnSelectedValueChanged handler
> The other would be to use FindControl on the main page to get a reference
to
> the user control object and then use that to refer to the datalist.
> --
> Sincerely,
> S. Justin Gengo, MCP
> Web Developer / Programmer
> www.aboutfortunate.com
> "Out of chaos comes order."
> Nietzsche
> "Moe Sizlak" <moe@.moe.com> wrote in message
> news:eDpjmkReEHA.3916@.TK2MSFTNGP11.phx.gbl...
> > Hi Justin,
> > Any other ideas? have a forgotten to declare something in my page?
> > "Moe Sizlak" <moe@.moe.com> wrote in message
> > news:uD27XQReEHA.2848@.TK2MSFTNGP10.phx.gbl...
> > > Hi Justin,
> > > > The control I am using is "includes/_control_content.ascx" and I just
> > > include it in the main page. What else could it be?
> > > > Sean
> > > > <% @.Import Namespace="System.Data" %>
> > > <% @.Import Namespace="System.Data.SqlClient" %>
> > > <% @.Import Namespace="System.Web.UI.WebControls.DropDownList" %>
> > > <%@. Import Namespace="System.Web.UI.WebControls.CheckBox" %>
> > > <%@. Register TagPrefix="UserControl2" TagName="PlaceHeader"
> > > src="http://pics.10026.com/?src=includes/_placelistingsuser_header.ascx" %>
> > > <%@. Register TagPrefix="UserControl3" TagName="Control"
> > > src="http://pics.10026.com/?src=includes/_control_content.ascx" %>
> > > <%@. Register TagPrefix="UserControl4" TagName="FormList"
> > > src="http://pics.10026.com/?src=includes/_formlist_content.ascx" %>
> > > <link rel="stylesheet" type="text/css" href="http://links.10026.com/?link=>
> > > <script language="vb" runat="server">
> > > > > > </script>
> > > > > <html>
> > > <head>
> > > <meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
> > > <meta name="distribution" content="global">
> > > <meta name="revisit-after" content="14 days">
> > > <meta name="ROBOTS" content="ALL">
> > > > <title>title</title>
> > > </head>
> > > <form enctype="multipart/form-data" runat="server">
> > > <body topmargin="0" marginheight="0" marginwidth="0">
> > > <table width="100%" border="0" cellpadding="0" cellspacing="0">
> > > <td colspan="2" valign=top><UserControl2:PlaceHeader
runat="server"
> > > /></td>
> > > <tr>
> > > <td width="563" valign=top style="padding-left:40px "><div
> align=left
> > > class=formtext sty style="padding-left:8px
> > "></div><br><UserControl3:Control
> > > runat="server" /></td>
> > > <td>2</td>
> > > </tr>
> > > > <TR>
> > > <td colspan=2> </td>
> > > <td>
> > > </tr>
> > > </table>
> > > </form>
> > > </body>
> > > </html>
> > > > > > "S. Justin Gengo" <sjgengo@.aboutfortunate[no-spam].com> wrote in
message
> > > news:10gu5g8q5cnksf0@.corp.supernews.com...
> > > > Moe,
> > > > > > No, that looks good. It shouldn't make a difference that it's in a
> user
> > > > control.
> > > > > > Are you adding the user control to the page dynamically?
> > > > > > --
> > > > Sincerely,
> > > > > > S. Justin Gengo, MCP
> > > > Web Developer / Programmer
> > > > > > www.aboutfortunate.com
> > > > > > "Out of chaos comes order."
> > > > Nietzsche
> > > > "Moe Sizlak" <moe@.moe.com> wrote in message
> > > > news:e%23ckR9QeEHA.3684@.TK2MSFTNGP09.phx.gbl...
> > > > > Hi Justin,
> > > > > > > > I have the listmenu on the page and I do make sure that the menu
is
> > > > selected
> > > > > before clicking the button, the load sud where I bind the list is
in
> > the
> > > > > user control. Would this make a difference?
> > > > > > > > Moe
> > > > > > > > Sub Page_Load(byVal obj As Object, byVal e As EventArgs)
> > > > > If Not Page.IsPostBack Then
> > > > > lstS.DataSource = CommonFunctions.BindStates
> > > > > lstS.DataBind()
> > > > > lstS.Items.Insert(0, new ListItem("By State","0"))
> > > > > End If
> > > > > End Sub
> > > > > > > > > > > "S. Justin Gengo" <sjgengo@.aboutfortunate[no-spam].com> wrote in
> > message
> > > > > news:10gu2o4t1gmb294@.corp.supernews.com...
> > > > > > Moe,
> > > > > > > > > > First I am assuming that you aren't trying to repsponse.write
the
> > > value
> > > > > > until after it's selected. You'll get the object reference error
> > right
> > > > > away
> > > > > > otherwise since no value has been selected yet.
> > > > > > > > > > Second, you need to make certain that the code populating the
list
> > > only
> > > > > > fires on page load. If not, it is resetting the list every time.
> Do
> > > this
> > > > > > with the following if then:
> > > > > > > > > > If Not Page.IsPostBack Then
> > > > > > '--Populate list only once here
> > > > > > End If
> > > > > > > > > > > > > > --
> > > > > > Sincerely,
> > > > > > > > > > S. Justin Gengo, MCP
> > > > > > Web Developer / Programmer
> > > > > > > > > > www.aboutfortunate.com
> > > > > > > > > > "Out of chaos comes order."
> > > > > > Nietzsche
> > > > > > "Moe Sizlak" <moe@.moe.com> wrote in message
> > > > > > news:%23LjercQeEHA.3552@.tk2msftngp13.phx.gbl...
> > > > > > > Hi There,
> > > > > > > > > > > > I am trying to write the selected value of a listcontrol when
a
> > > button
> > > > > is
> > > > > > > clicked and I keep getting the error "object not set to a
> > reference
> > > of
> > > > > an
> > > > > > > object". The libox itself is in a usercontrol and all i'm
really
> > > > needing
> > > > > > to
> > > > > > > do is get the selected value when the button is clicked on the
> > form.
> > > > > > > > > > > > Can someone tell what I need to include in my page to get this
> > > working
> > > > ?
> > > > > > > > > > > > Moe <><
> > > > > > > > > > > > !-- response.write
> > > > > > > > > > > > response.write (lstS.selectedItem.tostring())
> > > > > > > > > > > > response.end
> > > > > > > > > > > > > > > > > !-- class function
> > > > > > > > > > > > Public Class CommonFunctions
> > > > > > > Public Shared Function BindStates() as SqlDataReader
> > > > > > > > > > > > Dim myConnection as New
> > > > > > > SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
> > > > > > > Const strSQL as String = "SELECT LocationID,
> > Location
> > > > AS
> > > > > > > Location " & _
> > > > > > > "FROM tbLocation
> > ORDER
> > > BY
> > > > > > > Location"
> > > > > > > Dim myCommand as New SqlCommand(strSQL,
myConnection)
> > > > > > > myConnection.Open()
> > > > > > > Dim objDR as SqlDataReader
> > > > > > > objDR =
> > > > > myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
> > > > > > > Return objDr
> > > > > > > End Function
> > > > > > > End Class
> > > > > > > > > > > > !-- bind the contro
> > > > > > > > > > > > lstS.DataSource = CommonFunctions.BindStates
> > > > > > > lstS.DataBind()
> > > > > > > lstS.Items.Insert(0, new ListItem("By State","0"))
> > > > > > > > > > > > !- lisbox on page
> > > > > > > > > > > > <asp:listbox id="lstS" runat="server" rows=1
> > > > > > > DataTextField="Location"
> > > DataValueField="LocationID"/>
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
Hi.

Did anyone manage to find the solution to this problem?

I'm having a similar issue with populating a drop-down list menu from
a SQLDataReader.

Here is my function:-

Function SelectOptions(ByVal queryString) As
System.Data.SqlClient.SqlDataReader
' Application("ConnectionString") is set in our global.asax file

Dim sqlConnection As System.Data.SqlClient.SqlConnection = New
System.Data.SqlClient.SqlConnection(Application("ConnectionString"))

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

sqlConnection.Open()
Dim dataReader As System.Data.SqlClient.SqlDataReader =
sqlCommand.ExecuteReader(System.Data.CommandBehavi or.CloseConnection)

Return dataReader
End Function

If I call this function directly in my aspx page it works fine, no
problem.

However, if i attempt to call it via my own custom web user control
ascx page, it causes a "Object reference not set to an instance of an
object." error.

Here is my non-working code:-

Dim func As New CommonFunctions
dropdownlist.DataSource = func.SelectOptions("SELECT colname FROM
table")
dropdownlist.DataBind()

Any help is much appreciated.

Thanks in advance

Dan Williams.
It appears that my web user control didn't like my
Application("ConnectionString") setting.

As soon as i referenced it using
System.Web.HttpContext.Current.Application("connectionString"), it
worked straight away, no problem.

Cheers

Dan.

dan_williams@.newcross-nursing.com (Dan Williams) wrote in message news:<2eac5d02.0408250258.287751@.posting.google.com>...
> Hi.
> Did anyone manage to find the solution to this problem?
> I'm having a similar issue with populating a drop-down list menu from
> a SQLDataReader.
> Here is my function:-
> Function SelectOptions(ByVal queryString) As
> System.Data.SqlClient.SqlDataReader
> ' Application("ConnectionString") is set in our global.asax file
> Dim sqlConnection As System.Data.SqlClient.SqlConnection = New
> System.Data.SqlClient.SqlConnection(Application("ConnectionString"))
> Dim sqlCommand As System.Data.SqlClient.SqlCommand = New
> System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
> sqlConnection.Open()
> Dim dataReader As System.Data.SqlClient.SqlDataReader =
> sqlCommand.ExecuteReader(System.Data.CommandBehavi or.CloseConnection)
> Return dataReader
> End Function
> If I call this function directly in my aspx page it works fine, no
> problem.
> However, if i attempt to call it via my own custom web user control
> ascx page, it causes a "Object reference not set to an instance of an
> object." error.
> Here is my non-working code:-
> Dim func As New CommonFunctions
> dropdownlist.DataSource = func.SelectOptions("SELECT colname FROM
> table")
> dropdownlist.DataBind()
> Any help is much appreciated.
> Thanks in advance
> Dan Williams.