Group: Forum Members
Last Active: Tue 1 Apr 2014
Posts: 5,
Visits: 25
|
Hello all,
I need a way to be able to dynamically add products on a public (logged in user) page. I have created the page and copied much of the code from the Usercontrols/_EditProduct.ascx page to get the required functionality.
When I visit the page with ?ProductID=0, everything displays properly except the Name, Description, and Strapline textboxes were missing. I Added textbox fields for these. When I click the 'Save' button, nothing happens. In the log I get the error:
System.NullReferenceException: Object reference not set to an instance of an object. at _LanguageContainer.ReadContent() at Customerebooks.SaveProduct(DML_OPERATION enumOperation) at Customerebooks.btnSave_Click(Object sender, EventArgs e) at System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Here is my code: aspx page
<%@ Page Title="" Language="VB" MasterPageFile="~/Skins/Kartris/Template.master" AutoEventWireup="false" CodeFile="Customerebooks.aspx.vb" Inherits="Customerebooks" %> <%@ Register TagPrefix="_user" TagName="LanguageContainer" Src="~/UserControls/Back/_LanguageContainer.ascx" %> <%@ Register TagPrefix="_user" TagName="AutoComplete" Src="~/UserControls/Back/_AutoCompleteInput.ascx" %>
<asp:Content ID="cntMain" ContentPlaceHolderID="cntMain" runat="Server"> <div id="customer"> <user:BreadCrumbTrail ID="UC_BreadCrumbTrail" runat="server" EnableViewState="False" /> <h1>Your eBooks</h1> </div> <div class="changecustomercode section"> <h2> Add an eBook</h2> <p> <asp:UpdatePanel ID="updMain" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Literal ID="litProductID" runat="server" Visible="false" /> <asplaceHolder ID="phdNoCategories" runat="server" Visible="false"> <asp:Literal ID="litContentTextNoCategoriesInThisSite" runat="server" Text="<%$ Resources: _Kartris, ContentText_NoCategoriesInTheSite %>" /> </asplaceHolder> <asplaceHolder ID="phdEditProduct" runat="server"> <!-- Language Elements --> <div> <asp:UpdatePanel ID="updLanguageContainer" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asplaceHolder ID="phdLanguageContainer" runat="server" Visible="false"> <_user:LanguageContainer ID="_UC_LangContainer" runat="server" /> </asplaceHolder> </ContentTemplate> </asp:UpdatePanel> </div> <!-- Line --> <div class="line"> </div> <div class="Kartris-DetailsView"> <div class="Kartris-DetailsView-Data"> <ul> <li><span class="Kartris-DetailsView-Name"> Name </span> <span class="Kartris-DetailsView-Value"> <asp:TextBox name="txtValue" ID="txtValue_0" runat="server" class="elementname" /> </li> <li class="elementdesc"><span class="Kartris-DetailsView-Name"> Description </span> <span class="Kartris-DetailsView-Value"> <textarea name="txtValue" rows="2" cols="20" id="txtValue_1" class="elementdesc"> </textarea></li> <li class="elementstrapline"><span class="Kartris-DetailsView-Name"> Strapline </span> <span class="Kartris-DetailsView-Value"> <textarea name="txtStrap" rows="2" cols="20" id="txtStrap" class="elementstrapline"> </textarea></li> <li><span class="Kartris-DetailsView-Name"> <asp:Label ID="litContentTextCategoryParent" runat="server" Text="<%$ Resources: _Category, ContentText_CategoryParent %>"></asp:Label> </span><span class="Kartris-DetailsView-Value"> <asp:UpdatePanel ID="updProductCategories" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:ListBox ID="lbxProductCategories" runat="server"></asp:ListBox> <asp:LinkButton ID="lnkBtnRemoveProductCategory" class="linkbutton icon_delete" runat="server" Text='<%$ Resources:_Kartris, ContentText_RemoveSelected %>' /><br /> <_user:AutoComplete ID="_UC_AutoComplete" runat="server" MethodName="GetCategories" /> <asp:LinkButton ID="lnkBtnAddCategory" class="linkbutton icon_new" runat="server" Text='<%$ Resources:_Kartris, FormButton_Add %>' /><br /> </ContentTemplate> </asp:UpdatePanel> </span> </li> <% If litProductID.Text <> 0 Then%> <li> <!-- Date Created (P_DateCreated) --> <span class="Kartris-DetailsView-Name"> <asp:Literal ID="litFormLabelDateCreated" runat="server" Text="<%$ Resources: _Kartris, ContentText_DateCreated%>"></asp:Literal> </span><span class="Kartris-DetailsView-Value"> <asp:Literal ID="litDateCreated" runat="server"></asp:Literal> </span></li> <!-- Last Modified (P_LastModified) --> <li><span class="Kartris-DetailsView-Name"> <asp:Literal ID="litFormLabelLastModified" runat="server" Text="<%$ Resources: _Kartris, ContentText_LastUpdated %>"></asp:Literal> </span><span class="Kartris-DetailsView-Value"> <asp:Literal ID="litLastModified" runat="server"></asp:Literal> </span></li> <% End If%> <!-- LimitByGroup (CustomerGroupID) --> <li><span class="Kartris-DetailsView-Name"> <asp:Label ID="litContentText_LimitToCustomerGroup" runat="server" Text="<%$ Resources: _Category, ContentText_LimitToCustomerGroup %>" AssociatedControlID="ddlCustomerGroup" Visible="false" ></asp:Label> </span><span class="Kartris-DetailsView-Value"> <aspropDownList ID="ddlCustomerGroup" runat="server" AppendDataBoundItems="true" AutoPostBack="true" Visible="false" > <asp:ListItem Text="<%$ Resources: _Category, ContentText_AvailableToAll %>" Value="0"></asp:ListItem> </aspropDownList> </span></li> <li><span class="Kartris-DetailsView-Name"> <asp:Label ID="litContentTextProductType" runat="server" Text="<%$ Resources: _Product, ContentText_ProductType %>" AssociatedControlID="ddlProductType"></asp:Label> </span><span class="Kartris-DetailsView-Value"> <asp:UpdatePanel ID="updProductType" runat="server" UpdateMode="Conditional"> <ContentTemplate> <aspropDownList ID="ddlProductType" runat="server" AutoPostBack="True"> <asp:ListItem Text="<%$ Resources: _Product, ContentText_ProductTypeSingleVersionDisplay %>" Value="s"></asp:ListItem> <asp:ListItem Text="<%$ Resources: _Product, ContentText_ProductTypeMultipleVersionDisplay %>" Value="m"></asp:ListItem> <asp:ListItem Text="<%$ Resources: _Product, ContentText_ProductTypeOptionVersionDisplay %>" Value="o"></asp:ListItem> </aspropDownList></ContentTemplate> </asp:UpdatePanel> </span></li> <!-- Version Display Type (VersionDisplayType) --> <li><span class="Kartris-DetailsView-Name"> <asp:Label ID="litFormLabelVersionDisplayType" runat="server" Text="<%$ Resources: _Product, FormLabel_VersionDisplayType %>" AssociatedControlID="ddlVersionDisplay" Visible="false"></asp:Label> </span><span class="Kartris-DetailsView-Value"> <asp:UpdatePanel ID="updVersionDisplayType" runat="server" UpdateMode="Conditional" Visible="false"> <ContentTemplate> <aspropDownList ID="ddlVersionDisplay" runat="server" CssClass="longtext"> <asp:ListItem Text="<%$ Resources:_Product,ContentText_DefaultVerDisplayType %>" Value="d"></asp:ListItem> <asp:ListItem Text="<%$ Resources:_Product,ContentText_OptionPriceVerDisplayType %>" Value="p"></asp:ListItem> <asp:ListItem Text="<%$ Resources:_Product,ContentText_RowsVerDisplayType %>" Value="r"></asp:ListItem> <asp:ListItem Text="<%$ Resources:_Product,ContentText_OptionsVerDisplayType %>" Value="o"></asp:ListItem> <asp:ListItem Text="<%$ Resources:_Product,ContentText_NoneVerDisplayType %>" Value="l"></asp:ListItem> </aspropDownList></ContentTemplate> </asp:UpdatePanel> </span></li> </ul> </div> </div> <!-- Save Button --> <div id="updatebuttonbar" class="submitbuttons topsubmitbuttons"> <asp:UpdatePanel ID="updSaveChanges" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:LinkButton ID="btnSave" runat="server" CssClass="button savebutton" Text='<%$ Resources: _Kartris, FormButton_Save %>' ToolTip='<%$ Resources: _Kartris, FormButton_Save %>' /> <asp:LinkButton ID="btnCancel" runat="server" CssClass="button cancelbutton" Text='<%$ Resources: _Kartris, FormButton_Cancel %>' ToolTip='<%$ Resources: _Kartris, FormButton_Cancel %>' /> <asp:HyperLink ID="hlinkPreview" runat="server" CssClass="button previewbutton" Text='<%$ Resources: _Kartris, FormButton_Preview %>' Target="_blank" Visible="false" ToolTip='<%$ Resources: _Kartris, FormButton_Preview %>' /> <span class="floatright"> <asp:LinkButton ID="lnkBtnDelete" CssClass="button deletebutton" runat="server" Text='<%$ Resources: _Kartris, FormButton_Delete %>' ToolTip='<%$ Resources: _Product, ContentText_DeleteThisProduct %>' /></span> <asp:ValidationSummary ID="valSummary" runat="server" CssClass="valsummary" DisplayMode="BulletList" ForeColor="" HeaderText="<%$ Resources: _Kartris, ContentText_Errors %>" /> </ContentTemplate> </asp:UpdatePanel> </div> <asp:ListBox ID="lbxResult" runat="server" Visible="False"></asp:ListBox> <_useropupMessage ID="_UC_PopupMsg" runat="server" /> </asplaceHolder> </ContentTemplate> </asp:UpdatePanel> </p> </div> </asp:Content>
[/quote]
vb codebehind [quote]Imports CkartrisBLL Imports System.Web.HttpContext Imports CkartrisDataManipulation Imports CkartrisEnumerations Imports CkartrisDisplayFunctions Imports CkartrisImages Imports KartSettingsManager
Partial Class Customerebooks Inherits PageBaseClass
''' <summary> ''' raised when the product does not exist ''' </summary> ''' <remarks></remarks> Public Event ProductNotExist()
''' <summary> ''' raised when the product is saved ''' </summary> ''' <remarks></remarks> Public Event ProductSaved()
Public Event ProductUpdated(ByVal strNewName As String)
Private _ProductType As Char
Public ReadOnly Property GetProductType() As Char Get Return _ProductType End Get End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load btnSave.ValidationGroup = LANG_ELEM_TABLE_TYPE.Products valSummary.ValidationGroup = LANG_ELEM_TABLE_TYPE.Products
litProductID.Text = _GetProductID() If Not Page.IsPostBack Then AddParentCategory()
If Session("_tab") = "products" Then If ddlCustomerGroup.Items.Count <= 1 Then Dim drwCGs As DataRow() = GetCustomerGroupsFromCache.Select("CG_Live = 1 AND LANG_ID=" & Session("_LANG")) ddlCustomerGroup.DataTextField = "CG_Name" ddlCustomerGroup.DataValueField = "CG_ID" ddlCustomerGroup.DataSource = drwCGs ddlCustomerGroup.DataBind() End If ReloadProduct() End If CheckProductType() End Sub
Public Sub ReloadProduct() If _GetProductID() = 0 Then 'new product '' If there is no parent category, we should make sure that we have categories in the db. If _GetParentCategory() = 0 Then If CategoriesBLL._GetTotalCategoriesByLanguageID(Session("_LANG")) = 0 Then phdNoCategories.Visible = True phdEditProduct.Visible = False Else phdNoCategories.Visible = False phdEditProduct.Visible = True End If End If _UC_LangContainer.CreateLanguageStrings(LANG_ELEM_TABLE_TYPE.Products, True) lnkBtnDelete.Visible = False hlinkPreview.Visible = False Else _UC_LangContainer.CreateLanguageStrings(LANG_ELEM_TABLE_TYPE.Products, False, _GetProductID) If Not Page.IsPostBack Then LoadProductInfo() lnkBtnDelete.Visible = True hlinkPreview.NavigateUrl = "~/Product.aspx?ProductID=" & _GetProductID() hlinkPreview.Visible = True End If End Sub
''' <summary> ''' reads the parent category from the query string and add it to the parents' list ''' </summary> ''' <remarks></remarks> Private Sub AddParentCategory() Dim numParentCategoryID As Integer = 0 Try numParentCategoryID = _GetCategoryID() Catch ex As Exception ' End Try
lbxProductCategories.Items.Clear()
If numParentCategoryID <> 0 Then If lbxProductCategories.Items.FindByValue(CStr(numParentCategoryID)) Is Nothing Then lbxProductCategories.Items.Add( _ New ListItem(CategoriesBLL._GetNameByCategoryID(numParentCategoryID, Session("_LANG")), _ CStr(numParentCategoryID))) lbxProductCategories.SelectedIndex = lbxProductCategories.Items.Count - 1 End If End If
End Sub
''' <summary> ''' reads the product info from the db ''' </summary> ''' <remarks></remarks> Public Sub LoadProductInfo()
Dim tblProducts As New DataTable tblProducts = ProductsBLL._GetProductInfoByID(_GetProductID())
'' if no product returned "not exist in the db" If tblProducts.Rows.Count = 0 Then RaiseEvent ProductNotExist() : Exit Sub
'' ----------------------------------------- '' Load Product Main Info. into the contorls ddlVersionDisplay.SelectedValue = FixNullFromDB(tblProducts.Rows(0)("P_VersionDisplayType")) ddlProductType.SelectedValue = FixNullFromDB(tblProducts.Rows(0)("P_Type")) _ProductType = CChar(ddlProductType.SelectedValue)
Try ddlCustomerGroup.SelectedValue = FixNullFromDB(tblProducts.Rows(0)("P_CustomerGroupID")) ''Customer Group Catch ex As Exception ddlCustomerGroup.SelectedValue = "0" End Try
litDateCreated.Text = FormatDate(FixNullFromDB(tblProducts.Rows(0)("P_DateCreated")), "t", Session("_LANG")) litLastModified.Text = FormatDate(FixNullFromDB(tblProducts.Rows(0)("P_LastModified")), "t", Session("_LANG"))
'' -----------------------------------------
'' ----------------------------------------- '' checks the product's type to decide if it could be changed CheckProductType() '' -----------------------------------------
'' ----------------------------------------- '' Load Product's Parents into the 'Parent List' Dim tblProductCategories As New DataTable tblProductCategories = ProductsBLL._GetCategoriesByProductID(_GetProductID()) lbxProductCategories.Items.Clear() For Each row In tblProductCategories.Rows Dim itm As New ListItem itm.Value = CStr(FixNullFromDB(row("PCAT_CategoryID"))) itm.Text = CategoriesBLL._GetNameByCategoryID(CInt(itm.Value), Session("_LANG")) lbxProductCategories.Items.Add(itm) Next '' ----------------------------------------- updMain.Update() End Sub
''' <summary> ''' checking the product type, to decide if the product's type could be changed or no ''' - "Multiple Version" product with more than one version --> Not allowed ''' - "Option Product" --> Not allowed to be changed ''' </summary> ''' <remarks></remarks> Public Sub CheckProductType() ddlProductType.Enabled = True '' by default always allow the changes Select Case ddlProductType.SelectedValue Case "m" '' multiple version product If VersionsBLL._GetNoOfVersionsByProductID(_GetProductID()) > 1 Then ddlProductType.Enabled = False End If ddlVersionDisplay.Enabled = True 'Try to remove the 'options' display type Try ddlVersionDisplay.Items.Remove(ddlVersionDisplay.Items.FindByValue("o")) Catch ex As Exception 'Maybe failed because options type was 'selected, so reselect then try again ddlVersionDisplay.SelectedValue = "r" ddlVersionDisplay.Items.Remove(ddlVersionDisplay.Items.FindByValue("o")) End Try 'Try to remove the 'none' display type Try ddlVersionDisplay.Items.Remove(ddlVersionDisplay.Items.FindByValue("l")) Catch ex As Exception 'Maybe failed because options type was 'selected, so reselect then try again ddlVersionDisplay.SelectedValue = "r" ddlVersionDisplay.Items.Remove(ddlVersionDisplay.Items.FindByValue("l")) End Try Case "o" '' option product If VersionsBLL._GetNoOfVersionsByProductID(_GetProductID()) > 0 Then ddlProductType.Enabled = False End If
'Add options in Dim itmNew As New ListItem itmNew.Text = GetGlobalResourceObject("_Product", "ContentText_OptionsVerDisplayType") itmNew.Value = "o" itmNew.Selected = True ddlVersionDisplay.Items.Add(itmNew)
ddlVersionDisplay.SelectedValue = "o" ddlVersionDisplay.Enabled = False Case "s" '' single version product 'Add 'none' in Dim itmNew As New ListItem itmNew.Text = GetGlobalResourceObject("_Product", "ContentText_NoneVerDisplayType") itmNew.Value = "l" itmNew.Selected = True ddlVersionDisplay.Items.Add(itmNew)
ddlVersionDisplay.SelectedValue = "l" ddlVersionDisplay.Enabled = False End Select End Sub
''' <summary> ''' checks product type and adjusts other menus accordingly ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> ''' <remarks></remarks> Protected Sub ddlProductType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlProductType.SelectedIndexChanged CheckProductType() updProductType.Update() updVersionDisplayType.Update() End Sub
''' <summary> ''' used to reset the original info. from the db ''' </summary> ''' <remarks></remarks> Private Sub ResetChanges() '' 1. reset the controls '' 2. reset the language elements ... (clear the controls) '' 3. reads the language elements for the current category '' 4. loads the product info. from db
ddlVersionDisplay.SelectedIndex = 0 ddlCustomerGroup.SelectedIndex = 0 ddlProductType.SelectedIndex = 0 ddlProductType.Enabled = True litDateCreated.Text = Nothing litLastModified.Text = Nothing
_UC_LangContainer.CreateLanguageStrings(LANG_ELEM_TABLE_TYPE.Products, True) _UC_LangContainer.CreateLanguageStrings(LANG_ELEM_TABLE_TYPE.Products, False, _GetProductID())
updMain.Update() LoadProductInfo() End Sub
''' <summary> ''' adds the selected category from autocomplete list to the parents' list ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> ''' <remarks></remarks> Protected Sub lnkBtnAddCategory_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkBtnAddCategory.Click Try Dim strCategoryText As String = _UC_AutoComplete.GetText() If strCategoryText <> "" Then Dim numCategoryID As Integer = CInt(Mid(strCategoryText, strCategoryText.LastIndexOf("(") + 2, strCategoryText.LastIndexOf(")") - strCategoryText.LastIndexOf("(") - 1)) Dim strCategoryName As String = CategoriesBLL._GetNameByCategoryID(numCategoryID, Session("_LANG")) If Not strCategoryName Is Nothing Then If lbxProductCategories.Items.FindByValue(CStr(numCategoryID)) Is Nothing Then lbxProductCategories.Items.Add(New ListItem(strCategoryName, CStr(numCategoryID))) lbxProductCategories.SelectedIndex = lbxProductCategories.Items.Count - 1 End If Else _UC_PopupMsg.ShowConfirmation(MESSAGE_TYPE.ErrorMessage, GetGlobalResourceObject("_Kartris", "ContentText_InvalidCategory")) End If End If Catch ex As Exception _UC_PopupMsg.ShowConfirmation(MESSAGE_TYPE.ErrorMessage, GetGlobalResourceObject("_Kartris", "ContentText_InvalidCategory")) Finally _UC_AutoComplete.ClearText() _UC_AutoComplete.SetFoucs() End Try
End Sub
''' <summary> ''' removes the selected parent category from the parents' list ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> ''' <remarks></remarks> Protected Sub lnkBtnRemoveProductCategory_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkBtnRemoveProductCategory.Click Dim selectedIndx As Integer = lbxProductCategories.SelectedIndex If selectedIndx >= 0 Then lbxProductCategories.Items.RemoveAt(selectedIndx) If lbxProductCategories.Items.Count >= selectedIndx Then lbxProductCategories.SelectedIndex = selectedIndx - 1 Else If lbxProductCategories.Items.Count <> 0 Then lbxProductCategories.SelectedIndex = lbxProductCategories.Items.Count - 1 End If End If End If End Sub
''' <summary> ''' saving the changes ''' - (update for the existing product) ''' - (insert for the new product) ''' Steps: ''' 1. read the Language Elements of the product to save them. ''' 2. read the parents' cat. to be saved in the product category link. ''' 3. read the main product info. ''' 4. save the changes (update/insert) ''' INSERT --> redirect the page with the new changes ''' UPDATE --> rais the product saved event ''' </summary> ''' <param name="enumOperation"></param> ''' <remarks></remarks> Private Sub SaveProduct(ByVal enumOperation As DML_OPERATION)
'' double check if any parent category is selected If lbxProductCategories.Items.Count = 0 Then _UC_PopupMsg.ShowConfirmation(MESSAGE_TYPE.ErrorMessage, GetGlobalResourceObject("_Category", "ContentText_SelectParentCategory")) Exit Sub End If
Dim tblLanguageContents As New DataTable() Dim sbdParentsList As New StringBuilder("") Dim blnLive As Boolean, chrVersionDisplayType As Char, chrReviews As Char, chrType As Char Dim numSupplier As Integer, numCustomerGroup As Integer, numFeatured As Byte Dim strOrderVersionsBy As String, chrVersionsSortDirection As Char
''^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ''^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ '' 1. Language Contents
tblLanguageContents = _UC_LangContainer.ReadContent()
''^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ''^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
''^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ''^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ '' 2. Parents List For Each itm As ListItem In lbxProductCategories.Items sbdParentsList.Append(itm.Value) sbdParentsList.Append(",") Next ''^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ''^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
''^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ''^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ '' 3. Product Main Info. blnLive = True
numFeatured = 0
strOrderVersionsBy = "Default ('frontend.versions.display.sortdefault' config setting)" chrVersionsSortDirection = "Ascending" chrReviews = "Enabled" chrVersionDisplayType = CChar(ddlVersionDisplay.SelectedValue()) numSupplier = CurrentLoggedUser.ID.ToString chrType = CChar(ddlProductType.SelectedValue()) Try numCustomerGroup = CInt(ddlCustomerGroup.SelectedValue()) Catch ex As Exception numCustomerGroup = 0 End Try
''^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ''^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Dim strMessage As String = "" Dim intProductID As Integer = _GetProductID() Select Case enumOperation Case DML_OPERATION.UPDATE If Not ProductsBLL._UpdateProduct( _ tblLanguageContents, sbdParentsList.ToString, intProductID, blnLive, numFeatured, _ strOrderVersionsBy, chrVersionsSortDirection, chrReviews, chrVersionDisplayType, numSupplier, chrType, numCustomerGroup, strMessage) Then _UC_PopupMsg.ShowConfirmation(MESSAGE_TYPE.ErrorMessage, strMessage) Exit Sub End If Dim rowLanguageContents As DataRow() = tblLanguageContents.Select("_LE_LanguageID=" & Session("_LANG") & " AND _LE_FieldID = " & LANG_ELEM_FIELD_NAME.Name) If rowLanguageContents.Length > 0 Then RaiseEvent ProductUpdated(CStr(rowLanguageContents(0)("_LE_Value"))) RaiseEvent ProductSaved() Case DML_OPERATION.INSERT If Not ProductsBLL._AddProduct( _ tblLanguageContents, sbdParentsList.ToString, intProductID, blnLive, numFeatured, _ strOrderVersionsBy, chrVersionsSortDirection, chrReviews, chrVersionDisplayType, numSupplier, chrType, numCustomerGroup, strMessage) Then _UC_PopupMsg.ShowConfirmation(MESSAGE_TYPE.ErrorMessage, strMessage) Exit Sub End If RefreshNewestProductsCache() If lbxProductCategories.Items.Count >= 1 Then If _GetCategoryID() <> 0 Then Response.Redirect("~/Admin/_ModifyProduct.aspx?ProductID=" & intProductID & "&CategoryID=" & _GetCategoryID() & "&strParent=" & _GetParentCategory()) Else Try Response.Redirect("~/Admin/_ModifyProduct.aspx?ProductID=" & intProductID & "&CategoryID=" & lbxProductCategories.Items(0).Value & "&strParent=" & CategoriesBLL._GetParentsByID(Session("_lang"), lbxProductCategories.Items(0).Value).Rows(0)("ParentID").ToString()) Catch ex As Exception Response.Redirect("~/Admin/_ModifyProduct.aspx?ProductID=" & intProductID & "&CategoryID=" & lbxProductCategories.Items(0).Value) End Try End If Else Response.Redirect("~/Admin/_ModifyProduct.aspx?ProductID=" & intProductID) End If End Select RefreshFeaturedProductsCache()
End Sub
''' <summary> ''' if the delete is confirmed, "Yes" is chosen ''' </summary> ''' <remarks></remarks> Protected Sub _UC_PopupMsg_Confirmed() Handles _UC_PopupMsg.Confirmed Dim strMessage As String = "" If ProductsBLL._DeleteProduct(_GetProductID(), strMessage) Then RefreshFeaturedProductsCache() If GetKartConfig("backend.files.delete.cleanup ") = "y" Then KartrisDBBLL.DeleteNotNeededFiles() Response.Redirect("~/Admin/_Category.aspx?CategoryID=" & _GetParentCategory()) Else _UC_PopupMsg.ShowConfirmation(MESSAGE_TYPE.ErrorMessage, strMessage) End If End Sub
''' <summary> ''' handles the save button being clicked ''' </summary> ''' <remarks></remarks> Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
If _GetProductID() = 0 Then '' on new SaveProduct(DML_OPERATION.INSERT) Else '' on update SaveProduct(DML_OPERATION.UPDATE) End If
End Sub
''' <summary> ''' handles the cancel button being clicked ''' </summary> ''' <remarks></remarks> Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click If _GetProductID() = 0 Then '' on new Response.Redirect("~/Admin/_Category.aspx?CategoryId=" & _GetParentCategory()) Else '' on update ResetChanges() End If End Sub
''' <summary> ''' handles the delete linkbutton being clicked ''' </summary> ''' <remarks></remarks> Protected Sub lnkBtnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkBtnDelete.Click Dim strMessage As String = Replace(GetGlobalResourceObject("_Kartris", "ContentText_ConfirmDeleteItem"), "[itemname]", _ ProductsBLL._GetNameByProductID(_GetProductID(), Session("_LANG"))) _UC_PopupMsg.ShowConfirmation(MESSAGE_TYPE.Confirmation, strMessage) End Sub
Protected Sub ddlCustomerGroup_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCustomerGroup.SelectedIndexChanged End Sub End Class
I believe the error is coming from vb line 332 "tblLanguageContents = _UC_LangContainer.ReadContent()"
I'm guessing the built in name, description, and strapline textboxes are in the LangContainer so since mine are not displaying, it cannot read the contents and thus returns null. How can I correct this?
Thank you all!
|
Group: Administrators
Last Active: Tue 10 Sep 2024
Posts: 807,
Visits: 2,748
|
The language container is for fields that are language specific. These appear in a tabbed dialog, one tab for each language. In this way, creating or editing things such as products incorporates multiple fields for product name, etc. if there is more than one language.
I am not sure really from looking at your code why the language boxes don't display, but it's vital to get those working correctly and displaying because updating products without those is going to be hard because all our code is based around having those.
Another solution might be to consider using the web API to create products? You would then have more freedom to design your own form, and then make web service post to create or edit the product.
-- If my post solves your issue, can you 'Mark as Answer' so it's easier for other users to find in future.
If you would like to be informed of new features, new releases, developments and occasional special bonuses, please sign up to our mailing list: http://bit.ly/19sKMZb
|
Group: Forum Members
Last Active: Tue 1 Apr 2014
Posts: 5,
Visits: 25
|
Thank you Paul,
I dug a bit deeper in the _LanguageContainer code and realized that was an integral part to getting the form to post. Just can't figure out why it isn't displaying.
If I were to try the API route, what method would I need to call? What are the parameter formats/values?
Thanks again!
|
Group: Forum Members
Last Active: Tue 1 Apr 2014
Posts: 5,
Visits: 25
|
I am using essentially the exact code from usercontrols/_EditProducts.ascx
The only differences are - I'm inheriting PageBaseClass instead of System.Web.UI.UserControl
- I have the code in a aspx page that uses the site skin as a Masterpage
Could either of these make a difference?
|
Group: Forum Members
Last Active: Tue 1 Apr 2014
Posts: 5,
Visits: 25
|
Ok, so it look like to do this via the WebAPI, I need to call this function: Public Shared Function _AddProduct(ByVal ptblElements As DataTable, ByVal pParentsList As String, _ ByRef pProductID As Integer, ByVal pLive As Boolean, ByVal pFeatured As Byte, _ ByVal pOrderVersionsBy As String, ByVal pVersionsSortDirection As Char, _ ByVal pReviews As Char, ByVal pVersionDisplayType As Char, ByVal pSupplier As Integer, _ ByVal pProductType As Char, ByVal pCustomerGroupID As Integer, ByRef strMsg As String) As Boolean
so I would use. strMethodName = "ProductsBLL._AddProduct"? And my strParametersXML would need a value for every parameter listed in the function?
My problem remains with the language Contents. What is in the ptblElements Datatable so that I can recreate it to pass in the XML Parameter?
|
Group: Forum Members
Last Active: Tue 1 Apr 2014
Posts: 5,
Visits: 25
|
Can anyone please share some advice?
How can I use the API to add a product. Specifically what data has to be passed to the API and how do I determine what goes into the ptblElements DataTable?
Thank you!
|