Archive | October 2008

IE innerHTML – "Unknown runtime error"

Setting value of <div id=”divhtml”> using js like this :

document.getElementById(“divhtml”).innerHTML = “<form><input type=”text”>…</form>”;

it was giving me error..

Solution:

oldDiv = document.getElementById(divhtml);
newDiv = document.createElement(oldDiv.tagName);
newDiv.id = oldDiv.id;
newDiv.className = oldDiv.className;
newDiv.innerHTML = “<form><input type=”text”>…</form>”;

oldDiv.parentNode.replaceChild(newDiv, oldDiv);

And it worked like a charm!!!!!!

Link : http://piecesofrakesh.blogspot.com/2007/02/ies-unknown-runtime-error-when-using.html

There was an error while trying to serialize parameter http://tempuri.org/:obj. The InnerException message was ‘Type ‘System.Collections.Generic.List`1[Employee, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]‘ with data contract name ‘ArrayOfEmployee:http://schemas.datacontract.org/2004/07/Interfaces’ is not expected. Add any types not known statically to the list of known types – for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

Hi if you are getting your hands dirty with WCF and got your mind blown up with the error as shown above or shown in Screen i have medicine of it..so go ahead!!!!

image

I am creating one simple serviceoperation which should take argument as an object but i will pass instance of my generic list which can be like List<Employee> or List<Person> and all this….because in service implementation i will do further operation based on type….I have created one application like this:

IService.cs

image

Service.CS

image

Employee.CS

image

Client.CS

image

Now when i run this application it gives me error of KnownTypeAttribute and serialization

Cause:

Actually root cause of problem is that we have defined object as our datacontract but when we pass List<Employee> or List<Person> it dosen’t knows what to serialize and send from wire…..hoohh…….simple if i have told you to say HI and it i will sat Bye…you can’t understand what i mean to say…so i need to help you in understanding Bye…Simple!!!!!so let us tell CLR that hey what to do if i pass List<Employee> or any type which i want to pass..

Solution:

Open your service contract IService.cs

and after [ServiceContract] Add [ServiceKnownType(typeof(List<Employee>))] or [ServiceKnownType(typeof(List<Person>))]….and Run the application…modified IService.cs looks like this:

image

Hope it helped you…Wants to say..Thanks say it to

Sowmy Srinivasan’s for nice and in-depth article:http://blogs.msdn.com/sowmy/

Question:

I am just wondering suppose if i have 50 Types which i want to pass then i need to declare all this on top of IService….just searching some alternative for it..if i found will let you know and hoping for the same….

Adding application relative path in head section of master Page for JavaScript

Problem:

I have my application structure similar to as shown below:

image

My JavaScript file has one function which I want to use on each and every page which used my master page. That JS function looks like:


</font>
<font size="2">function HelloWorld()
{
&nbsp;&nbsp;&nbsp; alert("Helloo.....World...");
}</font>
<font size="2">

And to register a JS file i have registered it on one place which is in MASTER..rather than registering it on each and every page. so my master head looks like this:


</font>
<font size="2">
<head runat="server">&nbsp;&nbsp;&nbsp; </font> 

<font size="2"><script language="javascript" type="text/javascript" src="Javascript/HelloWorld.js">
</script>
</head></font>
<font size="2">


on FormWithMasterPage.aspx. i was calling that function as shown below:


</font>
<font size="2"><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
<input type="button" value="OK" onclick="HelloWorld();" />
</asp:Content></font>
<font size="2">


And it was working as expected..means showing alert message:

image

but when i tried the same within SubPageDefault.aspx which is under my SubFolder folder it was throwing an error:

image

Which says that it was unable to find JS function HelloWorld();

In short..How to Add application relative Javascript reference?????

Because for SubPageDefault.aspx function it was trying to find "Javascript/HelloWorld.js" under /SubFolder/javascript/..

Solution:

To solve this problem you need to change bit in your master page head section:

1. Open master page and locate its <HEAD> Section and if it has runat="server" remove it. [In some case if you are using Themes then it is compulsory to put it..no problem put another head tag with no runat="server".]

2. Hook the code as shown below under <HEAD> for registering JS:


</font>

<font size="2">
<head>&nbsp;&nbsp;&nbsp;
</font><font size="2">
<font color="#0000ff">&nbsp;&nbsp;&nbsp;
<%--To use line as shown below remove runat="server" And if it is required to put runat="server" put one more head with runat="server"--%>
&nbsp;&nbsp;&nbsp;
<script language="javascript" type="text/javascript" src='<%=ResolveClientUrl("~/Javascript/HelloWorld.js")%>'></script></font>
&nbsp;&nbsp;&nbsp; </font>
<font size="2"><font color="#ff0000"><%--Line below will not work--%>
&nbsp;&nbsp;&nbsp;
 <%--<script language="javascript" type="text/javascript" src="Javascript/HelloWorld.js"></script>--%>
