Welcome Guest Search | Active Topics | Sign In | Register

VB example of custom LayoutTemplate Options
swabygw
Posted: Tuesday, August 11, 2009 11:23:30 PM
Rank: Member
Groups: Member

Joined: 8/11/2009
Posts: 14
Hi, thanks for such a flexible tool (I'm trying out the AJAX uploader). I have been trying to start customization of the LayoutTemplate by converting the C# code I found in another post to VB. I'd like to customize it so that I can rearrange the textbox, buttons, and checkbox layout. I'd also like to change the font of the filename next to the checkbox. Needless to say...many problems. I apologize in advance for being such a neophyte at programming ".aspx" pages, but can you post a VB (not HTML or C) example of how to do it? Here's what I have so far:


Public Class AjaxFileUpload_LayoutTemplate
'Implements ITemplate
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control)
Dim inputPlaceHolder = New PlaceHolder

Dim progressBar = New ProgressBar()
progressBar.ID = "ProgressBar"
progressBar.ControlSkinID = "Windows_XP"

Dim hr = New HtmlGenericControl("hr")

Dim cancelButton = New ImageButton()
cancelButton.ID = "CancelButton"
cancelButton.ImageUrl = "~/Images/Detener.png"
cancelButton.MarginLeft = New Unit(10, UnitType.Pixel)
cancelButton.MarginTop = New Unit(5, UnitType.Pixel)
cancelButton.ToolTip = "Cancelar"

Dim deleteButton = New ImageButton()
deleteButton.ID = "DeleteButton"
deleteButton.ImageUrl = "~/Images/Anular.png"
deleteButton.MarginLeft = New Unit(10, UnitType.Pixel)
deleteButton.MarginTop = New Unit(5, UnitType.Pixel)
deleteButton.ToolTip = "Borrar ficheros seleccionados"
deleteButton.FirstColumn = False
deleteButton.LastColumn = True

Dim hr2 = New HtmlGenericControl("hr")

Dim postedFilesPlaceHolder = New PlaceHolder


container.Controls.Add(inputPlaceHolder)
container.Controls.Add(progressBar)
container.Controls.Add(hr)
container.Controls.Add(hr2)
container.Controls.Add(cancelButton)
container.Controls.Add(hr2)
container.Controls.Add(deleteButton)
container.Controls.Add(hr2)
container.Controls.Add(hr2)

' <LayoutTemplate>
' <asp:PlaceHolder ID="InputPlaceHolder" runat="server" />
' <eo:ProgressBar ID="ProgressBar" runat="server" ControlSkinID="Windows_XP" />
' <asp:PlaceHolder ID="ProgressTextPlaceHolder" runat="server" />
' <%//<RealeUI:Button ID="CancelButton" runat="server" Text="Cancelar" LastColumn="true" />
' //<RealeUI:Button ID="DeleteButton" runat="server" Text="Borrar ficheros seleccionados" /> %>
' <hr />
' <RealeUI:ImageButton ID="CancelButton" runat="server" ImageUrl="~/Images/Detener.png" MarginLeft="10px" MarginTop="5px" ToolTip="Cancelar" />
' <RealeUI:ImageButton ID="DeleteButton" runat="server" ImageUrl="~/Images/Anular.png" FirstColumn="false" MarginLeft="10px" MarginTop="5px" ToolTip="Borrar ficheros seleccionados" LastColumn="true" />
' <hr />
' <asp:PlaceHolder ID="PostedFilesPlaceHolder" runat="server" />
'</LayoutTemplate>


container.Controls.Add(postedFilesPlaceHolder)
End Sub
End Class

Protected Overloads Overrides Sub CreateChildControls()

Dim template As New AjaxFileUpload_LayoutTemplate()
'Me.LayoutTemplate = template

MyBase.CreateChildControls()

End Sub

Public withevents AJAXUploader1 as new AJAXUploader

Sub mySub
AJAXUploader1.LayoutTemplate = template
End Sub
eo_support
Posted: Wednesday, August 12, 2009 7:54:30 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

Your code looks fine to me. Try to move the code inside your CreateChildControls into OnInit. That way the controls all the controls will be created earlier.

If you continue to have problem, please let us know exactly what problem you are having and we will be happy to look into it.

Thanks!
swabygw
Posted: Wednesday, August 12, 2009 8:28:06 AM
Rank: Member
Groups: Member

Joined: 8/11/2009
Posts: 14
Thanks, in advance...
The server error: "Unable to cast object of type 'AjaxFileUpload_LayoutTemplate' to type 'System.Web.UI.ITemplate'."

Here's my updated code: (notice "Me.LayoutTemplate = template" and "Implements ITemplate" are commented out. Is that okay?)

