WordPress: After installing WS Polls plugin, create a polls archive page to use the polls archive option

1. Go to ‘WP-Admin -> Pages -> Add New’.
2. Type any title you like in the post’s title area.
3. If you ARE using nice permalinks, after typing the title, WordPress will generate the permalink to the page. You will see an ‘Edit’ link just beside the permalink.
4. Click ‘Edit’ and type in ‘pollsarchive’ in the text field (without the quotes) and click ‘Save’.
5. Type page_polls in the post’s content area (surrounded withbrackets []).
6. Click ‘Publish’.

Please follow and like us:

WordPress: The e-mail could not be sent. Possible reason: your host may have disabled the mail() function…

On Word Press Login Screen, you click, ‘Lost your password?’
You then type in your userid or email address associated with your user id.
You then click, ‘Get New Password’.

You should get the message, ‘Check your e-mail for the confirmation link.

But you don’t!

Instead, you get an Internal 500 Server Error (meaning you don’t have detailed error logging set in your asp hosted settings) or you get the following detailed error message:

The e-mail could not be sent.
Possible reason: your host may have disabled the mail() function…

By default WordPress uses the Mail() component to send out emails. But if your host has secure SMTP eMail authentication then Mail() will not send, and you may see the above error.

The solution for this problem is using the wp-mail-smtp plugin, which accepts a smtp host, username & password that sends out email via an SMTP host.

The plugin can be downloaded here.

Note: I found that I received an error when I tried to install the plugin via the plugin panel. It was better to simply down the plugin, unzip, and ftp the files directly to the wp-content/plugins folder. I then went into the plugins, activated the plugin, then modified the settings as you would if you were setting up your email via pop in your favorite email software.


From email: An email address that you set up via your hosting site (preferably)
From name: your name
Mailer: SMTP
SMTP Host: Your host server
SMTP Port: 25
Encryption: No Encryption
Authentification: Yes
Username: your email address
Password: your email password

Save the settings.

Finally, test it out by entering another one of your emails and see if the email is received. If so, then get out and try again.

Problem should be sovled.

Please follow and like us:

Microsoft Visual Studio 2010 – Generic IComparer

I have blogged at one time on an IComparer class that you could use to sort a property in an object within a collection http://www.jamesandchey.net/?p=601.

The downside was that the name of the object was hard-coded in the IComparer class. If I needed to sort different objects, I would have to create multiple IComparer classes. Well, that’s no good!

I was now on the hunt for one IComparer class that was generic in nature so I can sort multiple collections calling just the one IComparer class.

Here is a generic IComparer class written in visual basic. After the class, I demonstrate how to call the class.

Imports System.Collections.Generic
Imports System.Text
Imports System.Reflection

    Public Class GenericIComparer(Of T)
        Implements IComparer(Of T)

        Private m_memberName As String = String.Empty
        Private m_sortOrder As String = String.Empty
        Private m_methodParameters As New List(Of Object)()
        Private propertyInfo As PropertyInfo = Nothing
        Private methodInfo As MethodInfo = Nothing

        Public Property MemberName() As String
                Return m_memberName
            End Get
            Set(ByVal value As String)
                m_memberName = value
            End Set
        End Property

        Public Property SortOrder() As String
                Return m_sortOrder
            End Get
            Set(ByVal value As String)
                m_sortOrder = value
            End Set
        End Property

        Public ReadOnly Property MethodParameters() As List(Of Object)
                Return m_methodParameters
            End Get
        End Property

        Public Sub New()
        End Sub

        Public Sub New(ByVal memberName As String, ByVal sortOrder As String, ByVal methodParameters As List(Of Object))
            Me.m_memberName = memberName
            Me.m_sortOrder = sortOrder
            Me.m_methodParameters = methodParameters

        End Sub

        Private Sub GetReflected()
            Dim underlyingTypes As Type() = Me.[GetType]().GetGenericArguments()
            Dim thisUnderlyingtype As Type = underlyingTypes(0)

            Dim mi As MemberInfo() = thisUnderlyingtype.GetMember(m_memberName)
            If mi.Length > 0 Then
                If mi(0).MemberType = MemberTypes.[Property] Then
                    propertyInfo = thisUnderlyingtype.GetProperty(m_memberName)
                ElseIf mi(0).MemberType = MemberTypes.Method Then
                    Dim signatureTypes As Type() = New Type(-1) {}
                    If m_methodParameters IsNot Nothing AndAlso m_methodParameters.Count > 0 Then
                        signatureTypes = New Type(m_methodParameters.Count - 1) {}
                        For i As Integer = 0 To m_methodParameters.Count - 1
                            signatureTypes(i) = m_methodParameters(i).[GetType]()
                        methodInfo = thisUnderlyingtype.GetMethod(m_memberName, signatureTypes)
                        methodInfo = thisUnderlyingtype.GetMethod(m_memberName, signatureTypes)
                    End If
                    Throw New Exception("Member name: " & m_memberName & " is not a Public Property or " & "a Public Method in Type: " & thisUnderlyingtype.Name & ".")
                End If
                Throw New Exception("Member name: " & m_memberName & " not found.")
            End If
        End Sub

        Private Function GetComparable(ByVal obj As T) As IComparable
            If methodInfo IsNot Nothing Then
                Return DirectCast(methodInfo.Invoke(obj, m_methodParameters.ToArray()), IComparable)
                Return DirectCast(propertyInfo.GetValue(obj, Nothing), IComparable)
            End If

        End Function

        Public Function Compare(ByVal objOne As T, ByVal objTwo As T) As Integer Implements IComparer(Of T).Compare
            Dim iComparable1 As IComparable = GetComparable(objOne)
            Dim iComparable2 As IComparable = GetComparable(objTwo)

            If m_sortOrder IsNot Nothing AndAlso m_sortOrder.ToUpper().Equals("ASC") Then
                Return iComparable1.CompareTo(iComparable2)
                Return iComparable2.CompareTo(iComparable1)
            End If
        End Function

    End Class

Here is how to call the class:

'Sort the Collection by entered_date
Dim _IComparer As New GenericIComparer(Of _MyObject)
_IComparer.MemberName = "entered_date"
_IComparer.SortOrder = "asc"

1) I instantiate the GenericIComparer class.
2) I set the MemberName property to the object property (_MyObject) I want to sort on.
3) I set the SorOrder property to the direction I want to sort.
4) I then call the Sort method.

Note: _MyCollection happens to be defined as a List of (_MyObject). In other words, _MyCollection contains a collection of _MyObject’s. Each object has a property called ‘entered_date’. I simply want to sort the collection and put the objects in order (whether ascending or descending) by ‘entered_date’.

Please follow and like us:

ASP.net – Sorting a gridview where datasource is bound to a list of collection of a class object

Sorting by column on a gridview when the datasource is bound to a list of collection of a class object presented quite a challenge. Since I did not use the wizard of the gridview to assign my datasource via the control and instead created and assigned the datasource programmatically, I had to progammatically get my sorting to work also.

1) The first thing I needed was set the AllowSorting property of the gridview = true.

2) In the gridview task, I then clicked on ‘Edit Columns’. Inside the Fields dialog, for my bound columns that I wanted to sort, I set the SortExpression property to the same name I used for my DataField property. After closing the dialog, the visual representation of the column names in the design view of the grid now showed them blue and underlined.

When I viewed the page in the browser, I was able to click the column header, but instead of witnessing a sort, I instead received an error that told me I had to handle the sort in my code. After trial and error and much research, I will now present the steps to implement in your server-side code behind to handle the sorting.

3) After assigning the collection to the DataSource property of the gridview, you need to save the DataSource to the ViewState:

ViewState("DataSource") = GridView1.DataSource

4) To handle the column click, you need to add the Sorting handle for the gridview along with a SortDirection function that keeps track of what column you clicked last and the direction it was last sorted in. Here are the two methods in their entirety:

Protected Sub GridView1_Sorting(sender As Object, e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting

            '  GridView1.DataSource = Session("DataSource")
            GridView1.DataSource = ViewState("DataSource")

            Dim dt As New DataTable()
            Dim createColumns As Boolean = True
            For Each eachobj In GridView1.DataSource
                Dim t As Type = eachobj.[GetType]()
                Dim propInfos As PropertyInfo() = t.GetProperties()
                If createColumns Then
                    For Each eachProp As PropertyInfo In propInfos
                        dt.Columns.Add(eachProp.Name, GetType(Object))
                    createColumns = False
                End If
                Dim data As Object() = New Object(propInfos.Length - 1) {}
                For i As Integer = 0 To propInfos.Length - 1
                    Dim propInfo As PropertyInfo = propInfos(i)
                    data(i) = propInfo.GetValue(eachobj, Nothing)

            Dim dataView1 As New Data.DataView(dt)

            dataView1.Sort = e.SortExpression & " " & GetSortDirection(e.SortExpression)

            GridView1.DataSource = dataView1

        Catch ex As Exception
        End Try
    End Sub

    Private Function GetSortDirection(ByVal column As String) As String

        ' By default, set the sort direction to ascending.
        Dim sortDirection = "ASC"

        ' Retrieve the last column that was sorted.
        Dim sortExpression = TryCast(ViewState("SortExpression"), String)

        If sortExpression IsNot Nothing Then
            ' Check if the same column is being sorted.
            ' Otherwise, the default value can be returned.
            If sortExpression = column Then
                Dim lastDirection = TryCast(ViewState("SortDirection"), String)
                If lastDirection IsNot Nothing _
                  AndAlso lastDirection = "ASC" Then

                    sortDirection = "DESC"

                End If
            End If
        End If

        ' Save new values in ViewState.
        ViewState("SortDirection") = sortDirection
        ViewState("SortExpression") = column

        Return sortDirection
    End Function

Explanation of the above methods

1) The DataSource saved previously to the ViewState is now read back in and assigned back to the gridview’s DataSource property.

2) The next chunk of logic converts the DataSource that contains my collection to a DataTable and then to a DataView.

3) The Sort property of the DataView is then assigned the SortExpression of the column and the direction of the sort determined by the GetSortDirection function.

4) The last step is to assign the DataSource property of the gridview with the DataView along with a DataBind.

You now have sorting capability.

Please follow and like us:

ASP.Net – How to control client-side functionality based on triggered event (i.e. What button was clicked)

Let’s say you have a scenario that whenever a button event or any event for the matter is raised on the client-side you want to display text in a label on the screen that says something like, “PROCESSING… PLEASE WAIT.” At the end of processing, you then would clear out the text to that label at the end of the server-side event routine.

To do this on the client-side, you add a handler for the OnClientClick event, let’s say for a SEARCH button like this:

<asp:Button ID="btnSearch" runat="server" Text="Search" Width="81px"  
    OnClientClick="SetProcessLabelFromClient" TabIndex="14" 

At the top of your aspx, you then add the javascript like this:

function SetProcessLabelFromClient
  document.getElementById('<%= txtProcessing.ClientID %>').value = 'PROCESSING.... PLEASE WAIT.';

This works fine and all, but what if you have a SAVE button and you are using validation controls? The problem? Your label says, “PROCESSING… PLEASE WAIT.” and won’t go away because your…let’s say… telephone textbox error validation says “INVALID FORMAT”. The page never got submitted to the server in order to clear the label.

The solution? Pass the button control ID to the javascript like this:

<asp:Button ID="btnDSave" runat="server" Text="Save" Width="81px"  
    OnClientClick="SetProcessLabelFromClient(this.id)" TabIndex="30" 
    ValidationGroup="DetailGroup" UseSubmitBehavior="False" />

The difference is your are now passing the script a parameter called, “this.id”

Last but not least, modify your javascipt to except the parameter and interrogate whether you are dealing with the SAVE button. If the SAVE button, then execute the Page_ClientValidate method. If the page is valid, set the label. If not valid, then don’t set it. If the button is not SAVE, then set the label.

The modified script looks like this:

function SetProcessLabelFromClient(tid)
    if (tid == "btnDSave")
         if (Page_IsValid)
             document.getElementById('<%= txtProcessing.ClientID %>').value = 'PROCESSING.... PLEASE WAIT.';
    } else 
        document.getElementById('<%= txtProcessing.ClientID %>').value = 'PROCESSING.... PLEASE WAIT.';
Please follow and like us:

Adobe Flash CS5.5 and AS3 – How to pass a variable from one flash application to another

Let’s say that I initially passed a parameter called ‘Testee’ to my preloader flash application via the HTML param tag. Now I need to pass this same parameter value from the preloader to the main flash application. Here is the code that receives the parameter from the the HTML:

var paramUserName:String;
var flashVars:Object = LoaderInfo(this.root.loaderInfo).parameters;
paramUserName = flashVars.Testee;

From flashVars, I get the Testee parameter and assign it to a variable called paramUserName.

In the preloader, after the loader has finished loading the main flash application, the event.complete calls my ‘done’ function:

_URLLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, done);

In my ‘done’ function, after I add the _URLLoader, I call the dispatch event:

function done(e:Event):void
removeChild (_bar_guts);
percent = null;
_bar_border = null;
_bar_guts = null;

e.target.content.dispatchEvent (new Event("change"));

In my main flash application, I add a listener for the dispatched event called as shown above, ‘change’:

addEventListener(Event.CHANGE, SetUserName);

I then receive the value of my passed parameter in my SetUserName function:

function SetUserName(event:Event)
var mTestee:String = event.target.parent.parent.paramUserName;

Again, the ‘paramUserName’ is the variable in my preloader flash application that was assigned the ‘Testee’ parameter from the HTML that called the preloader flash application.

Please follow and like us:

ASP.Net – How to pass a variable from one aspx page to another aspx page

Let’s say I derive a value from a RadioButtonList control and I want to pass it to another ASPX page that I am going to redirect to.

1) I first build a string and wire together that ASPX page I am going to redirect to (via some event click).

Dim mQueryString As String = "~Page2.aspx?SomeVariable=" & RadioButtonList1.SelectedValue

I am going to redirect my current ASPX page to Page2.aspx. To pass the value to Page2.aspx, I give it a name (in this example, SomeVariable, and append it after Page.aspx connected with a ‘?’. I then add the value result of my RadioButtonList1 control that the user selected prior to hitting let’s say a button.

The end result looks something like this:


The variable name is SomeVariable and the value of the variable is Florida.

Now you can proceed to redirect to Page2.aspx as follows:


Now, on the receiving end of Page2.aspx, this is how you retrieve the SomeVariable value of Florida.

Dim myState as String = Request.QueryString("SomeVariable")

Using the Request.QueryString, the method scans the URL, finds the parameter variable SomeVariable, and extracts the value of ‘Florida’ to a variable I have created called myState

myState now = ‘Florida’

Please follow and like us:

ASP.Net – How to pass the user.identity.name from your ASP.Net application as a parameter via the client side of your aspx page to a flash program

Say you want to restrict access to your flash application that is called by your aspx page. That is easy enough by adding the aspx page to your your web.config file’s location/authorization section. But what if you want to pass the user that is logged on to your ASP.Net application via the authentication process?

Here is how to pass a parameter called UserName to your flash application using the param name tag in your html of your aspx page.

<param name="FlashVars" value="UserName=&lt;% Response.Write(UCASE(User.Identity.Name)) %>" />

User.Identity.Name contains the user logged into your ASP.Net application. Response.Write is the method to use to place the user into the value property of your parameter.

You can then use the following logic in your flash application to read in the UserName parameter:

var paramUserName:String;
var flashVars:Object = LoaderInfo(this.root.loaderInfo).parameters;
paramUserName = flashVars.UserName;
Please follow and like us:

ASP.Net – Missing URL parameter: IterationId’ Error

You get the following error when calling a reporting services report from your ASP.Net web application that passes a parameter on Non-IE browsers using the 2010 ReportViewer control:

Missing URL parameter: IterationId
at Microsoft.Reporting.WebForms.HandlerOperation.GetAndEnsureParam(NameValueCollection urlQuery, String paramName) at Microsoft.Reporting.WebForms.ReportImageOperation.PerformOperation(NameValueCollection urlQuery, HttpResponse response) at Microsoft.Reporting.WebForms.HttpHandler.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Sometimes this error will occur when you use the line control on a report. The Line control tries to include a standard blank image right after it, but the URL is missing that parameter in FireFox and Chrome. Try removing the line control from your report to see if the error disappears.

This error does not happen with IE Browsers. Just ignore.

Please follow and like us: