how to open a new window on button click

Store UI, layout, design, look and feel; Discussion on the customer facing pages of your online store. Cascading Style Sheets, Themes, Scriptlets, NVelocity and the components in the ConLib directory.
Post Reply
rupkumar2006
Ensign (ENS)
Ensign (ENS)
Posts: 1
Joined: Fri Feb 06, 2009 1:15 pm

how to open a new window on button click

Post by rupkumar2006 » Fri Feb 06, 2009 1:59 pm

Hi,
I have ablecommerse 7.0 and i have to add a new button on BuyProductDialog .And on click it open a new window .
for that i have added button ,and it is looking right . i am using in on_load
Button1.Attributes.Add("onclick", "window.open('http://www.microsoft.com'); return false;");
But its giving error .
So How i can do the same ?
Thanks in advance

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: how to open a new window on button click

Post by jmestep » Fri Feb 06, 2009 6:52 pm

Look at the code on the product page that pops up a window for the additional images- that might give you some help.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
nickc
Captain (CAPT)
Captain (CAPT)
Posts: 276
Joined: Thu Nov 29, 2007 3:48 pm

Re: how to open a new window on button click

Post by nickc » Sat Feb 07, 2009 1:12 am

You don't say what the error is? Javascript onclick or code-behind assignment of event?

window.open supports a target:

Code: Select all

window.open(string url,string target,string features,bool replace)
so you should be able to use "window.open('http://www.microsoft.com','_blank')" to get a new window...

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: how to open a new window on button click

Post by mazhar » Sat Feb 07, 2009 4:18 am

Check this, some part of this post is about window.open
viewtopic.php?f=42&t=9581

pizzaovens
Ensign (ENS)
Ensign (ENS)
Posts: 19
Joined: Wed Oct 01, 2008 10:05 am

Re: how to open a new window on button click

Post by pizzaovens » Tue Feb 17, 2009 2:30 pm

the OP is working on our site. we want an additional button on the products display page to request more info. this button will pop up a new window and have a forum that will then be sent to us via email with a note of what page the request button was triggered from (to know what product the customer wanted more info for)

we saw how the buttons where made in the buyproductdialog.ascx.cs so replicated that to make the button appear. however we cant get that button to trigger a new window to open up moreinfo.ascx .

here is a live version of the code below http://www.pizzaovens.com/Bakers-Pride- ... P5554.aspx

below are the files used from my conlib folder.

any help would be greatly appreciated.
Last edited by pizzaovens on Tue Feb 17, 2009 2:34 pm, edited 1 time in total.

pizzaovens
Ensign (ENS)
Ensign (ENS)
Posts: 19
Joined: Wed Oct 01, 2008 10:05 am

Re: how to open a new window on button click

Post by pizzaovens » Tue Feb 17, 2009 2:30 pm

BuyProductDialog.ascx