Public Class AjaxFileUpload_LayoutTemplate
'Implements ITemplate
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control)
Dim inputPlaceHolder = New PlaceHolder

Dim progressBar = New ProgressBar()
progressBar.ID = "ProgressBar"
progressBar.ControlSkinID = "Windows_XP"

Dim hr = New HtmlGenericControl("hr")

Dim cancelButton = New Button()
cancelButton.ID = "CancelButton"
cancelButton.MarginLeft = New Unit(10, UnitType.Pixel)
cancelButton.MarginTop = New Unit(5, UnitType.Pixel)
cancelButton.ToolTip = "Cancelar"

Dim deleteButton = New Button()
deleteButton.ID = "DeleteButton"
deleteButton.MarginLeft = New Unit(10, UnitType.Pixel)
deleteButton.MarginTop = New Unit(5, UnitType.Pixel)
deleteButton.ToolTip = "Borrar ficheros seleccionados"
deleteButton.FirstColumn = False
deleteButton.LastColumn = True

Dim hr2 = New HtmlGenericControl("hr")

Dim postedFilesPlaceHolder = New PlaceHolder

container.Controls.Add(inputPlaceHolder)
container.Controls.Add(progressBar)
container.Controls.Add(hr)
container.Controls.Add(hr2)
container.Controls.Add(cancelButton)
container.Controls.Add(hr2)
container.Controls.Add(deleteButton)
container.Controls.Add(hr2)
container.Controls.Add(hr2)
container.Controls.Add(postedFilesPlaceHolder)
End Sub
End Class

Public template

'Protected Overloads Overrides Sub CreateChildControls()
Protected Overrides Sub OnInit(ByVal e As EventArgs)

template = New AjaxFileUpload_LayoutTemplate()
'Me.LayoutTemplate = template

MyBase.CreateChildControls()

End Sub

Sub mySub
AJAXUploader1.id = "AJAXUploader1"
' AJAXUploader1.AutoPostBack = True
AJAXUploader1.Width = Unit.Parse("250px")
AJAXUploader1.TempFileLocation = formStagedFilespath
'AJAXUploader1.FinalFileLocation = formStagedFilespath
AJAXUploader1.PostedFileLabelFormat = "{posted_file_name} - ({posted_file_size} bytes)"
AJAXUploader1.MaxDataSize = "0"
AJAXUploader1.MaxFileCount = 1
AJAXUploader1.LayoutTemplate = template
VideoTableRowCell(39).Controls.Add(AJAXUploader1)
End Sub
eo_support
Posted: Wednesday, August 12, 2009 8:35:56 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
No. You can not comment out "Implements ITemplate". I believe that is exactly what caused the error for you.

Thanks
swabygw
Posted: Wednesday, August 12, 2009 8:25:05 PM
Rank: Member
Groups: Member

Joined: 8/11/2009
Posts: 14
SOLVED! Thanks for your help. I've encountered two other issues, but will post with a new subject. For those interested, here's the resolution (and interesting sample code of how to use ITemplate):

Public AJAXTemplate
Public WithEvents AJAXUploader1 as New AJAXUploader

Public Shared templateTableRow(99) As TableRow
Public Shared templateTableRowCell(99) As TableCell

Protected Overrides Sub OnInit(ByVal e As EventArgs)

AJAXTemplate = New AjaxFileUpload_LayoutTemplate()

End Sub

Public Class AjaxFileUpload_LayoutTemplate

Implements System.Web.UI.ITemplate

Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) _
Implements System.Web.UI.ITemplate.InstantiateIn

Dim InputPlaceHolder = New PlaceHolder
Dim ProgressTextPlaceHolder = New PlaceHolder
Dim PostedFilesPlaceHolder = New PlaceHolder

InputPlaceHolder.ID = "InputPlaceHolder"
ProgressTextPlaceHolder.ID = "ProgressTextPlaceHolder"
PostedFilesPlaceHolder.ID = "PostedFilesPlaceHolder"

Dim UploadButton = New Button
Dim CancelButton = New Button
Dim DeleteButton = New Button

UploadButton.ID = "UploadButton"
CancelButton.ID = "CancelButton"
DeleteButton.ID = "DeleteButton"
UploadButton.Text = "Upload"
CancelButton.Text = "Cancel"
DeleteButton.Text = "Delete"

Dim progressBar = New ProgressBar
progressBar.ID = "ProgressBar"
progressBar.ControlSkinID = "Windows_XP"

Dim templateTable As New Table

templateTable.Width = Unit.Parse("100%")
templateTable.Height = Unit.Parse("100%")
templateTable.ID = "templateTable"
'templateTable.Gridlines = Gridlines.Both
'templateTable.BorderWidth = 1
'templateTable.BorderColor = System.Drawing.Color.Gray

For x As Integer = 0 to UBound(templateTableRow)
templateTableRow(x) = New TableRow
Next x
For x As Integer = 0 to UBound(templateTableRowCell)
templateTableRowCell(x) = New TableCell
templateTableRowCell(x).HorizontalAlign = HorizontalAlign.Left
templateTableRowCell(x).VerticalAlign = VerticalAlign.Middle
templateTableRowCell(x).Font.Size = FontUnit.Parse("10")
templateTableRowCell(x).Font.Name = "Arial"
'templateTableRowCell(x).BorderColor = System.Drawing.Color.Gray
'templateTableRowCell(x).BorderWidth = 1
Next x
templateTableRowCell(0).Width = Unit.Parse("10%")
templateTableRowCell(1).ColumnSpan = 3
templateTableRowCell(2).ColumnSpan = 2
templateTableRowCell(3).Width = Unit.Parse("10%")
templateTableRowCell(4).Width = Unit.Parse("10%")
templateTableRowCell(5).ColumnSpan = 4

templateTableRow(0).Cells.Add(templateTableRowCell(0))
templateTableRow(0).Cells.Add(templateTableRowCell(1))
templateTableRow(1).Cells.Add(templateTableRowCell(2))
templateTableRow(1).Cells.Add(templateTableRowCell(3))
templateTableRow(1).Cells.Add(templateTableRowCell(4))
templateTableRow(2).Cells.Add(templateTableRowCell(5))

templateTable.Rows.Add(templateTableRow(0))
templateTable.Rows.Add(templateTableRow(1))
templateTable.Rows.Add(templateTableRow(2))

container.Controls.Add(templateTable)

templateTableRowCell(0).Controls.Add(DeleteButton)
templateTableRowCell(1).Controls.Add(PostedFilesPlaceHolder)

templateTableRowCell(2).Controls.Add(inputPlaceHolder)
templateTableRowCell(3).Controls.Add(UploadButton)
templateTableRowCell(4).Controls.Add(CancelButton)

templateTableRowCell(5).Controls.Add(progressBar)

End Sub

End Class

Sub someSub
AJAXUploader1.ID = "AJAXUploader1"
AJAXUploader1.LayoutTemplate = AJAXTemplate
End Sub
eo_support
Posted: Wednesday, August 12, 2009 8:32:54 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Great. Glad that you got it working. Thanks for sharing!
swabygw
Posted: Wednesday, August 12, 2009 9:22:13 PM
Rank: Member
Groups: Member

Joined: 8/11/2009
Posts: 14
I encountered something interesting: the Cancel button doesn't actually do anything. I see the button, but it is not enabled before the upload, during the upload, or after the upload. Shouldn't it become available at some point? Or, do I have use javascript to make it actually do something (if this is so, can you point me to a sample script that will cancel the upload)?
eo_support
Posted: Wednesday, August 12, 2009 9:39:40 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

AJAXUploader never hides Cancel button. So it is mostly that you have a problem in your template code. Try to:

1. Remove AJAXUploader from the page;
2. Add a new Panel control into the form, say "Panel1";
3. Call AJAXTemplate.InstantiateIn(Panel1). This will create all the child controls in Panel1;

Now you have a page without uploader but is running your custom template. If you see Cancel button now, then please post the complete test page and we will take a look. If you do not see Cancel button then the problem is in your InstantiateIn function.

Thanks!
swabygw
Posted: Wednesday, August 12, 2009 9:58:07 PM
Rank: Member
Groups: Member

Joined: 8/11/2009
Posts: 14
This is "kind-of" solved. Here's what happened:

1) Uploaded 20 mb file. It uploaded so quickly the Cancel button flashed on so briefly, barely noticed it become enabled for a split second.

2) Uploaded a 250 mb file. This looks like it hangs up my machine and times out after about 2 minutes. While it's trying to Request/Respond, the Cancel button is still unenabled because no upload is happening (the progress bar is not showing activity).

I figured I needed to find a medium-size file to catch it in action. So, I...

3) Uploaded a 35 mb file. I finally caught it and, yes, it works correctly.

Now, if I could figure out how to get the uploader to accept a 250 mb file... I know this was in one of the earlier posts. Something about a setting in IIS or web.config. Can you point me in the right direction (or post a link), plz? Thanks!
eo_support
Posted: Wednesday, August 12, 2009 10:07:35 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

You can find solutions to most common problems here:

http://doc.essentialobjects.com/library/1/ajaxuploader/troubleshoot.aspx

Your problem does not appear to be related to IIS 7. It's more likely that you have another module before the uploader that's trying the fetch data. While it is doing that you will see the uploader sitting there without moving the progress bar.

Thanks



You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.