Does Visual Web Part support ObjectDataSource in designer? - visual-studio-2010

I'm trying to upgrade some Sharepoint 2007 webparts to SP2010 using the web part projects built into Visual Studio 2010. Namely, I'm using Visual Web Part to migrate our existing controls, which make extensive use of ObjectDataSource. However, when adding an ODS to the control in the Visual Web Part project, it will not pick up objects in referenced class library projects. I was able to duplicate the problem from a clean setup as follows:
Create a new Visual Web Part
Add a new class library to the solution.
Class code is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WebPartODS
{
[System.ComponentModel.DataObject(true)]
public class TestUser
{
[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select,false)]
public List<int> TestMethod()
{
return new List<int>();
}
}
}
Add the class library project as a reference in the Web Part project
In the VisualWebPart ascx file, add a objectdatasource in the Source view:
<asp:ObjectDataSource ID="TestOD" runat="server"></asp:ObjectDataSource>
Switch to Design view, bring up the "Configure data source" wizard. On the drop down, the class from the library project will not appear.
Is there a step that I am missing here, or is there an issue with trying to do it this way?

Ok, i got it to work. Here is where i got my answer: MSDN Forumn
I originally had a separate class for my business layer. I removed it and put my code in the ascx.cs file. Then I added the following line of code to my page load method.
ObjectDataSource1.TypeName = this.GetType().AssemblyQualifiedName;
I also removed the TypeName from the ascx page.

Related

I can't create a report with an object datasource in Visual studio 2019

I am trying to create a simple report in my vs2019 with a class as the data model
I have a public class named 'persona'
I have a new wpf applicacion (.net 5)
I've create a new report (RDLC file)
I try to use a class as a data template to design the report
When I try to reference the class as the data source object, the class is not visible for the datasourtce wizard as you can see in the image below
If put that class in a diferent project, a class library project, I got a different error, as you can see in the images below
And whe I press the Finish button I got this new erro:
There is no clue about what to do,... does anyone have any idea ? What Am I doing wrong?
I have same problem. Try to use netstandard2.0 for model library, it works for me (vs2019 netcoreapp3.1)

Visual 2017 Form Designer Failing On "Can't Find Class Error" - However, The Class Exists

I am adding some more control to a win form I created that runs from a .dll
The project loaded fine, after I made some changes to the form in the form visual designer, compiled and then tried to open the form... I was fronted with this error screen.
It is complaining because it can't find the NoButtonsTabControl class.
The NoTabControl.cs class:
namespace TFG_Tools {
// Extend TabControl Class to provide a multi layer canvas with hidden tabs or buttons
public class NoButtonsTabControl : TabControl {
public NoButtonsTabControl() {
Appearance = TabAppearance.FlatButtons;
ItemSize = new Size(0, 1);
//SizeMode = TabSizeMode.Fixed;
}
protected override void WndProc(ref Message m) {
// Hide tabs by trapping the TCM_ADJUSTRECT message
if (m.Msg == 0x1328) m.Result = (IntPtr)1;
else base.WndProc(ref m);
}
}// end NoButtonsTabControl class
}
The start of the main form class looks like this...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using ENSED;
using System.Globalization;
using Win32;
using WindowsEnv;
namespace TFG_Tools {
public partial class TradePanelForm : Form {
//loaded as master
private bool isMaster = false;
public void SetAsMaster() { isMaster = true; }
...
Why has this suddenly just happened now, so frustrating. I am only intermediate with c# and visual studio. I only used it for this project to create the winform.
How do I tell the designer where this class is, so this error stops appearing?
The funny thing is, it worked fine before, with this arrangement! And if I compile the code, it works, and all the form elements are there.
It's just the designer which is dying atm.
P.S I also moved this project over from Virtual Studio 2015
Thank you.
My solution to this was weird.
close down all open windows in your project
Select the "any cpu" profile
go build->clean solution
Then build->rebuild solution
Re open your form designer
This worked for me, and hopefully will clear this mess up each time it pops up.
I have 2 profiles, a 32bit and 64bit profile so I can compile the dll to both.
Something must break in the designer when I switch to these profiles to build the project.
Hopefully this saves time for others.

Is there a Preprocessed Razor Template for Visual Studio 2015

I am going thru this article here which talks about using the Razor template for Xamarin forms. I am however unable to find such a template in Visual Studio. The closest I came to was a nuget package. I don't think I can use that if I am to follow the example in the article above. Has anyone found any such problem before or can this only be done on Xamarin studio?
Why would they not make a provision for Visual Studio as well!
Just tried to use a razor template inside a Xamarin.Forms PCL and stumbled over the missing template. But then I followed the advice in the comments and it worked without any problems.
Add a new class (or whatever you want) to the portable project and name the file RazorTest.cshtml.
Replace the content of the new file with a skeleton like this:
Adjust the namespace and bind to your own ViewModel:
#using RazorTestNamespace.ViewModels
#model RazorTestViewModel
<html>
<body>
<h1>#Model.Title</h1>
</body>
</html>
Go to the class properties, find the CustomTool property and type in RazorTemplatePreprocessor. Then VisualStudio magically creates the belonging RazorTest.cs file with the code-behind.
Build the HTML when needed:
Inside the ViewModel:
RazorTest razorTest = new RazorTest { Model = razorTestViewModel };
string html = razorTest.GenerateString();

How to get Visual Studio to use the default namespace when creating a new class?

When I create a new class in a sub folder in my project, by default it uses DefaultNameSpace.SubFolder.
Anyway to make it just use the default namespace defined at the project level?
You would have to create a new template for Class. You can use the existing template and just remove the extra "fluff" on the namespace.
See this answer: How do I edit the Visual Studio templates for new C# class/interface?
The specific file to modify for your version of Visual Studio is:
C:\Program Files (x86)\Microsoft Visual Studio
14.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
You may want to make a copy of that structure and give your template a different name so you don't end up breaking the default template if you ever want to go back to it.
Edit
Looking at the tokens now, I don't see one specifically for the Default Namespace, $safeprojectname$ is probably as close as you get get using tokens, or just hard code it for your specific template. This is what the template would look like:
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;
$if$ ($targetframeworkversion$ >= 4.5)using System.Threading.Tasks;
$endif$
namespace $safeprojectname$
{
class $safeitemrootname$
{
}
}
You can find the predefined tokens here: https://msdn.microsoft.com/en-us/library/eehb4faa.aspx

2 times the same project in the Class View Window (visual studio)

After converting a Web Site Project to a Web Application Project in Visual Studio, it seems that there is a problem with some meta data. The first noticeable is the fact that the project is mentioned twice in the Class View window.
If I add a new namespace and a new class in it, I'm not able to select it using intellisense. when I open the hierarchy of the Class view, I see my new namespace in one of them (that are indentical except the recent addings)
Is there a way to clean that up ?
You have to get rid off the App Folder. That's the origin of this problem.
http://vishaljoshi.blogspot.be/2009/07/appcode-folder-doesnt-work-with-web.html

Resources