Showing posts with label custom. Show all posts
Showing posts with label custom. Show all posts

Saturday, March 31, 2012

Theming custom created WebParts in ASP.NET 2.0

I have created my own WebPart using code, it is not derived from a UserControl.
Inside this WebPart I create a Calendar Control and add it to the WebParts
Control collection.

Now I want to apply a theme to this Calendar that is inside my WebPart. How
do I do that? I have created a theme and added a definition for a calendar.
The theme is applied to a calendar that is not inside the WebPart, but it is
not applied to the one inside.Hi c_kimbell,

Welcome to MSDN newsgroup.
As for the custom WebPart with a Calendar inside it, is it possible that we
define a public property on the Custom webPart which represent the Theme of
the inside Calendar control? Then, we any one assign a new value for this
property, the nested calendar's Theme value will be changed accordingly.

In addition, for .NET 2.0 and VS.NET whidbey beta issues, I suggest you
also try posting in the following web forum:

http://forums.microsoft.com/msdn/

since there are some other experienced members who may have some good ideas.

Thank you,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Thanks for suggesting the ASP.NET forums, I have posted there now as well.

Here are some more details on what I have tried;
1. On the webpart I have exposed the Calendar as a property with the name
FromCalendar.
2. I have added the following to the .skin file

<%@. Register Assembly="IMK.WebParts" Namespace="IMK.WebParts"
TagPrefix="IMK" %
<IMK:IMKDateWebPart runat="server">
<FromCalendar BackColor="#FFFFCC">
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"
ForeColor="#FFFFCC" />
</FromCalendar>
</IMK:IMKDateWebPart
Am I on the right track?

"Steven Cheng[MSFT]" wrote:

> Hi c_kimbell,
> Welcome to MSDN newsgroup.
> As for the custom WebPart with a Calendar inside it, is it possible that we
> define a public property on the Custom webPart which represent the Theme of
> the inside Calendar control? Then, we any one assign a new value for this
> property, the nested calendar's Theme value will be changed accordingly.
> In addition, for .NET 2.0 and VS.NET whidbey beta issues, I suggest you
> also try posting in the following web forum:
> http://forums.microsoft.com/msdn/
> since there are some other experienced members who may have some good ideas.
> Thank you,
> Steven Cheng
> Microsoft Online Support
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
Hi c_kimbell,

Thanks for your followup.
As you mentioned that
=================

1. On the webpart I have exposed the Calendar as a property with the name
FromCalendar.
2. I have added the following to the .skin file

<%@. Register Assembly="IMK.WebParts" Namespace="IMK.WebParts"
TagPrefix="IMK" %
<IMK:IMKDateWebPart runat="server">
<FromCalendar BackColor="#FFFFCC">
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"
ForeColor="#FFFFCC" />
</FromCalendar>
</IMK:IMKDateWebPart>
=======================

I'm not sure whether this will cause error since I haven't tested it.
However, IMO, I'd prefer expose a single string property on my custom web
control which represent the nested child calendar's Theme(or
stylesheettheme). Since the ASP.NET 2.0 's Theme are mostly for those
simple type properteis (such as string, int), I think just exposing a
single string type property will be much better). You can do the actual
Theme adjusting in the Property's Setter method.
How do you think ?

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
I get your point about using simple strings. One thing though, say you expose
a color, this can be specified using a name like 'Red' or it may be specified
using hex notation, like '#FFCC66'. The controls require a Color object, how
does one map between the different representations and the Color object. Are
there any utility classes I can use?

I have now done a bit more experimenting. If I declaratively add the webpart
to a webpartzone, then the theme is correctly applied. If I add the same
webpart to the zone using a catalog, the style is not applied. The catalog
I'm adding from is a custom created one, not one of the predefined types.

Any suggestions?

"Steven Cheng[MSFT]" wrote:

> Hi c_kimbell,
> Thanks for your followup.
> As you mentioned that
> =================
>
> 1. On the webpart I have exposed the Calendar as a property with the name
> FromCalendar.
> 2. I have added the following to the .skin file
> <%@. Register Assembly="IMK.WebParts" Namespace="IMK.WebParts"
> TagPrefix="IMK" %>
> <IMK:IMKDateWebPart runat="server">
> <FromCalendar BackColor="#FFFFCC">
> <SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
> <TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"
> ForeColor="#FFFFCC" />
> </FromCalendar>
> </IMK:IMKDateWebPart>
> =======================
> I'm not sure whether this will cause error since I haven't tested it.
> However, IMO, I'd prefer expose a single string property on my custom web
> control which represent the nested child calendar's Theme(or
> stylesheettheme). Since the ASP.NET 2.0 's Theme are mostly for those
> simple type properteis (such as string, int), I think just exposing a
> single string type property will be much better). You can do the actual
> Theme adjusting in the Property's Setter method.
> How do you think ?
> Steven Cheng
> Microsoft Online Support
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
Hi c_kimbell,

For those Color field, the ASP.NET runtime's ControlParser will help parse
the property value into the correct object instance. And for Color, there
is the ColorTranslator class which can be used from convert string color
value to System.Drawing.Color instance. For example:

string htmlColor = "Blue";
//or string htmlColor = "#3344ee";
// Translate htmlColor to a GDI+ Color structure.
Color myColor = ColorTranslator.FromHtml(htmlColor);

For the applying theme for custom created catalog's webpart, I'm not sure
whether this is ok. As far as I know, since the ASP.NET2.0 runtime apply
theme for controls in the page's PreInit event, so any change on Theme
after that event (for example in Page_load ..., post back event) will not
work in the first loading...

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Wednesday, March 28, 2012

They LIED!

I have designed a custom control and have been trying to set the TagPrefix and ToolBoxBitmap image to the control, but none of it is working!

Adding the TagPrefix to the control

To set the TagPrefix it's says to do this

'Within the AssemblyInfo.vb file add this
Imports System.Web.UI

'<Assembly: TagPrefix("Namespace Name", "TagPrefix")>
<Assembly: TagPrefix("JHAControls", "JHA")>

When I add my control to the page it shows up as this in the HTML

<%@dotnet.itags.org. Register TagPrefix="cc1" Namespace="JHACustomControls.JHAControls" Assembly="JHACustomControls" %>

the TagPrefix should be "JHA", not "cc1", which is the default.

Why doesn't this doesn't work!?

Adding an icon to the custom control
To add an icon to the custom control, it says to do this.
Assuming the icon is the same name as your class, which it is (JHATextBox class, and JHATextBox.bmp icon)

1) Create a 16x16 pixel bmp icon. which I did.
2) Add the icon to the project, which I did.
3) Set the icons build action to "Embedded Resource", which I did
4) Rebuild the project and the icon will display in the toolbox when the control is added.

This doesn't work either, I still get the default "gears" icon.

I can get the icon to work, but only if I specify the absolute path to the file (C:\MyFolder\MyFile.bmp). But then the control (.dll file) doesn't work on another computer unless the image exists in the same location on that computer.

Anyone know why these aren't working??I finally got the first part (TagPrefix) working...It isnt' only the namespace name that is needed...it is the SolutionName.Namespace name.

So instead of

<Assembly: TagPrefix("JHAControls", "JHA")>

it had to be

<Assembly: TagPrefix("JHACustomControls.JHAControls", "JHA")>

Where JHACustomControls is the name of the solution or project, then the namespace.

I still haven't figured out the icon part though.
I got it all fixed.
I removed the namespace from my class and the icon displayed just fine.
Thanks for the help!
What Help ?

I should be thanking you as you are miles ahead of me in .net.
I am finding it very difficult. Especially ADO.net.
I was being sarcastic, as it doesn't appear that anyone here has done, what I was trying to do.

.NET is pretty straight forward once you understand the basics.
If you need help just ask.
I have. I just haven't been around for a week. I have an entire toolbox tab full of controls with pretty icons. That tagPrefix is jumpy though it'll get lost and you'll have to mess with and force a full rebuild instead of the partial that is done default to fix it. And as best as I can tell you can only have one tagPrefix two even though the namespace is diffrent won't work.

Have you looked at designers yet. they are interesting to say the least.

This code crashes, what am I doing wrong??

ASP.NET 2.0

This code crashes. It generate this error:
Value cannot be null.
Parameter name: type

I've created some custom web.config settings and this crash is related to
accessing theme custom settings. This code is where the crash occur:
_instance =
(DAL)Activator.CreateInstance(Type.GetType(min.tes t.Config.Settings.msgElement.ProviderType));
This code is trying to do is to create an instance of the DAL provider,

************* custom web.config settings: **********************
<configSections>
<section name="msg" type="min.test.ConfigSection, __code"/>
</configSections>
<msg>
<messages providerType="min.test.DAL.SqlServer2005"/>
</msg>

********* In this code the crash occur *********
/* This code is from the DAL class, this code is trying to create an
instance of the DAL set in web.config - min.test.DAL.SqlServer2005
static public DAL Instance
{
get
{
if (_instance == null)
_instance =
(DAL)Activator.CreateInstance(Type.GetType(min.tes t.Config.Settings.msgElement.ProviderType));
<-- code crashes here
return _instance;
}
}

******** definition of the custom settings in web.config
**********************
using System;
using System.Collections.Generic;
using System.Configuration;

namespace min.test
{
public class ConfigSection : ConfigurationSection
{
[ConfigurationProperty("messages", IsRequired = true)]
public MsgElement msgElement
{
get { return (MsgElement)base["messages"]; }
}

}

public class MsgElement : ConfigurationElement
{
[ConfigurationProperty("providerType", DefaultValue =
"min.test.DAL.SqlServer2005")]
public string ProviderType
{
get { return (string)base["providerType"]; }
set { base["providerType"] = value; }
}
}

}

Any suggestions??

JeffWell,
The exception message doesn't lie - it's telling you that you've got a null
value, and it cannot accept it and continue.

One way to get at this is to "take apart" your compound statement so that it
will becom easier to set breakpoints and examine values, e.g.:

instance =
(DAL)Activator.CreateInstance(Type.GetType(min.tes t.Config.Settings.msgElement.ProviderType));

could be:

Type t = Type.GetType(min.test.Config.Settings.msgElement.P roviderType);
// check to see if t above is null.

instance = (DAL)Activator.CreateInstance(t);

Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Jeff" wrote:

Quote:

Originally Posted by

ASP.NET 2.0
>
This code crashes. It generate this error:
Value cannot be null.
Parameter name: type
>
I've created some custom web.config settings and this crash is related to
accessing theme custom settings. This code is where the crash occur:
_instance =
(DAL)Activator.CreateInstance(Type.GetType(min.tes t.Config.Settings.msgElement.ProviderType));
This code is trying to do is to create an instance of the DAL provider,
>
************* custom web.config settings: **********************
<configSections>
<section name="msg" type="min.test.ConfigSection, __code"/>
</configSections>
<msg>
<messages providerType="min.test.DAL.SqlServer2005"/>
</msg>
>
********* In this code the crash occur *********
/* This code is from the DAL class, this code is trying to create an
instance of the DAL set in web.config - min.test.DAL.SqlServer2005
static public DAL Instance
{
get
{
if (_instance == null)
_instance =
(DAL)Activator.CreateInstance(Type.GetType(min.tes t.Config.Settings.msgElement.ProviderType));
<-- code crashes here
return _instance;
}
}
>
******** definition of the custom settings in web.config
**********************
using System;
using System.Collections.Generic;
using System.Configuration;
>
namespace min.test
{
public class ConfigSection : ConfigurationSection
{
[ConfigurationProperty("messages", IsRequired = true)]
public MsgElement msgElement
{
get { return (MsgElement)base["messages"]; }
}
>
}
>
public class MsgElement : ConfigurationElement
{
[ConfigurationProperty("providerType", DefaultValue =
"min.test.DAL.SqlServer2005")]
public string ProviderType
{
get { return (string)base["providerType"]; }
set { base["providerType"] = value; }
}
}
>
}
>
Any suggestions??
>
Jeff
>
>
>


Thanks

Type t = Type.GetType(min.test.Config.Settings.msgElement.P roviderType);
t gets a NULL value here. I've looked at the web.config settings and the
code that creates the custom web.config settings and I cannot see what I'm
doing wrong here... or maybe I'm becoming blind to my own programming
errors. Do you see why it get NULL value??

Jeff

"Peter Bromberg [C# MVP]" <pbromberg@.yahoo.yabbadabbadoo.comwrote in
message news:ACE60486-118C-4BB2-A1C1-EB2416FB1CED@.microsoft.com...

Quote:

Originally Posted by

Well,
The exception message doesn't lie - it's telling you that you've got a
null
value, and it cannot accept it and continue.
>
One way to get at this is to "take apart" your compound statement so that
it
will becom easier to set breakpoints and examine values, e.g.:
>
instance =
(DAL)Activator.CreateInstance(Type.GetType(min.tes t.Config.Settings.msgElement.ProviderType));
>
could be:
>
Type t = Type.GetType(min.test.Config.Settings.msgElement.P roviderType);
// check to see if t above is null.
>
instance = (DAL)Activator.CreateInstance(t);
>
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
>
>
>
>
"Jeff" wrote:
>

Quote:

Originally Posted by

>ASP.NET 2.0
>>
>This code crashes. It generate this error:
>Value cannot be null.
>Parameter name: type
>>
>I've created some custom web.config settings and this crash is related to
>accessing theme custom settings. This code is where the crash occur:
>_instance =
>(DAL)Activator.CreateInstance(Type.GetType(min.tes t.Config.Settings.msgElement.ProviderType));
>This code is trying to do is to create an instance of the DAL provider,
>>
>************* custom web.config settings: **********************
><configSections>
> <section name="msg" type="min.test.ConfigSection, __code"/>
></configSections>
><msg>
> <messages providerType="min.test.DAL.SqlServer2005"/>
></msg>
>>
>********* In this code the crash occur *********
>/* This code is from the DAL class, this code is trying to create an
>instance of the DAL set in web.config - min.test.DAL.SqlServer2005
>static public DAL Instance
>{
> get
> {
> if (_instance == null)
> _instance =
>(DAL)Activator.CreateInstance(Type.GetType(min.tes t.Config.Settings.msgElement.ProviderType));
><-- code crashes here
> return _instance;
> }
>}
>>
>******** definition of the custom settings in web.config
>**********************
>using System;
>using System.Collections.Generic;
>using System.Configuration;
>>
>namespace min.test
>{
> public class ConfigSection : ConfigurationSection
> {
> [ConfigurationProperty("messages", IsRequired = true)]
> public MsgElement msgElement
> {
> get { return (MsgElement)base["messages"]; }
> }
>>
> }
>>
> public class MsgElement : ConfigurationElement
> {
> [ConfigurationProperty("providerType", DefaultValue =
>"min.test.DAL.SqlServer2005")]
> public string ProviderType
> {
> get { return (string)base["providerType"]; }
> set { base["providerType"] = value; }
> }
> }
>>
>}
>>
>Any suggestions??
>>
>Jeff
>>
>>
>>


Type.GetType gives you the ability to get a type back from a string. You pass
a known, available type name string to it, and expect it return that type.

If the assembly name is specified in the typeName string, Type.GetType()
will search inside this assembly only; otherwise, it tries to find one in the
caller assembly and then the system assembly (mscorlib.dll). Anything after
',' in the typeName string is treated as assembly name. To make it work,you
need to specify "YourAssembly.dll" in typeName. In contrast,
Type.GetType("System.Int32") can return type System.Int32 without mentioning
"mscorlib.dll".

Type.AssemblyQualifiedName is the right way to tell what kind of typeName
you should provide.
typeof(System.Data.SqlClient.SqlException).Assembl yQualifiedName equals:
"System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089". Type.GetType with this
long string will succeed in .NET 2.0.

In .NET, namespace and the associated assembly name are not necessarily
related. Type "System.Data.SqlClient.SqlException" is not associated with
"System.Data.SqlClient.dll" (which does not exist).

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Jeff" wrote:

Quote:

Originally Posted by

Thanks
>
Type t = Type.GetType(min.test.Config.Settings.msgElement.P roviderType);
t gets a NULL value here. I've looked at the web.config settings and the
code that creates the custom web.config settings and I cannot see what I'm
doing wrong here... or maybe I'm becoming blind to my own programming
errors. Do you see why it get NULL value??
>
Jeff
>
"Peter Bromberg [C# MVP]" <pbromberg@.yahoo.yabbadabbadoo.comwrote in
message news:ACE60486-118C-4BB2-A1C1-EB2416FB1CED@.microsoft.com...

Quote:

Originally Posted by

Well,
The exception message doesn't lie - it's telling you that you've got a
null
value, and it cannot accept it and continue.

One way to get at this is to "take apart" your compound statement so that
it
will becom easier to set breakpoints and examine values, e.g.:

instance =
(DAL)Activator.CreateInstance(Type.GetType(min.tes t.Config.Settings.msgElement.ProviderType));

could be:

Type t = Type.GetType(min.test.Config.Settings.msgElement.P roviderType);
// check to see if t above is null.

instance = (DAL)Activator.CreateInstance(t);

Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Jeff" wrote:

Quote:

Originally Posted by

ASP.NET 2.0
>
This code crashes. It generate this error:
Value cannot be null.
Parameter name: type
>
I've created some custom web.config settings and this crash is related to
accessing theme custom settings. This code is where the crash occur:
_instance =
(DAL)Activator.CreateInstance(Type.GetType(min.tes t.Config.Settings.msgElement.ProviderType));
This code is trying to do is to create an instance of the DAL provider,
>
************* custom web.config settings: **********************
<configSections>
<section name="msg" type="min.test.ConfigSection, __code"/>
</configSections>
<msg>
<messages providerType="min.test.DAL.SqlServer2005"/>
</msg>
>
********* In this code the crash occur *********
/* This code is from the DAL class, this code is trying to create an
instance of the DAL set in web.config - min.test.DAL.SqlServer2005
static public DAL Instance
{
get
{
if (_instance == null)
_instance =
(DAL)Activator.CreateInstance(Type.GetType(min.tes t.Config.Settings.msgElement.ProviderType));
<-- code crashes here
return _instance;
}
}
>
******** definition of the custom settings in web.config
**********************
using System;
using System.Collections.Generic;
using System.Configuration;
>
namespace min.test
{
public class ConfigSection : ConfigurationSection
{
[ConfigurationProperty("messages", IsRequired = true)]
public MsgElement msgElement
{
get { return (MsgElement)base["messages"]; }
}
>
}
>
public class MsgElement : ConfigurationElement
{
[ConfigurationProperty("providerType", DefaultValue =
"min.test.DAL.SqlServer2005")]
public string ProviderType
{
get { return (string)base["providerType"]; }
set { base["providerType"] = value; }
}
}
>
}
>
Any suggestions??
>
Jeff
>
>
>


>
>
>


Jeff,

In addition to Peter's reply, there's another way of obtaining the reference
in ASP.NET 2.0 dynamic compilation enviroment. Please use
System.Web.Compilation.BuildManager.GetType(min.te st.Config.Settings.msgElement.ProviderType, true);
instead.

Regards
--
Milosz

"Peter Bromberg [C# MVP]" wrote:

Quote:

Originally Posted by

Type.GetType gives you the ability to get a type back from a string. You pass
a known, available type name string to it, and expect it return that type.
>
If the assembly name is specified in the typeName string, Type.GetType()
will search inside this assembly only; otherwise, it tries to find one in the
caller assembly and then the system assembly (mscorlib.dll). Anything after
',' in the typeName string is treated as assembly name. To make it work,you
need to specify "YourAssembly.dll" in typeName. In contrast,
Type.GetType("System.Int32") can return type System.Int32 without mentioning
"mscorlib.dll".
>
Type.AssemblyQualifiedName is the right way to tell what kind of typeName
you should provide.
typeof(System.Data.SqlClient.SqlException).Assembl yQualifiedName equals:
"System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089". Type.GetType with this
long string will succeed in .NET 2.0.
>
In .NET, namespace and the associated assembly name are not necessarily
related. Type "System.Data.SqlClient.SqlException" is not associated with
"System.Data.SqlClient.dll" (which does not exist).
>
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
>
>
>
>
"Jeff" wrote:
>

Quote:

Originally Posted by

Thanks

Type t = Type.GetType(min.test.Config.Settings.msgElement.P roviderType);
t gets a NULL value here. I've looked at the web.config settings and the
code that creates the custom web.config settings and I cannot see what I'm
doing wrong here... or maybe I'm becoming blind to my own programming
errors. Do you see why it get NULL value??

Jeff

"Peter Bromberg [C# MVP]" <pbromberg@.yahoo.yabbadabbadoo.comwrote in
message news:ACE60486-118C-4BB2-A1C1-EB2416FB1CED@.microsoft.com...

Quote:

Originally Posted by

Well,
The exception message doesn't lie - it's telling you that you've got a
null
value, and it cannot accept it and continue.
>
One way to get at this is to "take apart" your compound statement so that
it
will becom easier to set breakpoints and examine values, e.g.:
>
instance =
(DAL)Activator.CreateInstance(Type.GetType(min.tes t.Config.Settings.msgElement.ProviderType));
>
could be:
>
Type t = Type.GetType(min.test.Config.Settings.msgElement.P roviderType);
// check to see if t above is null.
>
instance = (DAL)Activator.CreateInstance(t);
>
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
>
>
>
>
"Jeff" wrote:
>
>ASP.NET 2.0
>>
>This code crashes. It generate this error:
>Value cannot be null.
>Parameter name: type
>>
>I've created some custom web.config settings and this crash is related to
>accessing theme custom settings. This code is where the crash occur:
>_instance =
>(DAL)Activator.CreateInstance(Type.GetType(min.tes t.Config.Settings.msgElement.ProviderType));
>This code is trying to do is to create an instance of the DAL provider,
>>
>************* custom web.config settings: **********************
><configSections>
> <section name="msg" type="min.test.ConfigSection, __code"/>
></configSections>
><msg>
> <messages providerType="min.test.DAL.SqlServer2005"/>
></msg>
>>
>********* In this code the crash occur *********
>/* This code is from the DAL class, this code is trying to create an
>instance of the DAL set in web.config - min.test.DAL.SqlServer2005
>static public DAL Instance
>{
> get
> {
> if (_instance == null)
> _instance =
>(DAL)Activator.CreateInstance(Type.GetType(min.tes t.Config.Settings.msgElement.ProviderType));
><-- code crashes here
> return _instance;
> }
>}
>>
>******** definition of the custom settings in web.config
>**********************
>using System;
>using System.Collections.Generic;
>using System.Configuration;
>>
>namespace min.test
>{
> public class ConfigSection : ConfigurationSection
> {
> [ConfigurationProperty("messages", IsRequired = true)]
> public MsgElement msgElement
> {
> get { return (MsgElement)base["messages"]; }
> }
>>
> }
>>
> public class MsgElement : ConfigurationElement
> {
> [ConfigurationProperty("providerType", DefaultValue =
>"min.test.DAL.SqlServer2005")]
> public string ProviderType
> {
> get { return (string)base["providerType"]; }
> set { base["providerType"] = value; }
> }
> }
>>
>}
>>
>Any suggestions??
>>
>Jeff
>>
>>
>>



thank you guys, you helped me solve this problem.

This is a bit embarrassing. I tryed to create an instance of this class:
min.test.DAL.SqlServer2005, but this class don't exist in my project.
min.test.DAL.SqlServer2005.SqlServer2005 is the class I needed... I had
forgot that I had a namespace with the same name as the class...
anyway I changed the .SqlServer2005 namespace to SqlClient so now I'm
accessing min.test.DAL.SqlClient.SqlServer2005

once again, thank you

cheers

Jeff

"Milosz Skalecki [MCAD]" <mily242@.DONTLIKESPAMwp.plwrote in message
news:FB62B8F3-8DAE-4E81-917C-935316F2CFE8@.microsoft.com...

Quote:

Originally Posted by

Jeff,
>
In addition to Peter's reply, there's another way of obtaining the
reference
in ASP.NET 2.0 dynamic compilation enviroment. Please use
System.Web.Compilation.BuildManager.GetType(min.te st.Config.Settings.msgElement.ProviderType,
true);
instead.
>
Regards
--
Milosz
>
>
"Peter Bromberg [C# MVP]" wrote:
>

Quote:

Originally Posted by

>Type.GetType gives you the ability to get a type back from a string. You
>pass
>a known, available type name string to it, and expect it return that
>type.
>>
>If the assembly name is specified in the typeName string, Type.GetType()
>will search inside this assembly only; otherwise, it tries to find one in
>the
>caller assembly and then the system assembly (mscorlib.dll). Anything
>after
>',' in the typeName string is treated as assembly name. To make it
>work,you
>need to specify "YourAssembly.dll" in typeName. In contrast,
>Type.GetType("System.Int32") can return type System.Int32 without
>mentioning
>"mscorlib.dll".
>>
>Type.AssemblyQualifiedName is the right way to tell what kind of typeName
>you should provide.
>typeof(System.Data.SqlClient.SqlException).Assembl yQualifiedName equals:
>"System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0,
>Culture=neutral, PublicKeyToken=b77a5c561934e089". Type.GetType with this
>long string will succeed in .NET 2.0.
>>
>In .NET, namespace and the associated assembly name are not necessarily
>related. Type "System.Data.SqlClient.SqlException" is not associated with
>"System.Data.SqlClient.dll" (which does not exist).
>>
>-- Peter
>Site: http://www.eggheadcafe.com
>UnBlog: http://petesbloggerama.blogspot.com
>Short urls & more: http://ittyurl.net
>>
>>
>>
>>
>"Jeff" wrote:
>>

Quote:

Originally Posted by

Thanks
>
Type t =
Type.GetType(min.test.Config.Settings.msgElement.P roviderType);
t gets a NULL value here. I've looked at the web.config settings and
the
code that creates the custom web.config settings and I cannot see what
I'm
doing wrong here... or maybe I'm becoming blind to my own programming
errors. Do you see why it get NULL value??
>
Jeff
>
"Peter Bromberg [C# MVP]" <pbromberg@.yahoo.yabbadabbadoo.comwrote in
message news:ACE60486-118C-4BB2-A1C1-EB2416FB1CED@.microsoft.com...
Well,
The exception message doesn't lie - it's telling you that you've got
a
null
value, and it cannot accept it and continue.
>
One way to get at this is to "take apart" your compound statement so
that
it
will becom easier to set breakpoints and examine values, e.g.:
>
instance =
(DAL)Activator.CreateInstance(Type.GetType(min.tes t.Config.Settings.msgElement.ProviderType));
>
could be:
>
Type t =
Type.GetType(min.test.Config.Settings.msgElement.P roviderType);
// check to see if t above is null.
>
instance = (DAL)Activator.CreateInstance(t);
>
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
>
>
>
>
"Jeff" wrote:
>
>ASP.NET 2.0
>>
>This code crashes. It generate this error:
>Value cannot be null.
>Parameter name: type
>>
>I've created some custom web.config settings and this crash is
>related to
>accessing theme custom settings. This code is where the crash occur:
>_instance =
>(DAL)Activator.CreateInstance(Type.GetType(min.tes t.Config.Settings.msgElement.ProviderType));
>This code is trying to do is to create an instance of the DAL
>provider,
>>
>************* custom web.config settings: **********************
><configSections>
> <section name="msg" type="min.test.ConfigSection, __code"/>
></configSections>
><msg>
> <messages providerType="min.test.DAL.SqlServer2005"/>
></msg>
>>
>********* In this code the crash occur *********
>/* This code is from the DAL class, this code is trying to create an
>instance of the DAL set in web.config - min.test.DAL.SqlServer2005
>static public DAL Instance
>{
> get
> {
> if (_instance == null)
> _instance =
>(DAL)Activator.CreateInstance(Type.GetType(min.tes t.Config.Settings.msgElement.ProviderType));
><-- code crashes here
> return _instance;
> }
>}
>>
>******** definition of the custom settings in web.config
>**********************
>using System;
>using System.Collections.Generic;
>using System.Configuration;
>>
>namespace min.test
>{
> public class ConfigSection : ConfigurationSection
> {
> [ConfigurationProperty("messages", IsRequired = true)]
> public MsgElement msgElement
> {
> get { return (MsgElement)base["messages"]; }
> }
>>
> }
>>
> public class MsgElement : ConfigurationElement
> {
> [ConfigurationProperty("providerType", DefaultValue =
>"min.test.DAL.SqlServer2005")]
> public string ProviderType
> {
> get { return (string)base["providerType"]; }
> set { base["providerType"] = value; }
> }
> }
>>
>}
>>
>Any suggestions??
>>
>Jeff
>>
>>
>>
>
>
>

This code crashes, what am I doing wrong??

ASP.NET 2.0
This code crashes. It generate this error:
Value cannot be null.
Parameter name: type
I've created some custom web.config settings and this crash is related to
accessing theme custom settings. This code is where the crash occur:
_instance =
(DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgEleme
nt.ProviderType));
This code is trying to do is to create an instance of the DAL provider,
************* custom web.config settings: **********************
<configSections>
<section name="msg" type="min.test.ConfigSection, __code"/>
</configSections>
<msg>
<messages providerType="min.test.DAL.SqlServer2005"/>
</msg>
********* In this code the crash occur *********
/* This code is from the DAL class, this code is trying to create an
instance of the DAL set in web.config - min.test.DAL.SqlServer2005
static public DAL Instance
{
get
{
if (_instance == null)
_instance =
(DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgEleme
nt.ProviderType));
<-- code crashes here
return _instance;
}
}
******** definition of the custom settings in web.config
**********************
using System;
using System.Collections.Generic;
using System.Configuration;
namespace min.test
{
public class ConfigSection : ConfigurationSection
{
[ConfigurationProperty("messages", IsRequired = true)]
public MsgElement msgElement
{
get { return (MsgElement)base["messages"]; }
}
}
public class MsgElement : ConfigurationElement
{
[ConfigurationProperty("providerType", DefaultValue =
"min.test.DAL.SqlServer2005")]
public string ProviderType
{
get { return (string)base["providerType"]; }
set { base["providerType"] = value; }
}
}
}
Any suggestions'
JeffWell,
The exception message doesn't lie - it's telling you that you've got a null
value, and it cannot accept it and continue.
One way to get at this is to "take apart" your compound statement so that it
will becom easier to set breakpoints and examine values, e.g.:
instance =
(DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgEleme
nt.ProviderType));
could be:
Type t = Type.GetType(min.test.Config.Settings.msgElement.ProviderType);
// check to see if t above is null.
instance = (DAL)Activator.CreateInstance(t);
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Jeff" wrote:

> ASP.NET 2.0
> This code crashes. It generate this error:
> Value cannot be null.
> Parameter name: type
> I've created some custom web.config settings and this crash is related to
> accessing theme custom settings. This code is where the crash occur:
> _instance =
> (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgEle
ment.ProviderType));
> This code is trying to do is to create an instance of the DAL provider,
> ************* custom web.config settings: **********************
> <configSections>
> <section name="msg" type="min.test.ConfigSection, __code"/>
> </configSections>
> <msg>
> <messages providerType="min.test.DAL.SqlServer2005"/>
> </msg>
> ********* In this code the crash occur *********
> /* This code is from the DAL class, this code is trying to create an
> instance of the DAL set in web.config - min.test.DAL.SqlServer2005
> static public DAL Instance
> {
> get
> {
> if (_instance == null)
> _instance =
> (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgEle
ment.ProviderType));
> <-- code crashes here
> return _instance;
> }
> }
> ******** definition of the custom settings in web.config
> **********************
> using System;
> using System.Collections.Generic;
> using System.Configuration;
> namespace min.test
> {
> public class ConfigSection : ConfigurationSection
> {
> [ConfigurationProperty("messages", IsRequired = true)]
> public MsgElement msgElement
> {
> get { return (MsgElement)base["messages"]; }
> }
> }
> public class MsgElement : ConfigurationElement
> {
> [ConfigurationProperty("providerType", DefaultValue =
> "min.test.DAL.SqlServer2005")]
> public string ProviderType
> {
> get { return (string)base["providerType"]; }
> set { base["providerType"] = value; }
> }
> }
> }
> Any suggestions'
> Jeff
>
>
Thanks
Type t = Type.GetType(min.test.Config.Settings.msgElement.ProviderType);
t gets a NULL value here. I've looked at the web.config settings and the
code that creates the custom web.config settings and I cannot see what I'm
doing wrong here... or maybe I'm becoming blind to my own programming
errors. Do you see why it get NULL value'
Jeff
"Peter Bromberg [C# MVP]" <pbromberg@.yahoo.yabbadabbadoo.com> wrote in
message news:ACE60486-118C-4BB2-A1C1-EB2416FB1CED@.microsoft.com...
> Well,
> The exception message doesn't lie - it's telling you that you've got a
> null
> value, and it cannot accept it and continue.
> One way to get at this is to "take apart" your compound statement so that
> it
> will becom easier to set breakpoints and examine values, e.g.:
> instance =
> (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgEle
ment.ProviderType));
> could be:
> Type t = Type.GetType(min.test.Config.Settings.msgElement.ProviderType);
> // check to see if t above is null.
> instance = (DAL)Activator.CreateInstance(t);
> Peter
> --
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> Short urls & more: http://ittyurl.net
>
>
> "Jeff" wrote:
>
Type.GetType gives you the ability to get a type back from a string. You pas
s
a known, available type name string to it, and expect it return that type.
If the assembly name is specified in the typeName string, Type.GetType()
will search inside this assembly only; otherwise, it tries to find one in th
e
caller assembly and then the system assembly (mscorlib.dll). Anything after
',' in the typeName string is treated as assembly name. To make it work,you
need to specify "YourAssembly.dll" in typeName. In contrast,
Type.GetType("System.Int32") can return type System.Int32 without mentioning
"mscorlib.dll".
Type.AssemblyQualifiedName is the right way to tell what kind of typeName
you should provide.
typeof(System.Data.SqlClient.SqlException).AssemblyQualifiedName equals:
"System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089". Type.GetType with this
long string will succeed in .NET 2.0.
In .NET, namespace and the associated assembly name are not necessarily
related. Type "System.Data.SqlClient.SqlException" is not associated with
"System.Data.SqlClient.dll" (which does not exist).
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Jeff" wrote:

> Thanks
> Type t = Type.GetType(min.test.Config.Settings.msgElement.ProviderType);
> t gets a NULL value here. I've looked at the web.config settings and the
> code that creates the custom web.config settings and I cannot see what I'm
> doing wrong here... or maybe I'm becoming blind to my own programming
> errors. Do you see why it get NULL value'
> Jeff
> "Peter Bromberg [C# MVP]" <pbromberg@.yahoo.yabbadabbadoo.com> wrote in
> message news:ACE60486-118C-4BB2-A1C1-EB2416FB1CED@.microsoft.com...
>
>
Jeff,
In addition to Peter's reply, there's another way of obtaining the reference
in ASP.NET 2.0 dynamic compilation enviroment. Please use
System.Web.Compilation.BuildManager.GetType(min.test.Config.Settings.msgElem
ent.ProviderType, true);
instead.
Regards
--
Milosz
"Peter Bromberg [C# MVP]" wrote:
> Type.GetType gives you the ability to get a type back from a string. You p
ass
> a known, available type name string to it, and expect it return that type.
> If the assembly name is specified in the typeName string, Type.GetType()
> will search inside this assembly only; otherwise, it tries to find one in
the
> caller assembly and then the system assembly (mscorlib.dll). Anything afte
r
> ',' in the typeName string is treated as assembly name. To make it work,yo
u
> need to specify "YourAssembly.dll" in typeName. In contrast,
> Type.GetType("System.Int32") can return type System.Int32 without mentioni
ng
> "mscorlib.dll".
> Type.AssemblyQualifiedName is the right way to tell what kind of typeName
> you should provide.
> typeof(System.Data.SqlClient.SqlException).AssemblyQualifiedName equals:
> "System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0,
> Culture=neutral, PublicKeyToken=b77a5c561934e089". Type.GetType with this
> long string will succeed in .NET 2.0.
> In .NET, namespace and the associated assembly name are not necessarily
> related. Type "System.Data.SqlClient.SqlException" is not associated with
> "System.Data.SqlClient.dll" (which does not exist).
> -- Peter
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> Short urls & more: http://ittyurl.net
>
>
> "Jeff" wrote:
>
thank you guys, you helped me solve this problem.
This is a bit embarrassing. I tryed to create an instance of this class:
min.test.DAL.SqlServer2005, but this class don't exist in my project.
min.test.DAL.SqlServer2005.SqlServer2005 is the class I needed... I had
forgot that I had a namespace with the same name as the class...
anyway I changed the .SqlServer2005 namespace to SqlClient so now I'm
accessing min.test.DAL.SqlClient.SqlServer2005
once again, thank you
cheers
Jeff
"Milosz Skalecki [MCAD]" <mily242@.DONTLIKESPAMwp.pl> wrote in message
news:FB62B8F3-8DAE-4E81-917C-935316F2CFE8@.microsoft.com...
> Jeff,
> In addition to Peter's reply, there's another way of obtaining the
> reference
> in ASP.NET 2.0 dynamic compilation enviroment. Please use
> System.Web.Compilation.BuildManager.GetType(min.test.Config.Settings.msgEl
ement.ProviderType,
> true);
> instead.
> Regards
> --
> Milosz
>
> "Peter Bromberg [C# MVP]" wrote:
>

Monday, March 26, 2012

This is killing me... need to display custom HTML from remote site to a calling site

Ok, I hope someone has done this or can help me here as I'm having trouble finding what I need.

What I want to do is allow users to include a javascript file in their website that will go out and pull data from my site / db and display it on their website. What will happen is they pass over some specific information that indicates what they want returned and then I'll serve it to their website where it displays in a naturally embedded format and looks like it's part of their own content.

An example of what I want to do is the same as the following:

 <div style="padding-left:10px; padding-right:10px;">
<asp:PlaceHolder ID="plcContent"runat="Server">
<script language="javascript" src="http://pics.10026.com/?src=http://www.datafeedfile.com/dff_jsthrow.php?affid=1001&script=search_index&style=12"></script>
</asp:PlaceHolder>
</div>

What the above line does is display contents (full HTML) from data feed file onto a webpage (shopping content), but doesn't actually render the full HTML to the webpage (if you right-click and view source). I want to do the same thing where someone calls a .ASPX or .ASMX page / service and I return (or serve) the HTML content. So, a call to my app may look like:

 <div style="padding-left:10px; padding-right:10px;">
<asp:PlaceHolder ID="plcContent"runat="Server">
<script language="javascript" src="http://pics.10026.com/?src=http://www.mysite.com/contentsource.aspx?affid=1001&type=X"></script>
</asp:PlaceHolder>
</div>
The contentsource.aspx page will then return (or display) a listing of products from my website on the calling website.  

Can that be done in ASP.NET 2.0? Any help much appreciated as I've been searching for a couple days (and many many hours of trial and error) with no luck. Thanks!

Hi,

Try to use IFRAME, see http://www.w3schools.com/tags/tag_iframe.asp


Add this to your page (and remove html from the ASPX that shouldn't be there, such as <body>, <head> etc.)

protected override void Render(HtmlTextWriter writer)
{
StringBuilder sb=new StringBuilder();
StringWriter sw =new StringWriter(sb);
HtmlTextWriter hw =new HtmlTextWriter(sw);
base.Render(hw);

Response.Clear();
Response.ContentType ="text/javascript";

string html =string.Format("window.document.write({0});",Enquote(sb.ToString()));
writer.Write(html);

}

/// FUNCTION Enquote Public Domain 2002 JSON.org
/// @.author JSON.org
/// @.version 0.1
/// Ported to C# by Are Bjolseth, teleplan.no
public static string Enquote(string s)
{
if (s ==null || s.Length == 0)
{
return"\"\"";
}
char c;
int i;
int len = s.Length;
StringBuilder sb =new StringBuilder(len + 4);
string t;

sb.Append('"');
for (i = 0; i < len; i += 1)
{
c = s[i];
if ((c =='\\') || (c =='"') || (c =='>'))
{
sb.Append('\\');
sb.Append(c);
}
else if (c =='\b')
sb.Append("\\b");
else if (c =='\t')
sb.Append("\\t");
else if (c =='\n')
sb.Append("\\n");
else if (c =='\f')
sb.Append("\\f");
else if (c =='\r')
sb.Append("\\r");
else
{
if (c <' ')
{
//t = "000" + Integer.toHexString(c);
string tmp =new string(c, 1);
t ="000" +int.Parse(tmp, System.Globalization.NumberStyles.HexNumber);
sb.Append("\\u" + t.Substring(t.Length - 4));
}
else
{
sb.Append(c);
}
}
}
sb.Append('"');
return sb.ToString();
}


Thanks, but that doesn't quit work for what I want. I just want users to be able to do it via a javascript call like in the example I provided. IFrames are kinda ugly, clunky, and not really something I would want to ask users to drop into their sites. I appreciate the reply though!


guntem,

That's exactly what I needed! Very very much appreciated as you've saved me much time and frustration.

David

Saturday, March 24, 2012

this.Controls.Add()

I am developing a series of custom controls which get
added to a parent aspx container using the instruction
this.Controls.Add( myControl ). The parent application
creates an html table dynamically, and for each table row,
adds upwards of seven custom controls per row, which are
initially hidden. Custom controls are displayed based on
buttons the user clicks on a given row. When the
application processes renders table rows in an amount
greater than thirty, the application takes over 30 seconds
to render the entire page. We have used .NET profiler and
have determined the instruction this.Controls.Add(
myCustomControl ) is where execution time is being
consumed. My custom controls are simply c-sharp classes
with a Page_Load handler. These custom classes in turn
render a series of web-based .NET controls.

Why is the instruction this.Controls.Add() performing
slow? I have 1 gig of memory on my workstation.

SteveHi Steve,

Did this problem occur with a particualr custom control? For example, when
you add it with this.Controls.Add, it run slowly? If you add 30 same custom
controls, will this problem also occur?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Hi Luke,

Nope. The problem is apparent with all custom controls
added I've implemented. There are three main
this.Controls.Add( myControl ) calls in the top level
page_load. These calls are executed for each table row
rendered. There are thirty table rows in all. Each of the
custom controls added, may in turn nest other custom
controls which are added using this.Controls.Add(
myControl2 ). The .Net profiler has determined that these
calls are suspect and responsible for most of the
execution time. Ultimately the custom controls are
rendering a series of web controls. Now all of the custom
controls have a page_load event which gets called when the
control is added (i.e this.Controls.Add() ). Can I send
you an attachment of a sample custom control? How would I
direct an e-mail of this type using the web-client.

Steve Gagliardo

>--Original Message--
>Hi Steve,
>Did this problem occur with a particualr custom control?
For example, when
>you add it with this.Controls.Add, it run slowly? If you
add 30 same custom
>controls, will this problem also occur?
>Luke
>Microsoft Online Support
>Get Secure! www.microsoft.com/security
>(This posting is provided "AS IS", with no warranties,
and confers no
>rights.)
>.
Hi Steve,

With web-client, it is not be able to attach such a big project. To protect
your private code, I recommend you may submit a technial support incodent
for this issue. I think we need to analyst the source code of your custom
web control to find the problem. With a support incodent, this issue may be
resoved in a timely way. For detail, you may browse to:
support.microsoft.com.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Thursday, March 22, 2012

Thread Error

I get this thread error in my custom error log. It occurs on a
Response.Redirect statement. The odd thing it does not seem to affect
the functionality of the application at all. What causes this error:

System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()
at System.Web.HttpResponse.Redirect(String url, Boolean endResponse)
at System.Web.HttpResponse.Redirect(String url)
at contact911.planpayment.ProcessOrder() in C:\Inetpub\wwwroot\dirname\payment.aspx.vb:line 344.net pages run as programs, since you redirected the user, the program stops running.
This doesn't always happen though, its actually rare (it happens on two of my pages out of about 50). Why would the page still be running when the redirect occurs?
well it's not that the others r still running, just that exception while closing them wasnt thrown, lookig at it again, it seems like the error is when the thread tries to abort, but is already aborting.. perhaps something to do wih how quickly things are executed.

there is likely nothing you can do about it though, the exception comes from within the redirect statement, not your code.

The other possibility i can think of is perhaps if you have code in the unload event of those two forms.. but the strack trace indicates that it comes from the redirect statement.. so i guess that possibility is out.
I'm not that concern that the error is thrown, I'm just worried if the functionality will be interrupted. There is a lot of code in the Submit_Click method, then a lot of code in the Page_Load method of the page it goes too - maybe thats why it doesn't finish smoothly? So far all the functionality executes properly and completely, even when the error is thrown, but I'd still like to know why its doing it.
I did alot of searching, and it seems this is normal behavior.. all the typical asp ending functions will throw an exception most of the time.. which has to be a design flaw on microsofts behalf..

the way to fix it, tells microsoft is using the overload .Redirect("url", False)
and instead of response.end (for future reference) use HttpContext.Current.ApplicationInstance.CompleteRequest

i found this info at http://support.microsoft.com/default.aspx?scid=KB;EN-US;312629