Converting existing ASP.NET Application to DotNetNuke -what is the best approach?

I’ve posted on ASP.NET forums the following:


I have an existing ASP.NET 1.1 Application that includes more than hundred different ASPX pages and user controls (ASCX). The application consists of a number search forms, results lists and data details forms to view and edit database data.


I am considering converting the application to DotNetNuke.


 


I am looking for information what is the best approach for converting.


Should I make all my User Controls be derived from Modules.PortalModuleBase or I can use Dynamic Load User Controls Module ?


Should I locate all my DNN User Control in one folder under DNNDesktopModules or it’s better to create a few separate Modules.


Is it allowed to have User Controls in sub-folders of MyModule folder or it is recommended to have all of them in the root of the module.


 


 


Any info how to simplify the process and references how similar conversions were done would be appreciated.  


 

Advertisements

Remove NewLine characters from the data in SQL Server

UPDATE: Xavid  at 8/2/2007  in a comment suggested a simpler code:

REPLACE(REPLACE(REPLACE(MyField, CHAR(10), ”), CHAR(13), ”), CHAR(9), ”)

 


I found that some string in the database have NewLine characters where they do not required.

To remove them in T-SQL I wrote the following SQL script (TODO: write  re-usable SP, also special option to remove NewLine characters from the end of the string)

declare @NewLine char(2)
set @NewLine=char(13)+char(10)
update TableName
     set ColumnName =Replace(ColumnName , @NewLine,”)
WHERE ColumnName like ‘%’ +@NewLine +’%’

Note that even if WHERE condition may  look redundant,  it is important for performance. Without the (ColumnName like ‘%’ +@NewLine +’%’)condition all records will be updated,even if actual column value would not be changed.

To identify rows with newLine at the end the following condition can be used.

