Tech Boek

12
OVERVIEW
 
I get the calendar script “semi” hardcoded, because I have no control to give to the DotNetNuke version of the calendar popup function.  This could be solved giving a hidden unused dummy control, where you can replace the clientid
 
USAGE 
 

  t = create_new_textbox(fieldname, tmpDate, "inputshort", "150px", bReadOnly, True, get_calender_popup_template(System.Threading.Thread.CurrentThread.CurrentCulture.ToString, fieldname))

 
FUNCTIONS
 

  ''' <summary>
        ''' Create a new dynamic textbox control
        ''' </summary>
        ''' <param name="id">the id of the control</param>
        ''' <param name="value">the value of the control</param>
        ''' <param name="cssclass">the cssclass for the control</param>
        ''' <param name="width">optional width</param>
        ''' <param name="bReadonly">optional readonly flag, default is famse</param>
        ''' <param name="bSetReadOnlyColor">if true then the correct cssclass is set (readonly has grayed textbox)</param>
        ''' <param name="onclick">optional extra onclick attribute</param>
        ''' <returns>the dynamic textbox</returns>
        ''' <remarks></remarks>
        Public Shared Function create_new_textbox(ByVal id As String, ByVal value As String, Optional ByVal cssclass As String = "", Optional ByVal width As String = "", Optional ByVal bReadonly As Boolean = False, Optional ByVal bSetReadOnlyColor As Boolean = False, Optional ByVal onclick As String = "") As TextBox
            Try
                Dim t As New TextBox
                t.ID = id
                t.Text = value
                If Not cssclass.Equals("") Then t.CssClass = cssclass
                If Not width.Equals("") Then t.Style("Width") = width
                t.ReadOnly = bReadonly
                If bSetReadOnlyColor Then set_color_for_textbox_input(t)
                If Not onclick.Equals("") And Not bReadonly Then t.Attributes.Add("onclick", onclick)
                Return t
            Catch ex As Exception
                Throw New Exception(ex.Message)
            End Try
        End Function

 
 

Public Shared Function get_calender_popup_template(ByVal culture As String, ByVal clientid As String) As String
            Try
                Dim jv As String = ""
                Select Case culture
                    Case "es-ES"
                        jv = "javascript:popupCal('Cal',get_correct_clientid('[clientid]'),'dd/MM/yyyy','enero,febrero,marzo,abril,mayo,junio,julio,agosto,septiembre,octubre,noviembre,diciembre','dom,lun,mar,mié,jue,vie,sáb','HOY','CERRAR','CALENDARIO',0);"
                    Case "pt-PT"
                        jv = "javascript:popupCal('Cal',get_correct_clientid('[clientid]'),'dd-MM-yyyy','Janeiro,Fevereiro,Março,Abril,Maio,Junho,Julho,Agosto,Setembro,Outubro,Novembro,Dezembro','dom,seg,ter,qua,qui,sex,sáb','Hoje','Fechar','Calendário',1);"
                    Case Else 'default to en-US
                        jv = "javascript:popupCal('Cal',get_correct_clientid('[clientid]'),'M/d/yyyy','January,February,March,April,May,June,July,August,September,October,November,December','Sun,Mon,Tue,Wed,Thu,Fri,Sat','Today','Close','Calendar',1);"
                End Select
 
                Return jv.Replace("[clientid]", clientid)
            Catch ex As Exception
                Throw New Exception(ex.Message)
            End Try
        End Function
 

 
The [clientid] tag is replaced with the .NET id of the control
 
JAVASCRIPT
 

//search the correct client id for dynamic fields, the correct id is not yet known because it was not yet rendered
function get_correct_clientid(dotnetid) {
    //get all input boxes
    var boxes = document.getElementsByTagName("INPUT");
    //loop through them
    for(var i = 0; i < boxes.length; i++) {
        if(boxes[i].type == 'text' && boxes[i].id.endsWith(dotnetid) ) {
            return boxes[i].id;
        }
    }
}

 
This is because the client ID is not yet known at the moment you create the control, but you know for sure that it always ends with the serverid of the control
 
SUMMARY
 
Basicely what happens is that I construct the popup script for the calendar that gets its control id from a javascript, with the serverid as parameter.  As soon someone clicks the textbox, the javascript is called and at that time the control was rendered en exists and can be used in the dnn popup.
 
 
If you want more info on this, please feel free to ask !!
Posted in: DotNetNuke

Post Rating

Comments

proform treadmill
donderdag 3 november 2011 17:23
Great information, thanks for the share!

Post Comment

Naam (verplicht)

E-mail (verplicht)

Website

CAPTCHA Afbeelding
Enter the code shown above: