building a form in a custom module

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
12/12/2010 11:24:15 AM
Gravatar
Total Posts 50

building a form in a custom module

Hi again, i have this form with a codebehind file that allows a user to do a date-range pick (using ajaxControlToolKit), lists files in a directory and has a button with linked to a zip-and-download function using the DotNetZip Library.

pasting the form into the usercontrol DownloadForm.ascx file didn't work for me and is now not showing anything on the page(im not seeing an error ? ) im assuming this isn't the way to go about this.

i would prefer that the form is in the DownloadForm.ascx and not linked from DownloadForm.ascx to a .aspx file using the <portal:ModuleTitleControl> link.

How would you do this ?

Thanks

this is the form code:

           <asp:UpdatePanel ID="updatePnl" runat="server">
             <Triggers>
                <asp:AsyncPostBackTrigger controlid="Reload" eventname="Click" />
            </Triggers>
            <ContentTemplate>
            <table >
              <tr>
                <td valign="top">
                 <div id="dates" runat="server" visible="True">
                      <fieldset>
                      <legend>Dates</legend>

                            <div>
                              <div class="demoarea">
                                <div class="demoheading">Choose different Dates</div>
                                <br />

                                <b>Start Date: </b><br />

                                <asp:TextBox runat="server" ID="Date1" text="" OnTextChanged="date_TextChanged" AutoPostBack="true" />
                                <ajaxToolkit:CalendarExtender ID="defaultCalendarExtender" runat="server" TargetControlID="Date1" Format="dd/MM/yyyy" />
                                <asp:Image runat="Server" ID="Image2" ImageUrl="Calendar_scheduleHS.png" />
                                <div style="font-size: 90%"><em>(Set the focus to the textbox to show the calendar)</em></div>

                                <b>End Date: </b><br />
                                <asp:TextBox runat="server" ID="Date2" text="" OnTextChanged="date_TextChanged" AutoPostBack="true" />
                                <ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="Date2" Format="dd/MM/yyyy" />
                                <asp:Image runat="Server" ID="Image1" ImageUrl="Calendar_scheduleHS.png" />
 

                             </div>
                           </div>
                        </fieldset>
                 </div>
                </td>


                <td valign="top" >

                             <div id="Files" runat="server" visible="True">
                             <fieldset>
                                  <legend>Files</legend>
                                <div class="demoheading">Download Files</div>
                                <asp:CheckBoxList id="chklst" runat="server" /><br />
<script type="text/javascript">
    function fnCheckAll() {
        var i = 0;
        var item;
        while (true) {
            item = document.getElementById("ctl00_mainContent_chklst_" + i);
            if (item == null)
                break;
            item.checked = true;
            i++;
        }
    }
    function fnClearAll() {
        var i = 0;
        var item;
        while (true) {
            item = document.getElementById("ctl00_mainContent_chklst_" + i);
            if (item == null)
                break;
            item.checked = false;
            i++;
        }
    }
</script>
<asp:button id="chkButton" runat="server" Height="23px" Width="72px" Text="Select All" ></asp:button>
<asp:button id="clrButton" runat="server" Height="23px" Width="72px" Text="Clear" ></asp:button>
                                        <asp:button id="Reload" runat="server" Height="23px" Width="72px" Text="List Files" OnClick="Reload_Click" AutoPostBack="true"></asp:button>
 

                                    <asp:Label Font-Bold=true ID="Label1" runat="server" Text="">
                                    </asp:Label>
                                    <br />
                             </fieldset>
                            </div>

                </td>
              </tr>
            </table>


                <div id="Progress" runat="server" visible="False">
                      <img src="ajax-loader.gif" alt="loader" />
Loading...
</div>
<asp:UpdateProgress ID="UpdateProgress2" runat="server"
AssociatedUpdatePanelID="updatePnl"
DisplayAfter="100" DynamicLayout="true">

<ProgressTemplate >
<img border="0" src="ajax-loader.gif" alt="progress" />
<asp:Label id="ReloadLbl" runat="server" Text="Performing task..."></asp:Label>
</ProgressTemplate>

</asp:UpdateProgress>
<asp:label id="lbProgress" runat="server" Height="30px" Width="100px" ></asp:label>

<P>
<asp:label id="ErrorLbl" runat="server" Height="30px" Width="695px" ForeColor="Red"></asp:label>
<asp:literal id="ResultLit" runat="server"></asp:literal>
<asp:label id="debug1" runat="server" Height="30px" Width="695px" ForeColor="Blue"></asp:label>

</P>
</ContentTemplate>
</asp:UpdatePanel> 

12/16/2010 10:34:59 AM
Gravatar
Total Posts 50

Re: building a form in a custom module

Hi, can anyone help ?

thanks

12/16/2010 10:38:39 AM
Gravatar
Total Posts 2253

Re: building a form in a custom module

If a module doesn't work for some reason, you will not see errors on the page, they will be written to the system log which you can find in the Administration menu.

I suggest clearing the log, opening the page with the module and the refreshing the log so you only see errors related to your module.

HTH,
Joe D.

12/16/2010 10:56:58 AM
Gravatar
Total Posts 50

Re: building a form in a custom module

thanks Joe

12/21/2010 5:14:13 PM
Gravatar
Total Posts 50

Re: building a form in a custom module

Hi,

I've really hit a wall here, any help would be really appreciated:

i can't seem to retain a dynamic check box list when clicking a button in the UserControl form. i have tried all the possible ' if (!IsPostBack) ' methods, but every time i click the download button or i change the date (using ajaxToolkit:CalendarExtender)  the page reloads and i lose the dynamic check box list .it could be related to the Ajax but im not sure.

this is my DownloadForm.ascx:

<%@ Control Language="C#" AutoEventWireup="false" CodeBehind="DownloadForm.ascx.cs" Inherits="phytech.Web.UI.DownloadFormModule" %>

<portal:mojoPanel ID="mp1" runat="server" ArtisteerCssClass="art-Post" RenderArtisteerBlockContentDivs="true" >
<mp:CornerRounderTop id="ctop1" runat="server" />
<asp:Panel ID="pnlWrapper" runat="server" cssclass="art-Post-inner panelwrapper DownloadFormModule">
<portal:ModuleTitleControl EditText="Edit" runat="server" id="TitleControl" />
<portal:mojoPanel ID="MojoPanel1" runat="server" ArtisteerCssClass="art-PostContent">
<asp:Panel ID="pnlDownloadFormModule" runat="server" CssClass="modulecontent">

<fieldset>

<center>
<table >
<tr>
<td valign="top">
<div id="dates" runat="server" visible="True">
<fieldset>
<legend>Dates</legend>
<div>
<div class="area">
<div class="heading">Choose different Dates</div>
<br />

<b>Start Date: </b><br />

<asp:TextBox runat="server" ID="Date1" text="" AutoPostBack="true" />
<ajaxToolkit:CalendarExtender ID="defaultCalendarExtender" runat="server" TargetControlID="Date1" Format="dd/MM/yyyy" />
<asp:Image runat="Server" ID="Image2" ImageUrl="~/App_DesignTimeStyle/Calendar_scheduleHS.png" />
<div style="font-size: 90%"><em>(Set the focus to the textbox to show the calendar)</em></div>

<b>End Date: </b><br />
<asp:TextBox runat="server" ID="Date2" text="" AutoPostBack="true" />
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="Date2" Format="dd/MM/yyyy" />
<asp:Image runat="Server" ID="Image1" ImageUrl="~/App_DesignTimeStyle/Calendar_scheduleHS.png" />

</div>
</div>
</fieldset>
</div>
</td>


<td valign="top" >

<div id="Files" runat="server" visible="True">
<fieldset>
<legend>Files</legend>
<div class="demoheading">Download Files</div>
<asp:CheckBoxList id="chklst" runat="server" /><br />


<script type="text/javascript">
function fnCheckAll() {
var i = 0;
var item;
while (true) {
item = document.getElementById("ctl00_mainContent_chklst_" + i);
if (item == null)
break;
item.checked = true;
i++;
}
}
function fnClearAll() {
var i = 0;
var item;
while (true) {
item = document.getElementById("ctl00_mainContent_chklst_" + i);
if (item == null)
break;
item.checked = false;
i++;
}
}
</script>
<asp:button id="chkButton" runat="server" Height="23px" Width="72px" Text="Select All" ></asp:button>
<asp:button id="clrButton" runat="server" Height="23px" Width="72px" Text="Clear" ></asp:button>
<asp:button id="Reload" runat="server" Height="23px" Width="72px" Text="List Files" OnClick="Reload_Click" AutoPostBack="true"></asp:button>

<asp:Button ID="DownloadButton" runat="server" AutoPostBack="true" />

</fieldset>
</div>

</td>
</tr>
</table>

<P>
<asp:label id="ErrorLbl" runat="server" Height="30px" Width="695px" ForeColor="Red"></asp:label>

</P>

</center>
</fieldset>
</asp:Panel>

</portal:mojoPanel>
<div class="cleared"></div>
</asp:Panel>
<mp:CornerRounderBottom id="cbottom1" runat="server" />
</portal:mojoPanel> 

And this is the codebehind :

 


using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Globalization;
using System.Net;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using mojoPortal.Web;
using mojoPortal.Web.Framework;
using mojoPortal.Web.UI;
using log4net;
//using phytech.Web.Business;
using phytech.Business;
using Resources;
using AjaxControlToolkit;
//using phytech.Web.UI.App_GlobalResources;
using Ionic.Zip;

 

namespace phytech.Web.UI
{

    public partial class DownloadFormModule : SiteModuleControl
    {
       
        private DownloadFormRepository repository = new DownloadFormRepository();

        #region OnInit

        protected override void OnInit(EventArgs e)
        {

            base.OnInit(e);
            this.Load += new EventHandler(Page_Load);
            DownloadButton.Click += new EventHandler(DownloadButton_Click);

        }

 

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {

                LoadSettings();
                PopulateLabels();
                PopulateControls();
 

            chkButton.Attributes.Add("onclick", "return fnCheckAll();");
            clrButton.Attributes.Add("onclick", "return fnClearAll();");

            Response.Cache.SetCacheability(HttpCacheability.NoCache);

            FillDates(); 


        }

 

        private void PopulateControls()
        {
           // TitleControl.EditUrl = SiteRoot + "/DownloadForm/DownloadForm.aspx";
            TitleControl.Visible = !this.RenderInWebPartMode;
            if (this.ModuleConfiguration != null)
            {
                this.Title = this.ModuleConfiguration.ModuleTitle;
                this.Description = this.ModuleConfiguration.FeatureName;
            }

        }


        private void PopulateLabels()
        {
            TitleControl.EditText = "Edit";
            DownloadButton.Text = DownloadFormResources.DownloadButton;
        }

        private void LoadSettings()
        {
            if (!IsPostBack) { ShowFileList(); }
        }


        protected void Reload_Click(object sender, System.EventArgs e)
        {
            ShowFileList();
        }


        protected void date_TextChanged(object sender, EventArgs e)
        {
            try
            {
                        Session["Date1"] = Date1.Text;
                        Session["Date2"] = Date2.Text;
                        ShowFileList();
                   }
 



            }
            catch (Exception ex)
            {
                ErrorLbl.Text = ErrorLbl.Text + "date_TextChanged: " + ex.Message;
                return;
            }

        }


         private void ShowFileList()
         {


                 System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("he-IL");
                 try
                 {
                     if (!Directory.Exists(@"files\\" + Context.User.Identity.Name))

                         Directory.CreateDirectory(@"files\\" + Context.User.Identity.Name);
                 }
                 catch (Exception ex)
                 {
                     ErrorLbl.Text =  ex.Message ;
                 }

                 try
                 {

                     string dateString = null;

                     string file = null;
                     string User = Context.User.Identity.Name;

                     System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(Server.MapPath("files\\" + Context.User.Identity.Name + "\\"));
                     System.IO.FileInfo[] diar1 = di.GetFiles();
                     System.IO.FileInfo dra = null;

                     // chklst.Items.Clear();

                    //loop through files, compare names to dates, show files with names in range.
                     foreach (System.IO.FileInfo dra_loopVariable in diar1)
                     {
                         dra = dra_loopVariable;
                         file = dra.ToString();

                         dateString = file.Remove(file.Length - 4, 4);
                         dateString = dateString.Substring(dateString.Length - 10);
                         dateString = dateString.Replace("_", "/");


                         DateTime convertedDate = System.DateTime.ParseExact(dateString, "dd/MM/yyyy", System.Threading.Thread.CurrentThread.CurrentCulture);
                         DateTime CDate1 = System.DateTime.ParseExact((string)Session["Date1"], "dd/MM/yyyy", System.Threading.Thread.CurrentThread.CurrentCulture);
                         DateTime CDate2 = System.DateTime.ParseExact((string)Session["Date2"], "dd/MM/yyyy", System.Threading.Thread.CurrentThread.CurrentCulture);  

                         if (CDate1 <= convertedDate && convertedDate <= CDate2)
                         {

                             chklst.Items.Add(file);
                        
                         }
                     
                     }

                 }
                 catch (Exception ex)
                 {
                     ErrorLbl.Text =  ex.Message;
                 }

                 System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

         }

         public void FillDates()
         {
             System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("he-IL");
             try
             {
                 if (Date2.Text == string.Empty)
                 {

                     Session["Date2"] = DateTime.Now.ToString("dd/MM/yyyy");
                     Session["Date1"] = DateTime.Now.AddDays(-10).ToString();
                     Date2.Text = DateTime.Now.ToString("dd/MM/yyyy");
                 }

                 if (Date1.Text == string.Empty)
                 {
                     string TodaysDate = DateTime.Now.ToString("dd/MM/yyyy");
                     Session["Date1"] = DateTime.Now.AddDays(-10).ToString("dd/MM/yyyy");
                     Date1.Text = DateTime.Now.AddDays(-10).ToString("dd/MM/yyyy");
                 }

             }
             catch (Exception ex)
             {
                 ErrorLbl.Text = ErrorLbl.Text + "FillDates" + ex.Message;
             }

             System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
             return;
         }


         void DownloadButton_Click(object sender, EventArgs e)
         {
             Download1_Click1();
          
         }


         private void Download1_Click1()
         {

             try
             {
                 System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("he-IL");
                 bool emptyCheckboxList = false;
                 Int32 ItemsNum = chklst.Items.Count;
                 FileStream MyFileStream = default(FileStream);
                 long FileSize = 0;
                 StreamWriter fp = default(StreamWriter);
                 log4net.ILog log = default(log4net.ILog);

                 string exeFileName = Context.User.Identity.Name + "_" + DateTime.Now.ToString("ddMMyyyy") + "_" + DateTime.Now.ToString("HHmmss") + ".exe";
                 string zipFileName = Context.User.Identity.Name + "_" + DateTime.Now.ToString("ddMMyyyy") + "_" + DateTime.Now.ToString("HHmmss") + ".zip";
                 Response.Clear();

                 using (ZipFile zip = new ZipFile())
                 {

                     foreach (ListItem lstItem in chklst.Items)
                     {

                         ErrorLbl.Text = ErrorLbl.Text + "in checklist: " + lstItem.Text + "<br />";

                         if (lstItem.Selected == true)
                         {
                             emptyCheckboxList = true;
                             ErrorLbl.Text = ErrorLbl.Text + "downloaded: " + lstItem.Text + "<br />";
                             zip.AddFile(Server.MapPath("files\\" + Context.User.Identity.Name + "\\") + lstItem.Text, Context.User.Identity.Name + "_" + DateTime.Now.ToString("ddMMyyyy") + "_" + DateTime.Now.ToString("HHmmss"));

                         }
                     }

                     zip.Save(Server.MapPath("files\\temp\\") + zipFileName);
                 }


                 MyFileStream = new FileStream(Server.MapPath("files\\temp\\") + zipFileName, FileMode.Open);
                 FileSize = MyFileStream.Length;

                 byte[] Buffer = new byte[Convert.ToInt32(FileSize) + 1];
                 MyFileStream.Read(Buffer, 0, Convert.ToInt32(FileSize));
                 MyFileStream.Close();

 

              using (FileStream fs = new FileStream(Server.MapPath("files\\temp\\") + zipFileName, FileMode.OpenOrCreate, FileAccess.Read))
                 {
                     byte[] Buffer2 = new byte[2049];
                     Int32 n = default(Int32);
                     do
                     {
                         n = fs.Read(Buffer2, 0, 2048);
                         Response.OutputStream.Write(Buffer2, 0, n);
                     } while (n > 0);
                 }
                 Response.Flush();
                 Response.Close();

                 if (emptyCheckboxList == false)
                 {
                     ErrorLbl.Text = ErrorLbl.Text + "No File was chosen for download, please select files ";
                 }

             }
             catch (Exception ex)
             {
                 ErrorLbl.Text = ErrorLbl.Text + "Download_Click: " + ex.Message;

                 return;
             }
             System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
         }

    }
}

 

 

 

 

 

 

 

 

12/22/2010 10:21:45 AM
Gravatar
Total Posts 18439

Re: building a form in a custom module

you should set breakpoints in your code and step through it to see what is happening. I would add Page.EnableViewState = true; in oninit event and I would remove all that try catch stuff and just let it break if something goes wrong so you can see the error details.

your code for checking for and creating a directory looks funky to me as well as all that changing back and forth of the thread culture. Server.MapPath expects a relative or virtual path not a file system path with \ chars in it.

Hope it helps,

Joe

12/23/2010 4:40:36 AM
Gravatar
Total Posts 50

Re: building a form in a custom module

Hi Joe, 

i added  EnableViewState = true to the web.config already.

also i tried debugging step by step and couldn't find out where the checkbox list was being rebuilt.

thanks for the tips on checking for and creating a directory and the thread culture.

after spending days on this without success i will turn to a different solution for now so right now its not urgent,

i might get back to it later,

thanks for your help

Boaz

You must sign in to post in the forums. This thread is closed to new posts.