where ( RIGHT(ColumnName ,2)=@NewLine

See ASCII Characters for values of different characters .

Differences between Visual Basic Trim function and String.Trim() method

Today I recognized that Visual Basic Trim function removes spaces only, but String.Trim() method removes all white space characters(see Remarks here) including newline and carriage return.


The following C# sample confirms this:


      public void VBTrim_Test()


      {


            string str=”string” + ‘r’ + ‘n’;


            Debug.WriteLine(String.Format(“length of {0} is {1}”, str,Microsoft.VisualBasic.Strings.Len(str)));


            str=Microsoft.VisualBasic.Strings.Trim(str);


            Debug.WriteLine(String.Format(“After VB trim length of {0} is {1}”, str,Microsoft.VisualBasic.Strings.Len(str)));


            str=str.Trim();


            Debug.WriteLine(String.Format(“After String trim length of {0} is {1}”, str,Microsoft.VisualBasic.Strings.Len(str)));


      }                                  


The output is following:


length of string


 is 8


After VB trim length of string


 is 8


After String trim length of string is 6


 

ASP.NET custom control HyperLinkWithImage

I’ve posted source code for the custom control that shows hyperlink and image next to each other that when clicked, will open the same URL.


The standard WebControls.HyperLink  shows text or image, but not both.


 

ASP.NET custom control HyperLinkWithImage

I wanted to have hyperlink next to image  that when clicked, will open the same URL.

The standard WebControls.HyperLink  shows text or image, but not both.

So I decided to create custom control.

Image can be at the left or at the right of the HyperLink that can be specified by ImageAlign property.

See  a source code for the custom control below:

using System;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.ComponentModel;

using System.Web.UI.Design; //!!!System.Design (in System.Design.dll)

using System.Drawing.Design;

using System.Collections.Specialized;//NameValueCollection Class 

using System.Diagnostics;

 

namespace FSWeb.CustomControls

{

//TODO should I use ViewState and also different names for Text and ImageUrl

      ///

      /// HyperLinkWithImage –hyperlink next to image that when clicked, will open the same URL.

      ///

      [DefaultProperty(“Text”),

            ToolboxData(“<{0}:HyperLinkWithImage runat=server>”)]

      public class HyperLinkWithImage : System.Web.UI.WebControls.HyperLink 

      { //,IPostBackDataHandler

            private string m_ImageUrl;

            private ImageAlign m_ImageAlign;

            //private string m_text;use ViewState instead

            public HyperLinkWithImage() : base()

            {

            }

 

            [Bindable(true),

                  Category(“Appearance”),

                  DefaultValue(“”),

            EditorAttribute(typeof(System.Web.UI.Design.ImageUrlEditor), typeof(UITypeEditor))]

            public  new string ImageUrl  //Shadows base hyperlink ImageUrl that will be null

            {

                  get

                  {

                        return m_ImageUrl;

                  }

 

                  set

                  { 

                        m_ImageUrl = value;

                  }

            }

            //WebCategory(“Layout”)-internal in System.Web

            //WebSysDescription(“Image_ImageAlign”)-internal in System.Web

            [ Bindable(true), Category(“Layout”), DefaultValue(0)]

            public virtual ImageAlign ImageAlign

            {

                  get

                  {

                        object obj1 = m_ImageAlign ;//this.ViewState[“ImageAlign”];

                        if (obj1 != null)

                        {

                              return ((ImageAlign) obj1);

                        }

                        return ImageAlign.NotSet;

                  }

                  set

                  {

                        if ((value < ImageAlign.NotSet) || (value > ImageAlign.TextTop))

                        {

                              throw new ArgumentOutOfRangeException(“value”);

                        }

                        m_ImageAlign= value;// this.ViewState[“ImageAlign”] = value;

                  }

            }

            [Bindable(true),

            Category(“Appearance”),

            DefaultValue(“”)

            ]

            public  new string Text  //Shadows base hyperlink Text that will be null

            {

                  get

                  {

                        object obj1 = this.ViewState[“TextValue”];

                        if (obj1 != null)

                        {

                              return (string) obj1;

                        }

                        return string.Empty;

                  }

                  set

                  { 

                        this.ViewState[“TextValue”] = value;

                  }

            }

 

            ///

            /// Overrides the OnPreRender method.

            ///

            protected override void OnPreRender(System.EventArgs e)

            {

                  base.OnPreRender(e);

            }

 

            ///

            /// Render this control to the output parameter specified.

            ///

            /// The HTML writer to write out to

            protected override void Render(HtmlTextWriter output)

            {

                  string sUrl, sImg=null;

                  if (!DataHelper.IsNullOrEmpty(m_ImageUrl))

                  {    

                        sUrl=this.ResolveUrl(m_ImageUrl);//to resolve ‘~’ can’t be called in construction time

                        sImg=”<IMG alt=”” src=”” + sUrl + “” border=”0″ >”;

                  }

                  bool bImageAlignNotSet=(ImageAlign.NotSet == m_ImageAlign);

                  bool bImageRight=(ImageAlign.Right== m_ImageAlign);

                  if ( bImageAlignNotSet) //

                  {//Standard HyperLink

                        base.Text= this.Text;

                        base.ImageUrl= this.ImageUrl;

                  }

                  else if (null!=sImg)

                  {

                        if(!bImageRight)

                        {    

                              base.Text= sImg+this.Text;

                        }

                        else

                        {

                              base.Text= this.Text+sImg;

                        }

                  }

                  base.Render(output);

            }

 

      }

}

  Update: The control refers to DataHelper class, posted here

Calling __doPostBack in javascript

Update: There is an existing .Net Framework method Page.GetPostBackEventReference that emits client-side script that initiates postback and also provides a reference to the control that initiated the postback event. It is well described in MSDN article Generating Client-Side Script for Postback“. So my function should call and  in most cases GetPostBackEventReference can be used directly.

Original Post:

I’ve used a function to submit postback from my javascript by passing Id of the link server control as it was suggested in article “How postback works in ASP.NET” 

   //call the postback function with the right ID
 __doPostBack(‘ControlId’,”);
and it worked fine for a while.

However when I moved the link to the User control, it stopped to work.

I recognized that I need to provide fully qualified Control.ClientId but it didn’t work.
In debugger I found that when calling the __doPostBack(), ASP.NET generates ID with dollar – $ -separator, not underscore that is used in ClientID, e.g. ‘userContol1$linkContol1’.

I found confirmation to this in ASP.NET Server Control – Design Time Support  and .NET Development: PressButton Design and Server Control . Microsoft provides  UniqueIDWithDollars  internal method, that can be accessed through reflection.

However I found that it is simpler just to duplicate code in static function.

The working version of javascript function to __doPostBack :

            public static bool RegisterFunctionToPostBack(string sFunctionName,Control ctrl)

            { //from http://www.xefteri.com/articles/show.cfm?id=18 How postback works in ASP.NET

                  if (HttpContext.Current.Request.Browser.JavaScript)

                  {

 

                        string sJS =”    function ” + sFunctionName + @”()

                        {

                            //call the postback function with the right ID

                             __doPostBack(‘” + UniqueIDWithDollars(ctrl) + @”‘,”);

                        }”;

                        sJS=JScriptHelper.JScript(sJS);

                        ctrl.Page.RegisterStartupScript(sFunctionName, sJS);

                        return true;

                  }

                  return false;

            }

            //from http://www.codeproject.com/aspnet/DesignTimeSupport.asp

            public static string UniqueIDWithDollars(Control ctrl)

            {

                        string sId = ctrl.UniqueID;

                        if (sId == null)

                        {

                              return null;

                        }

                        if (sId.IndexOf(‘:’) >= 0)

                        {

                              return sId.Replace(‘:’, ‘$’);         

                        }

                        return sId;

            }

If I would start the function from the scratch, I probably would consider ScriptCallback/AJAX approach.

ctrl.Page.GetPostBackEventReference(ctrl)  instead of 
__doPostBack(‘” + UniqueIDWithDollars(ctrl) + @”‘,”);