</font></head></font>
<font size="2">


That's it...Happy mastering!!

Source code: http://sites.google.com/site/klpatils/Home/RelativeJSURL.rar?attredirects=0

Links:

http://www.dotnetgenerics.com/Modules/TricksAndTips/ASP.NET/PowerOfTilda.aspx

http://www.odetocode.com/Articles/419.aspx

http://www.odetocode.com/articles/450.aspx - ATOZ of Master Page

Web.config registration missing! The Telerik dialogs require a HttpHandler registration in the web.config file.

Problem:

Was getting this error with IIS7 and Telerik Dialog control. Which says that “Web.config registration missing! The Telerik dialogs require a HttpHandler registration in the web.config file.”

Solution:

Telerik guys says “When a web site is running under IIS7 Integrated mode, the web server searches the HttpHandler registrations under the <system.webServer> configuration section instead of the standard <system.web> configuration section of the application configuration file.”.

All you need to do to manually register the HttpHandler for the IIS7 Integrated mode is copy the Telerik HttpHandler to the <handlers> section of the <system.webServer> section group, delete the validate attribute and give it a name, e.g.

<system.webServer>
<handlers>
 …
<add name="Telerik.Web.UI.DialogHandler" path="Telerik.Web.UI.DialogHandler.aspx" verb="*" type="Telerik.Web.UI.DialogHandler, Telerik.Web.UI" />
 …
</handlers>
</system.webServer>

Thanks to : http://www.telerik.com/support/kb/article/b454K-hek-b454T-mb-b454c-mb.aspx

Log4Net – Quickstart guide

Q.What it is?

Ans. It is a logging framework for Microsoft .NET. The initial work was done by NeoWorks and was donated to Apache Software foundation in February 2004.

It is a tool which will help programmers to output a log to a variety of output targets. [Text file, eventLog, database etc.]

Provides Nested Diagnostic Context (NDC) and Mapped Diagnostic Context (MDC).

Log4 net is designed with two main goals: speed and flexibility.

Features

  • Supports for multiple frameworks
  • Output to Multiple Logging Targets
  • Hierarchical logging architecture
  • XML Configuration
  • Dynamic Configuration
  • Logging Context
  • Proven Architecture

Q. Developing Application using Log4NET.

In this demo Application we will see how we can write a log to the text file. This has been configured in Web.config

1) Create a new console Application

clip_image002

2) Add Reference to Log4net.dll [I guess you have downloaded the Log4NET project. If not then please download from here: http://logging.apache.org/log4net/download.html. And you will get bin\net\2.0\ log4net.dll this is the guy whose reference we are going to add]…and ya don’t forget to include using statement using log4net; and using log4net.config;

3) Add Configuration file

clip_image004

4) Now add the following stuff in your configuration file.

 
<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
<!--Configure your configuration Section Handler which is Log4NetConfigurationSectionHandler--> 
<configSections> 
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/> 
</configSections> 
<log4net> 
<!--Only one root logger element may only be defined and it must be a child of <log4net> 
element. The root logger is the root of the logger hierarchy. All loggers ultimately inherit from this logger.--> 
<root> 
<!--Root Element has no attributes--> 
<level value="DEBUG" /> 
<!--Optional element, maximum of one allowed. Defines the logging level for this logger.  
This logger will only accept event that are at this level or above.--> 
<appender-ref ref="LogFileAppender" /> 
<!--Zero or more elements allowed. Allows the logger to reference appenders by name.--> 
</root> 
<!--Appenders may only be defined as child elements of the <log4net> 
element. Each appender must be uniquely named. The implementing type for the appender must be specified.--> 
<!--name = Required attribute. Value must be a string name for this appender.  
The name must be unique among all the appenders defined in this configuration file. This name is used by the <appender-ref> 
element of a Logger to reference an appender.--> 
<!--type = Required attribute. Value must be the type name for this appender.  
If the appender is not defined in the log4net assembly this type name must be fully assembly qualified.--> 
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" > 
<!--RollingFileAppender extends FileAppender to backup the log files when they reach a certain size.--> 
<param name="File" value="C:\log.txt" /> 
<param name="AppendToFile" value="true" /> 
<rollingStyle value="Size" /> 
<maxSizeRollBackups value="10" /> 
<maximumFileSize value="10MB" /> 
<staticLogFileName value="true" /> 
<!-- layout = Optional element, maximum of one allowed. Defines the layout used by this appender.--> 
<layout type="log4net.Layout.PatternLayout"> 
<param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} - %m%n" /> 
<!--%p - will show the level of message 
%d - will show the date 
%l - will show the class, method and line number where error occurred and  
%m - will show message to display 
See more pattern from Here http://www.beefycode.com/post/Log4Net-Tutorial-pt-4-Layouts-and-Patterns.aspx 
--> 
</layout> 
</appender> 
</log4net> 
</configuration> 

