Thursday, March 11, 2010

Ajax enabled WCF Service stops working with Undefined error

I got a javascript underfine error when I use the wcf service call. I found out that it will work after I remove or comment the extendedProtectionPolicy from the web configuration.


 

Tuesday, March 09, 2010

Use AspNet_Merge to Version Website Assemblies

If you want to add versioning information to the assemblies generated for a precompiled Web site, you can do the following:

  • Add an AssemblyInfo.cs or AssemblyInfo.vb file to the App_Code folder. The assembly generated for the App_Code folder will then be versioned. You can also add version attributes to the code-behind files for pages and user controls. However, adding version attributes to individual files is tedious and applies only to code-behind files in an updatable precompilation layout.
  • Add references to an AssemblyInfo.cs or AssemblyInfo.vb file to the compilerOptions attribute of the <compiler> element in the Web.config file. This enables you to add versioning for all assemblies generated for the Web site. In that case, you must include both C# and Visual Basic compilers because ASP.NET might select a compiler for non-code type files, such as WSDL, when compiling the proxies.

Aspnet_merge.exe can version the assemblies it creates by either copying the attributes from the App_Code assembly or copying them from a specific assembly specified using the –copyattrs option. This is therefore treated like any other assembly attribute. These options for specifying an attribute for the merged assembly or assemblies ensures that you can define all version attributes, including the file version, the assembly version, and any other assembly attributes you require.

Figure 25 shows the merge command used to apply attributes from the App_Code assembly, using the Web site shown in Figure 1. The AssemblyInfo.cs file shown in Figure 22 has been added to the Web site's App_Code folder.

Example

Aspnet_merge c:\precompileWebsite –copyattrs –a

Monday, March 08, 2010

IE Modal Dialog and ASP.NET PostBack solution


 

Put the following HTML code inside of your page header in HTML source,

1

<head>

2

    <title>My Page</title>


 

3

    <base
target="_self"></base>

4

</head>

The modal dialog will be able to successfully postback to itself

Thursday, March 04, 2010

Multiple Onclick JavaScript Events on a Single Control

You can't add two identical events to the same Html control. For example, if you have a button with an onclick event, and you add another onclick at the server, the second event will overwrite the first. This becomes a problem if you need to add an event to some variable control, but you don't know what events that control already has. However, .Net provides a way to handle this.

We can:

  1. See if the variable html control already has an onclick event.
  2. If it does, then dynamically register a new script that calls both the original onclick script as well as the new script.
  3. Replace the variable control's onclick value with that new script.

The following code snippets this. This first block shows a simple JavaScript (with a parameter) being called by a button's onclick event.

function DoStuff1(var1) {
    alert('1: ' + var1);
}

...

<INPUT id="Button1" onclick="DoStuff1('Hello1')" type="button" value="Button" name="Button1" runat="server">

...

This snippet shows the server code to check if an onclick event already exists, and add a new wrapper if needed. Note that it persists the onclick values in viewstate to ensure that the wrapper function doesn't wrap itself upon postback. For example, if the first onclick event called DoStuff1(), and we wanted to dynamically add a new onclick function DoStuff2(), we could create a wrapper function Wrapper1() that called both functions, and was called from the onclick. Wrapper1() becomes the new value of the button's onclick.

private void Page_Load(object sender, System.EventArgs e)
{
    string s = this.Button1.Attributes["onclick"];
    if (!Page.IsPostBack)
        OriginalJSFunction = s;
    if (s == null)
        this.Button1.Attributes.Add("onclick","DoStuff2()");
    else
    {
        if (!Page.IsClientScriptBlockRegistered("JS1"))
            Page.RegisterClientScriptBlock("JS1",GetJS(OriginalJSFunction));
        this.Button1.Attributes.Add("onclick","Wrapper1()");
    }
}

private string OriginalJSFunction
{
    get
    {
        object o = ViewState["OriginalJSFunction"];
        if (o == null)
            return "";
        else
            return o.ToString();
    }
    set
    {
        ViewState["OriginalJSFunction"] = value;
    }
}

