Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SharePoint > SharePoint 2010 > BOOK: Beginning SharePoint 2010 Development
|
BOOK: Beginning SharePoint 2010 Development
This is the forum to discuss the Wrox book Beginning SharePoint 2010 Development by Steve Fox; ISBN: 978-0-470-58463-7
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning SharePoint 2010 Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 12th, 2011, 10:15 AM
Registered User
 
Join Date: Oct 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default chapter 2 Create a custom webpart programmatically

Code:
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace MyFirstWebPart.MyFirstWebPart
{
    [ToolboxItemAttribute(false)]
    public class MyFirstWebPart : WebPart
    {
        Label lblUserEntry = new Label();
        TextBox txtbxUserEntry = new TextBox();
        Label lblFinalCost = new Label();
        TextBox txtbxFinalCost = new TextBox();
        Button btnCalcTax = new Button();
        double totalTax = 0.00;
        double prodTax = 0.11;
        public MyFirstWebPart()
        { }
        protected override void CreateChildControls()
        {
            lblUserEntry.Text = "Cost of Widget";
            lblFinalCost.Text = "Fianl Cost";
            btnCalcTax.Text = "Calc.";
            txtbxUserEntry.Text = "59.30";
            this.Controls.Add(lblUserEntry);
            this.Controls.Add(txtbxUserEntry);
            this.Controls.Add(new LiteralControl("<p>"));
            this.Controls.Add(lblFinalCost);
            this.Controls.Add(txtbxFinalCost);
            this.Controls.Add(new LiteralControl("<p>"));
            this.Controls.Add(btnCalcTax);
            btnCalcTax.Click+=new EventHandler(btnCalcTax_Click);
            base.CreateChildControls();
        }

        void btnCalcTax_Click(object sender, EventArgs e)
        {
            double prodCost = Convert.ToDouble(txtbxUserEntry.Text);
            totalTax=Math.Round(prodCost-(prodCost*prodTax),2)*100/100;
            txtbxFinalCost.Text = totalTax.ToString();
        }

        protected override void RenderContents(HtmlTextWriter writer)
        {
            base.RenderContents(writer);
        }

    }
}
shows following error when I press F5
cannot start service SPUserCodeV4





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 17-WebPart error Berdia BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 0 May 24th, 2010 08:15 AM
Create SQL Server users programmatically? Dmitriy Pro VB.NET 2002/2003 4 October 29th, 2008 03:14 PM
Create SQL Server user programmatically? Dmitriy Pro VB Databases 1 March 8th, 2006 10:02 AM
Create SQL Server database user programmatically? Dmitriy VB.NET 3 January 3rd, 2006 12:30 PM
Create SQL Server database user programmatically? Dmitriy Pro VB 6 0 December 8th, 2005 02:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.