Code: Select all

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="BuyProductDialog.ascx.cs" Inherits="ConLib_BuyProductDialog" %>
<%--
<conlib>
<summary>Displays product details and buy now button to add it to cart.</summary>
<param name="ShowSku" default="true">Possible values are true or false.  Indicates whether the SKU will be shown or not.</param>
<param name="ShowPrice" default="true">Possible values are true or false.  Indicates whether the price details will be shown or not.</param>
<param name="ShowSubscription" default="true">Possible values are true or false.  Indicates whether the subscription details will be shown or not.</param>
<param name="ShowMSRP" default="true">Possible values are true or false.  Indicates whether the MSPR will be shown or not.</param>
</conlib>
--%>
<%@ Register Assembly="CommerceBuilder.Web" Namespace="CommerceBuilder.Web.UI.WebControls" TagPrefix="cb" %>
<%@ Register Src="~/ConLib/Utility/ProductPrice.ascx" TagName="ProductPrice" TagPrefix="uc" %>
<ajax:UpdatePanel ID="BuyProductPanel" runat="server" UpdateMode="Always">
    <ContentTemplate>
        <table class="buyProductForm" cellpadding="0" cellspacing="0">
            <tr id="trSku" runat="server" enableviewstate="false">
                <th class="rowHeader">
                    <asp:Localize ID="SkuLocalize" runat="server" Text="Item #:" EnableViewState="false"></asp:Localize>
                </th>
                <td>
                    <asp:Literal ID="Sku" runat="server"></asp:Literal>
                </td>
            </tr>
            <tr id="trRegPrice" runat="server" enableviewstate="false">
                <th class="rowHeader">
                    <asp:Localize ID="RegPriceLocalize" runat="server" Text="Reg. Price:" EnableViewState="false"></asp:Localize> 
                </th>
                <td>
                    <asp:Label ID="RegPrice" runat="server" SkinID="MSRP" EnableViewState="false"></asp:Label>
                </td>
            </tr>
            <tr id="trOurPrice" runat="server" EnableViewState="false">
                <th class="rowHeader" valign="top">
                    <asp:Localize ID="OurPriceLocalize" runat="server" Text="Our Price:" EnableViewState="false"></asp:Localize>        
                </th>
                <td>
                    <uc:ProductPrice ID="OurPrice" runat="server" />                    
                </td>
            </tr>
            <tr id="trVariablePrice" runat="server" enableviewstate="false">
                <th class="rowHeader">
                    <asp:Localize ID="VariablePriceLabel" runat="server" Text="Enter Price:" EnableViewState="false"></asp:Localize>
                </th>
                <td>
                    <asp:TextBox ID="VariablePrice" runat="server" MaxLength="8" Width="60px" ValidationGroup="AddToBasket"></asp:TextBox>
                    <asp:PlaceHolder ID="phVariablePrice" runat="server"></asp:PlaceHolder>
                </td>
            </tr>
            <tr id="rowSubscription" runat="server" enableviewstate="false">
                <td>&nbsp;</td>
                <td>
                    <asp:Localize ID="RecuringPaymentMessage" runat="server" Text="This item includes a recurring payment." EnableViewState="false"></asp:Localize><br />
                    <asp:Localize ID="InitialPayment" runat="server" Text="Initial Payment: {0:ulc}<br />" EnableViewState="false"></asp:Localize>
                    <asp:Localize ID="RecurringPayment" runat="server" Text="Recurring Payment: {0} payments of {1:ulc}, every {2}." EnableViewState="false"></asp:Localize>
                </td>
            </tr>
			<asp:PlaceHolder runat="server" id="phOptions" EnableViewState="false"></asp:PlaceHolder>
			<asp:PlaceHolder ID="phAddToBasketWarningOpt" runat="server" EnableViewState="false" Visible="false">
			<tr>
				<td>&nbsp;</td>
                <td colspan="8">          
                    <asp:Label ID="AddToBasketWarningOpt" runat="server" EnableViewState="false"  SkinID="ErrorCondition" Text="Please make your selections above."></asp:Label>
                </td>
            </tr>
			</asp:PlaceHolder>
			<asp:PlaceHolder runat="server" id="phKitOptions" EnableViewState="false"></asp:PlaceHolder>
			<asp:PlaceHolder ID="phAddToBasketWarningKit" runat="server" EnableViewState="false" Visible="false">
			<tr>
				<td>&nbsp;</td>
                <td colspan="8">          
                    <asp:Label ID="AddToBasketWarningKit" runat="server" EnableViewState="false"  SkinID="ErrorCondition" Text="Please make your selections above."></asp:Label>
                </td>
            </tr>
			</asp:PlaceHolder>
            <tr id="rowQuantity" runat="server" enableviewstate="false">
                <th class="rowHeader">
                    <asp:Localize ID="QuantityLocalize" runat="server" Text="Quantity:"></asp:Localize>        
                </th>
                <td nowrap>
                    <cb:updowncontrol Width="30" id="Quantity" runat="server" DownImageUrl="~/images/down.gif" UpImageUrl="~/images/up.gif" Columns="2" MaxLength="5" Text='1' MaxValue="32767" onFocus="this.select()"></cb:updowncontrol><asp:CustomValidator ID="QuantityValidaor" runat="server" ValidationGroup="AddToBasket" ErrorMessage="Quantity can not exceed the available stock of {0}." ControlToValidate="Quantity">*</asp:CustomValidator>
                    <asp:PlaceHolder ID="QuantityLimitsPanel" runat="server" EnableViewState="false"></asp:PlaceHolder>
                    </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <asp:PlaceHolder ID="InventoryDetailsPanel" runat="server" EnableViewState="false"></asp:PlaceHolder>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:ValidationSummary ID="ValidationSummary" runat="server" ValidationGroup="AddToBasket" />					
                    <asp:LinkButton ID="AddToWishlistButton" runat="server" SkinID="Button" Visible="true" OnClick="AddToWishlistButton_Click" Text="Add to Wishlist" EnableViewState="false" ValidationGroup="AddToBasket"></asp:LinkButton>
                    <asp:LinkButton ID="AddToBasketButton" runat="server" SkinID="Button" Visible="true" OnClick="AddToBasketButton_Click" Text="Add to Basket" EnableViewState="false" ValidationGroup="AddToBasket"></asp:LinkButton>
                    <asp:LinkButton ID="MoreInfoButton" runat="server" SkinID="Button" Visible="true" OnClick="MoreInfoButton_Click" Text="More Info"  ></asp:LinkButton>
                </td>
                </tr>
        </table>
    </ContentTemplate>
</ajax:UpdatePanel>

pizzaovens
Ensign (ENS)
Ensign (ENS)
Posts: 19
Joined: Wed Oct 01, 2008 10:05 am

Re: how to open a new window on button click

Post by pizzaovens » Tue Feb 17, 2009 2:31 pm

BuyProductDialog.ascx.cs

Code: Select all

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CommerceBuilder.Common;
using CommerceBuilder.DigitalDelivery;
using CommerceBuilder.Orders; 
using CommerceBuilder.Products;
using CommerceBuilder.Users;
using CommerceBuilder.Stores;
using CommerceBuilder.Utility;

public partial class ConLib_BuyProductDialog : System.Web.UI.UserControl
{
    int _ProductId = 0;
    Product _Product = null;
    Dictionary<int, int> _SelectedOptions = null;
    List<int> _SelectedKitProducts = null;

    private bool _ShowSku = true;
    public bool ShowSku
    {
        get { return _ShowSku; }
        set { _ShowSku = value; }
    }

    private bool _ShowPrice = true;
    public bool ShowPrice
    {
        get { return _ShowPrice; }
        set { _ShowPrice = value; }
    }

    private bool _ShowSubscription = true;
    public bool ShowSubscription
    {
        get { return _ShowSubscription; }
        set { _ShowSubscription = value; }
    }

    private bool _ShowMSRP = true;
    public bool ShowMSRP
    {
        get { return _ShowMSRP; }
        set { _ShowMSRP = value; }
    }
protected void Page_Load(object sender, EventArgs e)
    {
	try{
// MoreInfoButton..Attributes.Add("onclick", "window.open('www.pizzaovens.com')"; return false;");
	}
        catch (Exception ex)
        {

             Response.Write("new error saumitra" + ex.Message+ ex.InnerException + ex.StackTrace); 
        }
    }
    protected void Page_Init(object sender, System.EventArgs e)
    {
        _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
        _Product = ProductDataSource.Load(_ProductId);
        if (_Product != null)
        {
            //DISABLE PURCHASE CONTROLS BY DEFAULT
            AddToBasketButton.Visible = false;
            rowQuantity.Visible = false;

            //HANDLE SKU ROW
            trSku.Visible = (ShowSku && (_Product.Sku != string.Empty));
            if (trSku.Visible)
            {
                Sku.Text = _Product.Sku;
            }
            //HANDLE REGPRICE ROW
            trRegPrice.Visible = (ShowMSRP && (_Product.MSRP > 0));
            if (trRegPrice.Visible)
            {
                RegPrice.Text = _Product.MSRP.ToString("ulc");
            }
            // HANDLE PRICES VISIBILITY
            if (ShowPrice)
            {
                if (!_Product.UseVariablePrice)
                {
                    trOurPrice.Visible = true;
                    trVariablePrice.Visible = false;
                }
                else
                {
                    trOurPrice.Visible = false;
                    trVariablePrice.Visible = true;
                    VariablePrice.Text = _Product.Price.ToString("F2");
                    string varPriceText = string.Empty;
                    Currency userCurrency = Token.Instance.User.UserCurrency;
                    LSDecimal userLocalMinimum = userCurrency.ConvertFromBase(_Product.MinimumPrice);
                    LSDecimal userLocalMaximum = userCurrency.ConvertFromBase(_Product.MaximumPrice);
                    if (userLocalMinimum > 0)
                    {
                        if (userLocalMaximum > 0)
                        {
                            varPriceText = string.Format("(between {0:ulcf} and {1:ulcf})", userLocalMinimum, userLocalMaximum);
                        }
                        else
                        {
                            varPriceText = string.Format("(at least {0:ulcf})", userLocalMinimum);
                        }
                    }
                    else if (userLocalMaximum > 0)
                    {
                        varPriceText = string.Format("({0:ulcf} maximum)", userLocalMaximum);
                    }
                    phVariablePrice.Controls.Add(new LiteralControl(varPriceText));
                }
            }

            //UPDATE QUANTITY LIMITS
            if ((_Product.MinQuantity > 0) && (_Product.MaxQuantity > 0))
            {
                string format = " (min {0}, max {1})";
                QuantityLimitsPanel.Controls.Add(new LiteralControl(string.Format(format, _Product.MinQuantity, _Product.MaxQuantity)));
            }
            else if (_Product.MinQuantity > 0)
            {
                string format = " (min {0})";
                QuantityLimitsPanel.Controls.Add(new LiteralControl(string.Format(format, _Product.MinQuantity)));
            }
            else if (_Product.MaxQuantity > 0)
            {
                string format = " (max {0})";
                QuantityLimitsPanel.Controls.Add(new LiteralControl(string.Format(format, _Product.MaxQuantity)));
            }
            if (_Product.MinQuantity > 0) Quantity.Text = _Product.MinQuantity.ToString();

            //BUILD PRODUCT ATTRIBUTES
            _SelectedOptions = ProductHelper.BuildProductOptions(_Product, phOptions);
            //BUILD PRODUCT CHOICES
            ProductHelper.BuildProductChoices(_Product, phOptions);
            //BUILD KIT OPTIONS
            _SelectedKitProducts = ProductHelper.BuildKitOptions(_Product, phKitOptions);

        }
        else
        {
            this.Controls.Clear();
        }

// MoreInfoButton..Attributes.Add("onclick", "javascript:window.open('www.pizzaovens.com'); return false;");

    }

    private void UpdateInventoryDetails(InventoryManagerData inv)
    {
        if ((inv.InventoryMode == InventoryMode.None) || (inv.AllowBackorder)) return;
        if (inv.InStock > 0)
        {
            string inStockformat = Token.Instance.Store.Settings.InventoryInStockMessage;
            string inStockMessage = string.Format(inStockformat, inv.InStock);
            InventoryDetailsPanel.Controls.Clear();
            InventoryDetailsPanel.Controls.Add(new LiteralControl(inStockMessage));
            Quantity.MaxValue = inv.InStock;
        }
        else
        {
            string outOfStockformat = Token.Instance.Store.Settings.InventoryOutOfStockMessage;
            string outOfStockMessage = string.Format(outOfStockformat, inv.InStock);
            InventoryDetailsPanel.Controls.Clear();
            InventoryDetailsPanel.Controls.Add(new LiteralControl(outOfStockMessage));
        }
    }

    private void HideAddToBasket()
    {
        AddToBasketButton.Visible = false;
        AddToWishlistButton.Visible = false;
        rowQuantity.Visible = false;
    }

    private void ShowAddToBasket()
    {
        AddToBasketButton.Visible = true;
        AddToWishlistButton.Visible = true;
        rowQuantity.Visible = true;
    }