This configuration says that I want to write a log in C:\log.txt file. And it should be appended…Will explore more on each bit and write it down..but for this point of time I don’t think it is required.

5) Now we are ready with configuration part so let’s log something.

Open your program.cs file and declare this variable


/*CREATE A LOGGER - you can create different Logger for each Package/namsepace

* No need to create Logger for each Class.

*/

public static readonly ILog logger = LogManager.GetLogger(typeof(Program));

Now under Main let’s use this logger to log


XmlConfigurator.Configure();

//Write down Error/Debug/Fatal/Information Message

logger.Debug("..This is Debug Message...");

logger.Error("..This is Error Message...");

logger.Fatal("..This is Fatal Message...");

logger.Info("..This is Information Message...");

So, finally your main looks like this:

clip_image006

6) Run the application. Close the console which get opened. And locate c:\log.txt file. Which we have configured on step 4.

7) If you can see the following output then its good time to think about starting using it within your project.

clip_image008

Webliography

http://en.wikipedia.org/wiki/Apache_Log4net

Wiki

http://logging.apache.org/log4net/release/features.html

Features

http://logging.apache.org/log4net/download.html

log4net 1.2.10

http://www.codeproject.com/KB/trace/log4net_intro.aspx

Log4J

http://safari.oreilly.com/0321228103/part01#X2ludGVybmFsX1RvYz94bWxpZD0wMzIxMjI4MTAzL2NoMDhsZXYxc2VjMTQ=

http://weblogs.asp.net/lorenh/archive/2005/02/18/376191.aspx

MS Logging Block And Log4net

http://logging.apache.org/log4net/release/manual/configuration.html

Configuration information

http://www.codeproject.com/KB/trace/Logger_using_log4net.aspx

Quickstart

http://www.beefycode.com/post/Log4Net-Tutorial-pt-4-Layouts-and-Patterns.aspx

http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html

Patterns

http://www.beefycode.com/category/log4net.aspx

Nice resource with all information

using Object Initializers with Sub object

I have Two Entities like as shown below:

Address.cs

image

Employee.cs

image

Now i want to use Powerful feature of C# 3.0 object initializers. I am using it since few days but with simple types not with complex type like Employee.Address.. but its good to know that c#3.0 also supports this…Thanks to “Anders hejlsberg” for such a nice programming language…anyway lets look how we can do this..here’s the way..

image

and output is:

image

My intention of showing output is that the code works :) just kidding… Enjoy the new and powerful features of C#3.0…

Fetching value from XML parameter in SP-SQL SERVER 2005

XML Document as a parameter

[sourcecode language='xml']

DECLARE @xmlParam as XML

SET @xmlParam =

‘<Root>

<List>

<ID>1</ID>

<Cost>10.00</Cost>

<Active>true</Active>

</List>

<List>

<ID>2</ID>

<Cost>10.00</Cost>

<Active>true</Active>

</List>

<List>

<ID>3</ID>

<Cost>10.00</Cost>

<Active>true</Active>

</List>

<List>

<ID>13</ID>

<Cost>10.00</Cost>

<Active>true</Active>

</List>

<List>

<ID>14</ID>

<Cost>10.00</Cost>

<Active>true</Active>

</List>

<List>

<ID>15</ID>

<Cost>10.00</Cost>

<Active>true</Active>

</List>

<List>

<ID>16</ID>

<Cost>10.00</Cost>

<Active>true</Active>

</List>

<List>

<ID>17</ID>

<Cost>10.00</Cost>

<Active>true</Active>

</List>

</Root>’

[/sourcecode]

SQL Syntax for retrieving values:

SELECT

–get the ID

ParamValues.Data.value(‘ID[1]‘,’bigint’) as ID,

–get the Cost

ParamValues.Data.value(‘Cost[1]‘,’decimal(10,2)’) as Cost,

ParamValues.Data.value(‘Active[1]‘,’bit’) as Active –Active

FROM

–get the data from entityfields using Xquery

@xmlParam.nodes(‘Root/List’) as ParamValues(Data)

Output

clip_image002

Updated on 10-Oct-2008

At a time of Update…How to fetch values??

DECLARE @employeesData as XML

SET @employeesData =
‘<Employees>
<Employee>
<EmployeeID>1</EmployeeID>
<EmployeeName>ABC</EmployeeName>
</Employee>
<Employee>
<EmployeeID>2</EmployeeID>
<EmployeeName>XYZ</EmployeeName>
</Employee>
</Employees>’

UPDATE Employees
SET [EmployeeName] = ParamValues.Data.value(‘EmployeeName[1]‘,’varchar(50)’)
FROM @employeesData .nodes(‘/Employees/Employee’) as ParamValues(Data)
WHERE EmployeeID IN (ParamValues.Data.value(‘EmployeeID[1]‘,’bigint’))

Hope it helps some one…..runing out of time..

Follow

Get every new post delivered to your Inbox.

Join 328 other followers