G
Guest
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.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
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
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.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
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