1

I have created my first Webpart with own properties:

    [ToolboxItemAttribute(false)]
public class BildMitHyperlink : WebPart
{
    [WebBrowsable(true), Category("MY"), DefaultValue(""), WebDisplayName("Hyperlink"), WebDescription("Der Hyperlink der gestartet werden soll, sobald auf das Bild geklickt wird.")]
    public string Hyperlink
    {
        get { return _hyperlink; }
        set { _hyperlink = value; }
    }
    public static string _hyperlink;



        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        var parent = (BildMitHyperlink)Parent;

        if (parent.NeuesFenster)
            Response.Redirect(parent.Hyperlink, "_blank", null);
        else
            Response.Redirect(parent.Hyperlink);
    }

My Problem is: When i create more then one WebPart on the same Page, the properties are shared on each WebPart! So if i change a propertie of one of the webparts - its change all my webparts?!

How can i make own properties for each Webpart?

Thanks 4 Answer!

  • Ahh! Thats it! Thanks 4 your fast answer and help! – user9454 Jul 13 '12 at 10:04
  • 1
    No prob, if it works for you, feel free to mark it as 'Answered' – Andy Burns Jul 13 '12 at 10:13
3

I would suggest that the _hyperlink variable should not be static. All the web parts of this type share the same C# class, so setting _hyperlink would reset that variable for all those web parts.

It probably shouldn't be public, either, as you've provided a property to access it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.