Hola de nuevo:
Esto está siendo un calvario, a ver, ahí va mi nuevo
problema. Tengo el siguiente código de mi webpart:
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
using System.Web.UI.HtmlControls;
using System.Runtime.InteropServices;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.HtmlControls;
namespace WebPart1
{
/// <summary>
/// Description for WebPart1.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:WebPart1 runat=server></
{0}:WebPart1>"),
XmlRoot(Namespace="WebPart1")]
public class WebPart1 :
Microsoft.SharePoint.WebPartPages.WebPart
{
private const string defaultText = "";
private const string myTitle = "Links with
target blank";
private string text = defaultText;
[Browsable(true),
Category("Miscellaneous"),
DefaultValue(defaultText),
WebPartStorage(Storage.Personal),
FriendlyName("Text"),
Description("Text Property")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
/// <summary>
/// This method gets the custom tool
parts for this Web Part by overriding the
/// GetToolParts method of the WebPart
base class. You must implement
/// custom tool parts in a separate
class that derives from
///
Microsoft.SharePoint.WebPartPages.ToolPart.
/// </summary>
///<returns>An array of references to
ToolPart objects.</returns>
// public override ToolPart[] GetToolParts()
// {
// ToolPart[] toolparts = new ToolPart
[2];
// WebPartToolPart wptp = new
WebPartToolPart();
// CustomPropertyToolPart custom =
new CustomPropertyToolPart();
// toolparts[0] = wptp;
// toolparts[1] = custom;
// return toolparts;
// }
/// <summary>
/// Render this Web Part to the output
parameter specified.
/// </summary>
/// <param name="output"> The HTML writer
to write out to </param>
protected override void
CreateChildControls ()
{
}
protected override void RenderWebPart
(HtmlTextWriter output)
{
//creo una etiqueta
Label myLabel = new Label();
SPWeb mySite =
SPControl.GetContextWeb(Context);
myLabel.Text += mySite.Name;
output.Write(SPEncode.HtmlEncode
(Text));
if (this.Title.CompareTo(myTitle)
== 0)
{
//escribo el texto
myLabel.Text = "Change the
web part name to the name of list you desire to show.";
}
else
{
myLabel.Text = "Hola
caracola";
}
//añado la etiqueta a la página
this.Controls.Add(myLabel);
//Lo renderizo en la salida
myLabel.RenderControl(output);
}
}
}
El caso es que cuando intento acceder a cualquier
propiedad de la variable mySite:
SPWeb mySite = SPControl.GetContextWeb(Context);
myLabel.Text += mySite.Name;
sea la que sea, la generación va bien, pero la página de
elementos web me da el error:
El elemento web WebPart1 parece estar causando un
problema.
¿Alguna idea?
Gracias.
Javi.
Leer las respuestas