I am looking to add custom properties to a tool part. I've been able to add the textbox as desired. I've been able to enter values and display it in the webpart.
The problem is when I edit the webpart - the panel pops up but the control I added is not populated with the previously entered value. See below:
I have followed the instructions on this website exactly as written - neither myself nor a more experienced Sharepoint developer co-worker is able to figure out what's going on here.
We thought that overriding the SyncChanges() method would allow for this - It seems it doesn't, unless our implementation isn't correct?
public override void SyncChanges()
{
DemoWebPart wp = (DemoWebPart)this.ParentToolPane.SelectedWebPart;
urls.Text = wp.ListValue;
}
We have also prefixed the urls property of the DemoWebPart.cs class with the following, to no avail:
[Browsable(true), Category("Miscellaneous"),
DefaultValue("Site Names"),
WebPartStorage(Storage.Shared / Personal / None),
FriendlyName("URLs"), Description("Text Property")]
(Having tried Storage.Shared, Storage.Personal, and Storage.None).
Any help you can provide would be greatly appreciated - thanks in advance!
This is the code I generally use for such properties:
[Personalizable(PersonalizationScope.Shared)]
[WebBrowsable(true)]
[System.ComponentModel.Category("Custom")]
[WebDisplayName("DisplayNameGoesHere")]
[WebDescription("Type the description of this web property here.")]
public string MyProperty{ get; set; }
I've never had any problems with it.
Only use the following if Webpart personalization is enbaled in central admin:
Personalizable(PersonalizationScope.Shared)
If it is not, remove the Personalizable attribute completely. Do not put in false or none in it, delete that attribute and use this:
WebPartStorage(Storage.Shared)
Suggestion :
Create a new WP
and use this article http://snahta.blogspot.com/2009/11/webpart-custom-properties.html
I have used this 100s of times , please give it try , it will work.
Thanks
Sandeep
Related
I have already searched here to answer my question, and the closest I ever got was that post, but it still does not completely clarify the matter to me, so I will ask.
What I need is extending maxlengthattribute in the way that when I set it inside the C# file,
[MaxLength(50)]
[Display(Name = "Project Description")]
public string ProjectDescription { get; set; }
the attribute "maxlength" will be added inside the tag and will be <\stuff stuff maxlength = "50">
I have initially implemented it as writing html-helper to modify TextBoxFor, however, this is out of option since project is tightly intertwined with .js, and inserting renamed method will break a code, which will be a pain to fix.
The answer I referred above provides the closest explanation of what I need, but it looks like I will need to declare attributes (like inside ( ) in function), which I do not see there.
At this point I can either try modifying JS file on the server-side, or extending maxlengthattribute. Thus far, latter is preferable for me, thus I would like to ask how to properly extend it inside the c# file.
Thank you very much in advance!
You can write a custom dataannotation provider. The max length attribute will get added to the control.
Refer this link
I have to make many combination of field and property. I cannot use the implicit property version "{ get; set; }" since the fields need some attributes.
So, in Visual Studio Express 2013, is there a way to have a shortcut to create a property associated with a field I just ended up writing?
Let's say I write;
private MyType myData;
and I press CTRL+P (whatever the shortcut), and it adds
public MyType MyData
{
get { return myData; }
set { myData = value; }
}
just after.
Is it possible?
EDIT:
The Express version however does only have two refactoring functionalities: rename and extract method, the other functionalities like encapsulate are not present.
I guess I'm stuck.
By what you are asking 3 simple clicks will do it like this:
rigth-click in your field then Refactor-->EncapsulateField
And your done.
Check this out:
http://msdn.microsoft.com/en-us/library/z41h7fat.aspx
this might also be useful (Create your own snippets) :
http://msdn.microsoft.com/en-us/library/vstudio/ms165394.aspx
here you have all the code snippets you need including "prop", which is the one you need now!
Hope it helps
Type prop
then press tab
then enter the property name
then press ctrl+.
then click on convert to full property
You should use code snippet and assign hotkey for it.
More information about managing code snippets here: http://msdn.microsoft.com/en-us/library/ms165394.aspx
I seem to be experiencing a problem clearing the "altRecipient" attribute in Active Directory. When I run my program, it executes and returns successfully, but when I check either ADUC or ADSI Edit, the attribute is not cleared. Below is how I'm trying to clear the attribute:
termUser.Properties["altRecipient"].Clear();
I have also tried to clear the attribute by using:
termUser.Properties["altRecipient"].Value = null;
If I use the Clear() method on the "ipPhone" attribute, it works as expected. The only difference that I can see between the "ipPhone" attribute and the "altRecipient" attribute in ADSI Edit is that "ipPhone" is a Unicode String syntax whereas the "altRecipient" attribute has a Distinguished Name syntax.
Any help would be appreciated. Thank you.
Thank you for your response JPBLanc. I tried the "deliverAndRedirect" property and was still having a problem. I had a method that was setting three properties total and had the
termUser.CommitChanges();
being called at the end. I ended up calling
termUser.CommitChanges();
twice, once after
termUser.Properties["altRecipient"].Clear();
and again after setting the other two properties. It seems to be working now.....thank you for your help!
I am new to SharePoint developement and have a few startup problems which I hope you will help me with.
I am trying to make a custom field type and I am using WPS builder to create the project. Right now I have the following files which are all compiling just fine :)
SuperLookup3.cs
SuperLookup3Control.cs
SuperLookup3FieldEditor.cs
SuperLookup3FieldEditor.ascx (controltemplate)
fldtypes_SuperLookup3.xml (XML)
I have tried look at this example but I just can't get it to work.
My questions
How is the relationsships between the files?
I can see an override of UpdateFieldValueInItem() which is setting the value to the selected item of a dropdown list. But this method is never called (when debugging). How can this be?
Some general advice would be to post this question to the SharePoint Stack Exchange site (if this answer is unsatisfactory), since there are a lot more SharePoint developers there.
From what I understand of that example, it seems to be quite a complex Custom Field Type to start with (given that it has multiple values). There's a good straightforward and pretty well explained tutorial on MSDN that you might want to try out: Walkthrough: Creating a Custom Field Type
Here's a brief explanation of your files (and the classes they contain):
This is the main class of your field, which derives from the SharePoint field base class (SPField). Your naming seems to indicate you're creating a lookup derivative; if so, you may wish to derived from SPFieldLookup.
This is the class the creates the form control displayed on a list item's New, Edit, and Display forms (but not the List View). It's a go-between for the forms and the item's value for this field.
&
This is the section displayed on the Add/Edit Column page. I would expect 3. to have the ending '.ascx.cs' instead of '.cs', since it is the code-behind for 4.; which may be the cause of your problem. This control sets up your field; associating the class in 1. to the list.
This is the field declaration. It says to SharePoint "Hey, I've created my own field; go look here to find it.", and directs SharePoint to the class in 1., which makes the field available on the Add Column page.
I have created custom MembershipUser, MembershipProvider and RolePrivoder classes. These all work and I am very happy with it, apart from one thing. I have an extra field in the "Users" table. I have an overridden method for CreateUser() that takes in the extra variable and puts it into the DB.
My issues is that I want to be able to have this called from the Create User Wizard control. I have customized the control to have a drop down to populate my extra field. I have used the following code to store that piece of info but I am at a loss of how I either use the profile or call my custom CreateUser Method:
// Create an empty Profile for the newly created user
ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true);
// Populate some Profile properties off of the create user wizard
p.CurrentLevel = Int32.Parse(((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("clevel")).SelectedValue);
// Save profile - must be done since we explicitly created it
p.Save();
Thank you for any and all help
Jon Hawkins
I think your solution is the "easiest" you're going to get. You could create your own wizard and call the correct method, but that's a lot more work.
The only thing I could recommend is using the OnCreatedUser event instead.
reference: 4guysfromrolla
This is not the answer but I found a work around, would still like to know if someone could answer the question directly...
public void UpdateCurrentLvl_OnDeactivate(object sender, EventArgs e)
{
int level = Int32.Parse(((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("clevel")).SelectedValue);
MyMembershipUser myUser = (MyMembershipUser)Membership.GetUser(CreateUserWizard1.UserName);
myUser.CurrentLVL = level;
Membership.UpdateUser(myUser);
}
In my first CreateUserWizardStep if put the method above to fire on deactivate. As at this point it has inserted the user into the DB I can get the User out, cast to my MembershipUser class, set the variable and all the update method.
As I say this is a work around from the way I would liked to have solved it but it works.
Thanks
This is also incredibly hacky, but in the past when I've had to do similar things, I've just crammed the extra value into an unused parameter, like the password reset question or answer. Though, I'm not entirely sure how you'd manage this using the wizard.
It's ugly, but as long as it is explicitly documented (to be safe, I'd comment on the method itself as well as anywhere you reference it) it will work fine.
It's also a lot less work than creating your own wizard.