    protected BasketItem GetBasketItem()
    {
        //GET THE QUANTITY
        int tempQuantity = AlwaysConvert.ToInt(Quantity.Text,1);
        if (tempQuantity < 1) return null;
		if (tempQuantity > System.Int16.MaxValue) tempQuantity = System.Int16.MaxValue;

        //RECALCULATE SELECTED KIT OPTIONS
        GetSelectedKitOptions();
        // DETERMINE THE OPTION LIST
        string optionList = ProductVariantDataSource.GetOptionList(_ProductId, _SelectedOptions, false);
        //CREATE THE BASKET ITEM WITH GIVEN OPTIONS
        BasketItem basketItem = BasketItemDataSource.CreateForProduct(_ProductId, (short)tempQuantity, optionList, _SelectedKitProducts);
        if (basketItem != null)
        {
            //ADD IN VARIABLE PRICE
            if (_Product.UseVariablePrice)
            {
                Currency userCurrency = Token.Instance.User.UserCurrency;
                decimal userLocalPrice = AlwaysConvert.ToDecimal(VariablePrice.Text);
                basketItem.Price = userCurrency.ConvertToBase(userLocalPrice);
            }
            ProductHelper.CollectProductTemplateInput(basketItem, this);
        }
        return basketItem;
    }

    private bool ValidateVariablePrice()
    {
        if (!_Product.UseVariablePrice) return true;
        Currency userCurrency = Token.Instance.User.UserCurrency;
        LSDecimal userLocalPrice = AlwaysConvert.ToDecimal(VariablePrice.Text);
        LSDecimal price = userCurrency.ConvertToBase(userLocalPrice);
        bool priceValid = ((price >= _Product.MinimumPrice) && ((_Product.MaximumPrice == 0) || (price <= _Product.MaximumPrice)));
        if (!priceValid)
        {
            CustomValidator invalidPrice = new CustomValidator();
            invalidPrice.IsValid = false;
            invalidPrice.Text = "*";
            invalidPrice.ErrorMessage = "Price does not fall within the accepted range.";
            invalidPrice.ControlToValidate = "VariablePrice";
            invalidPrice.ValidationGroup = "AddToBasket";
            phVariablePrice.Controls.Add(invalidPrice);
        }
        return priceValid;
    }

    private bool AllProductOptionsSelected()
    {
        if (_SelectedOptions.Count != _Product.ProductOptions.Count)
        {
            phAddToBasketWarningOpt.Visible = true;
            return false;
        }
        else
        {
            phAddToBasketWarningOpt.Visible = false;
            return true;
        }
    }

    private int AvailableProductOptionsCount()
    {
        int count = 0;
        for (int i = 0; i < _Product.ProductOptions.Count; i++)
        {
            Option option = _Product.ProductOptions[i].Option;
            // GET THE COLLECTION OF OPTIONS THAT ARE AVAILABLE FOR THE CURRENT SELECTIONS
            OptionChoiceCollection availableChoices = OptionChoiceDataSource.GetAvailableChoices(_Product.ProductId, option.OptionId, _SelectedOptions);
            if (availableChoices.Count > 0) count++;
        }
        return count;
    }

    private bool RequiredKitOptionsSelected()
    {
        bool requiredKitOptionsSelected = ProductHelper.RequiredKitOptionsSelected(_Product, _SelectedKitProducts);
        if (requiredKitOptionsSelected)
        {
            phAddToBasketWarningKit.Visible = false;
            return true;
        }
        else
        {
            phAddToBasketWarningKit.Visible = true;
            return false;
        }
    }

    protected bool ValidateQuantity()
    {
        string optionList = ProductVariantDataSource.GetOptionList(_ProductId, _SelectedOptions, true);
        if (!string.IsNullOrEmpty(optionList))
        {
            int currentQuanity = AlwaysConvert.ToInt(Quantity.Text);
            if (currentQuanity == 0)
            {
                QuantityValidaor.ErrorMessage = "Please enter a valid quantity.";
                QuantityValidaor.IsValid = false;
                return false;
            }
            InventoryManagerData inv = InventoryManager.CheckStock(_ProductId, optionList, _SelectedKitProducts);
            if (inv.InventoryMode != InventoryMode.None && !inv.AllowBackorder && inv.InStock > 0 && currentQuanity > inv.InStock)
            {
                //Quantity.Text = inv.InStock.ToString();
                QuantityValidaor.ErrorMessage = String.Format(QuantityValidaor.ErrorMessage, inv.InStock);
                QuantityValidaor.IsValid = false;
                return false;
            }
        }
        return true;
    }