private string GetJS(string strOriginalFn) //will handle initial JS with params
{
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.Append(@"
        <script language='javascript'>
        function Wrapper1() {
        " + strOriginalFn + @";
        DoStuff2();
        }
        </script>
    ");

    return sb.ToString();
}

 While this approach is tedious, it lets you dynamically add an event to a control without overwriting that control's existing event. This is useful when making your own custom controls that integrate with existing Html controls already on the page.

http://timstall.dotnetdevelopersjournal.com/multiple_onclick_javascript_events_on_a_single_control.htm

Tuesday, March 02, 2010

Multiple select values in Cognos Report with store procedure


 

  1. Import the stored procedure in Framework Manager and set the parameters to:

    1st parameter = #prompt('param1')#

    2nd parameter = #prompt('param2')#

     
     

  2. Create a report in Report Studio with a report page calling the SP and a prompt page containing the multiple select value prompt

 
 

  1. Add a text box prompt object to the prompt page

 
 

  1. Set the following ID's for the objects on the prompt page:

    Multiple select value prompt ID = Preprocessing_ID1

    Textbox prompt ID = Postprocessing_ID1

     
     

  2. Add an HTML item with the following javascript to the report:

 
 

<script>

// IBM Cognos 8.3 specific

 
 

function assignParamValue()

{

// get the reference to the Cognos form

var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() :

document.forms["formWarpRequest"]);

 
 

var i, tmp;

tmp = "";

 
 

// get the handle for the 1st checkbox prompt - add div around them to distinguish

 
 

var prompt1 = document.getElementById('checkboxPrompt1');

 
 

// find all the children of the div of type checkboxes.

for (i=0; i < prompt1.childNodes.length; i++)

{

var node_list = prompt1.getElementsByTagName('input');

for (var i = 0; i < node_list.length; i++)

{

var node = node_list[i];

if (node.getAttribute('type') == 'checkbox')

{

if (node.checked)

{

if( tmp == "" )

{

tmp = node.value;

}

else

{

tmp = tmp + "," + node.value;

}

}

}

}

}

fW._textEditBoxPostprocessing_ID.value = tmp;

 
 

canSubmitPrompt();

promptButtonFinish();

}

</script>

  1. Add an HTML item before the checkbox with the contents of

    <div id="checkboxPrompt1">

    and add an HTML item right after the checkbox prompt with the contents of

    </div>

     
     

  2. Add a virtual "finish" button to call the javascript function before proceeding to the report itself by adding another HTML item and inserting the following code:

 
 

<input type="BUTTON" class="clsPromptButton" onClick="assignParamValue()"

value="Finish">

Code Signing for Developers - An Authenticode How-To

If you are a software developer then you probably already know that Microsoft Windows and web browsers such as Internet Explorer and Mozilla Firefox use a technology called Authenticode to verify the publisher of downloads and check that they have not been infected by a virus since they were created. If your software is not signed with a digital certificate, users will receive a warning that the publisher could not be verified and asked whether they want to continue running it. Many users will decide to play safe and click "Don't run", costing you lost sales.

http://www.tech-pro.net/code-signing-for-developers.html

How to Create Versioned Assemblies in the Visual Studio 2005 and Visual Studio 2008 Website

To create an assembly-information file for your website

  1. Using a text editor, create a new assembly-information file. For Visual Basic applications, the suggested file name is AssemblyInfo.vb. For C# applications, the suggested file name is AssemblyInfo.cs.

[assembly:System.Reflection.AssemblyVersionAttribute("versionNumber")]

Do not place the assembly-information file in the App_Code directory. If you place the assembly-information file in the App_Code directory, it will be compiled automatically by the ASP.NET runtime and might cause compilation errors later in the compilation process.

To specify the assembly-information file in your .aspx page

  1. Open your .aspx file in a text editor.
  2. Add the following attribute to the @ Page directive in the .aspx page.

CompilerOptions="path\AssemblyInfo.cs"

Replace the path parameter with the physical path to the assembly-information file on disk.

If the path to your assembly-information file contains spaces, you must enclose the path and file name in single quotation marks (').

CompilerOptions='"path with spaces\AssemblyInfo.cs"'

Replace the path with spaces parameter with the physical path to the assembly-information file on disk.

  1. Publish the website.

To specify the assembly-information file in your Web.config file

  1. Open your Web.config file in a text editor.
  2. Add the following code to your Web.config file.

"c#;cs;csharp" extension=".cs"

type="Microsoft.CSharp.CSharpCodeProvider, System,

Version=2.0.3600.0, Culture=neutral,

PublicKeyToken=b77a5c561934e089" warningLevel="1"

compilerOptions="path\AssemblyInfo.cs" />

  1. Publish the website

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