0

How can I go about creating a custom Web Part that has a custom UI for editing. When the page is in Edit mode I have a special button show up "Edit" and when the user clicks on it it posts back to the page. I catch this and I want to display a custom UI so they can edit the web part properties. I need to be able to have rich text fields, and text fields that are editable and will post back so I can save them to the properties.

I'm struggling mostly with creating a RichTextField, or TextBox that I can grab the data in post back. I know how to do it if I outputted raw HTML to the page, then use HTTP.Context, but what's the C# way to do it?

Thanks!

kevingreen
  • 1,541
  • 2
  • 18
  • 40

2 Answers2

1

You can check in your web part if page is in Edit mode or Display mode and render the controls accordingly.

How to tell if page is in edit mode on a non-publishing site

On postback, you can fetch the values and assign it to your web part properties. Since you are handing it custom, you will need to set dirty flag:

http://msdn.microsoft.com/en-us/library/ms157656.aspx

Community
  • 1
  • 1
Madhur Ahuja
  • 22,211
  • 14
  • 71
  • 124
  • I use WebPartManager.DisplayMode == WebPartManager.DesignDisplayMod to make sure it's in edit mode. That part seems to be working. I have a edit mode inside the edit mode (design is a preview mode), so users can edit via form in the webpart (not the toolpart). I'm not able to get button event handlers to fire from this "edit mode inside edit mode". Thanks – kevingreen Jul 01 '11 at 18:26
0

It sounds like you're putting a configuration UI into the web part itself?

The standard way to provide a configuration UI is via the toolpart - the tall thin window that appears down the right hand side of a page when you edit a web part.

These posts should give you a good introduction :-

Ryan
  • 23,871
  • 24
  • 86
  • 132
  • The reason I didn't go the toolpane route was, the data I'm storing is way to complicated to be stored in the toolpane. It's a lot of rich text boxes. – kevingreen Oct 25 '11 at 17:58