    protected void AddToBasketButton_Click(object sender, System.EventArgs e)
    {
        if (Page.IsValid && ValidateVariablePrice() && ValidateQuantity()
            && AllProductOptionsSelected() && RequiredKitOptionsSelected())
        {
            BasketItem basketItem = GetBasketItem();
            if (basketItem != null)
            {
                // DETERMINE IF THE LICENSE AGREEMENT MUST BE REQUESTED
                BasketItemLicenseAgreementCollection basketItemLicenseAgreements = new BasketItemLicenseAgreementCollection(basketItem, LicenseAgreementMode.OnAddToBasket);
                if ((basketItemLicenseAgreements.Count > 0))
                {
                    // THESE AGREEMENTS MUST BE ACCEPTED TO ADD TO BASKET
                    List<BasketItem> basketItems = new List<BasketItem>();
                    basketItems.Add(basketItem);
                    string guidKey = Guid.NewGuid().ToString("N");
                    Cache.Add(guidKey, basketItems, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 10, 0), System.Web.Caching.CacheItemPriority.NotRemovable, null);
                    string acceptUrl = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("~/Basket.aspx"));
                    string declineUrl = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(Page.ResolveClientUrl(_Product.NavigateUrl)));
                    Response.Redirect("~/BuyWithAgreement.aspx?Items=" + guidKey + "&AcceptUrl=" + acceptUrl + "&DeclineUrl=" + declineUrl);
                }

                //ADD ITEM TO BASKET
                Basket basket = Token.Instance.User.Basket;
                basket.Items.Add(basketItem);
                basket.Save();

                //Determine if there are associated Upsell products
                if (basketItem.Product.GetUpsellProducts(basket).Count > 0)
                {
                    //redirect to upsell page
                    string returnUrl = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(Request.Url.ToString()));
                    Response.Redirect("~/ProductAccessories.aspx?ProductId=" + basketItem.ProductId + "&ReturnUrl=" + returnUrl);
                }

                // IF BASKET HAVE SOME VALIDATION PROBLEMS MOVE TO BASKET PAGE
                List<string> basketMessages;
                if (!basket.Validate(out basketMessages))
                {
                    Session.Add("BasketMessage", basketMessages);
                    Response.Redirect(NavigationHelper.GetBasketUrl());
                }

                //IF THERE IS NO REGISTERED BASKET CONTROL, WE MUST GO TO BASKET PAGE
                if (!PageHelper.HasBasketControl(this.Page)) Response.Redirect(NavigationHelper.GetBasketUrl());
            }
        }
    }
  protected void MoreInfoButton_Click(object sender, System.EventArgs e)
    {
       // StringBuilder sb = new StringBuilder();
	   string s = "<script>";
//        sb.Append("<script>");
  s = s+ "window.open('http://msdn.microsoft.com', '', '');" ;
//		sb.Append("window.open('http://msdn.microsoft.com', '', '');");
  s = s+ "</scri" ; 
//		sb.Append("</scri");
s = s+ "pt>" ; 
//		sb.Append("pt>");

        Page.RegisterStartupScript("test", s);

    }
    protected void AddToWishlistButton_Click(object sender, System.EventArgs e)
    {
		if (Page.IsValid && ValidateVariablePrice() && ValidateQuantity()
            && AllProductOptionsSelected() && RequiredKitOptionsSelected())
        {
			BasketItem wishlistItem = GetBasketItem();
			if (wishlistItem != null)
			{
                // DETERMINE IF THE LICENSE AGREEMENT MUST BE REQUESTED
                BasketItemLicenseAgreementCollection basketItemLicenseAgreements = new BasketItemLicenseAgreementCollection(wishlistItem, LicenseAgreementMode.OnAddToBasket);
                if ((basketItemLicenseAgreements.Count > 0))
                {
                    // THESE AGREEMENTS MUST BE ACCEPTED TO ADD TO BASKET
                    List<BasketItem> basketItems = new List<BasketItem>();
                    basketItems.Add(wishlistItem);
                    string guidKey = Guid.NewGuid().ToString("N");
                    Cache.Add(guidKey, basketItems, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 10, 0), System.Web.Caching.CacheItemPriority.NotRemovable, null);
                    string acceptUrl = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("~/Members/MyWishlist.aspx"));
                    string declineUrl = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(Page.ResolveClientUrl(_Product.NavigateUrl)));
                    Response.Redirect("~/BuyWithAgreement.aspx?Items=" + guidKey + "&AcceptUrl=" + acceptUrl + "&DeclineUrl=" + declineUrl + "&ToWishlist=True");
                }

				Wishlist wishlist = Token.Instance.User.PrimaryWishlist;
				wishlist.Items.Add(wishlistItem);
				wishlist.Save();
				Response.Redirect("~/Members/MyWishlist.aspx");
			}
		}
    }

    protected void Page_PreRender(object sender, EventArgs e)
    {
        //GET THE SELECTED KIT OPTIONS
        GetSelectedKitOptions();
        string optionList = ProductVariantDataSource.GetOptionList(_ProductId, _SelectedOptions, true);
        //SET THE CURRENT CALCULATED PRICE
        OurPrice.Product = _Product;
        OurPrice.OptionList = optionList;
        OurPrice.SelectedKitProducts = _SelectedKitProducts;
        bool allProductOptionsSelected = (_SelectedOptions.Count == _Product.ProductOptions.Count);
        bool requiredKitOptionsSelected = ProductHelper.RequiredKitOptionsSelected(_Product, _SelectedKitProducts);
        InventoryManagerData inv = null;

        //SHOW SUBSCRIPTIONS
        SubscriptionPlan sp = _Product.SubscriptionPlan;
        rowSubscription.Visible = (this.ShowSubscription && sp != null && sp.IsRecurring && ShowPrice);
        if (rowSubscription.Visible)
        {
            InitialPayment.Visible = (sp.RecurringChargeSpecified);
            if (InitialPayment.Visible) InitialPayment.Text = string.Format(InitialPayment.Text, _Product.Price);
            string period;
            if (sp.PaymentFrequency > 1) period = sp.PaymentFrequency + " " + sp.PaymentFrequencyUnit.ToString().ToLowerInvariant() + "s";
            else period = sp.PaymentFrequencyUnit.ToString().ToLowerInvariant();
            int numPayments = (sp.RecurringChargeSpecified ? sp.NumberOfPayments - 1 : sp.NumberOfPayments);
            RecurringPayment.Text = string.Format(RecurringPayment.Text, numPayments, sp.CalculateRecurringCharge(_Product.Price), period);
        }

        CommerceBuilder.Stores.Store store = Token.Instance.Store;

        if (store.EnableInventory && store.Settings.InventoryDisplayDetails
            && (_Product.InventoryMode != InventoryMode.None) && (!_Product.AllowBackorder))
        {
            if (allProductOptionsSelected && requiredKitOptionsSelected)
            {
                inv = InventoryManager.CheckStock(_ProductId, optionList, _SelectedKitProducts);
                UpdateInventoryDetails(inv);
            }
            else
            {
                InventoryDetailsPanel.Controls.Clear();
            }
        }

        HideAddToBasket();
        if (!_Product.DisablePurchase && !Token.Instance.Store.Settings.ProductPurchasingDisabled)
        {
            if (requiredKitOptionsSelected)
            {
                if (inv != null)
                {
                    if (inv.InventoryMode == InventoryMode.None || inv.InStock > 0 || inv.AllowBackorder)
                    {
                        ShowAddToBasket();
                    }
                }
                // IF NO VARIANT ARE AVAILABLE IN STOCK
                else if (_Product.InventoryMode == InventoryMode.Variant && AvailableProductOptionsCount() == 0)
                {
                    string outOfStockformat = Token.Instance.Store.Settings.InventoryOutOfStockMessage;
                    string outOfStockMessage = string.Format(outOfStockformat, 0);
                    InventoryDetailsPanel.Controls.Add(new LiteralControl(outOfStockMessage));
                }
                else
                {
                    ShowAddToBasket();
                }
            }
        }
    }

    protected void GetSelectedKitOptions()
    {
        _SelectedKitProducts = new List<int>();
        //COLLECT ANY KIT VALUES
        foreach (ProductKitComponent pkc in _Product.ProductKitComponents)
        {
            // FIND THE CONTROL
            KitComponent component = pkc.KitComponent;
            if (component.InputType == KitInputType.IncludedHidden)
            {
                foreach (KitProduct choice in component.KitProducts)
                {
                    _SelectedKitProducts.Add(choice.KitProductId);
                }
            }
            else
            {
                WebControl inputControl = (WebControl)PageHelper.RecursiveFindControl(this, component.UniqueId);
                if (inputControl != null)
                {
                    List<int> kitProducts = component.GetControlValue(inputControl);
                    foreach (int selectedKitProductId in kitProducts)
                    {
                        _SelectedKitProducts.Add(selectedKitProductId);
                    }
                }
            }
        }
    }
}

pizzaovens
Ensign (ENS)
Ensign (ENS)
Posts: 19
Joined: Wed Oct 01, 2008 10:05 am

Re: how to open a new window on button click

Post by pizzaovens » Tue Feb 17, 2009 2:32 pm

deleted
Last edited by pizzaovens on Tue Feb 17, 2009 2:50 pm, edited 1 time in total.

pizzaovens
Ensign (ENS)
Ensign (ENS)
Posts: 19
Joined: Wed Oct 01, 2008 10:05 am

Re: how to open a new window on button click

Post by pizzaovens » Tue Feb 17, 2009 2:33 pm

MoreInfoDialog.ascx.cs

Code: Select all

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//using CommerceBuilder.Common;
//using CommerceBuilder.Products;
//using CommerceBuilder.Marketing;
//using CommerceBuilder.Utility;
using System.Net.Mail;
public partial class ConLib_MoreInfoDialog : System.Web.UI.UserControl
{
    private string _Caption = "More Info";

    [Personalizable(), WebBrowsable()]
    public string Caption
    {
        get { return _Caption; }
        set { _Caption = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
       
       // int _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
       // Product _Product = ProductDataSource.Load(_ProductId);
       
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        SimpleMail(createMailMessage());
    }
    public string createMailMessage()
    {
        string mail = string.Empty;
        mail = "<HTML> <BODY><table border=\"1\" bordercolor=\"#cccccc\" >";
        /****/
        mail += "<tr><td>Full Name :</td><td>";
        mail += TextBox1.Text + "</td></tr>";
        /****/
        mail += "<tr><td>Email Address :</td><td>";
        mail += TextBox2.Text +  "</td></tr>";
        /****/
        mail += "<tr><td>Product  </td><td>";
        mail += Request.QueryString["ProductId"].ToString() + "</td></tr>";
        /****/
        mail += "<tr><td>Question : </td><td>";
        mail += TextBox3.Text + "</td></tr>";
        /****/
        
        
        mail += "</table> </BODY></HTML>";
        return mail;
    }
    public void SimpleMail(string mail)
    {
        try
        {

            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
            message.To.Add("support@pizzaovens.com");
            message.Subject = "MoreInfo";
            message.IsBodyHtml = true;
            message.From = new System.Net.Mail.MailAddress("aroberts@pizzaovens.com");
            message.Body = mail;
            SmtpClient smtp = new SmtpClient();
            smtp.Send(message);
            //this.Dispose(); 
        }
        catch (Exception ex)
        {
            //  Response.Write("Error in mail" + ex.Message + ex.InnerException+ "\n"+ ex.StackTrace);
        }
    }
}

pizzaovens
Ensign (ENS)
Ensign (ENS)
Posts: 19
Joined: Wed Oct 01, 2008 10:05 am

Re: how to open a new window on button click

Post by pizzaovens » Fri Feb 20, 2009 2:01 pm

anyone of you Able experts have any ideas ?

User avatar
nickc
Captain (CAPT)
Captain (CAPT)
Posts: 276
Joined: Thu Nov 29, 2007 3:48 pm

Re: how to open a new window on button click

Post by nickc » Fri Feb 20, 2009 4:48 pm

Looks like Mazhar's "Contact Us" control (viewtopic.php?f=47&t=7954) would be better suited to what you are trying to implement. Could be as easy as adding the button as an anchor tag, and modding the control to accept querystring assignments of subject, etc:

Code: Select all

<a href="/contactus.aspx?subject=More info about <%=Product.Name %>&to=support" target="_blank" class="button">More Info</a>
Downside is that new window would have all site chrome, header, nav, footer, etc, unless you disabled for all instances of contactus.aspx.

You could also check out Facebox; jQuery+facebox+iframe (or +div if you don't need postback) makes a great popup with very little code required.


Post Reply