I want to convert from wmv to mp4, webm and ogv on upload.
is there a way to implement miro video converter or something like at codebehind?
what i use is ACT's AsyncUpload
aspx page
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
<script type="text/javascript">
function uploadError(sender, args) {
if (document.getElementById('<%=lblStatus.ClientID%>').innerText.indexOf('must be a video') == -1)
document.getElementById('<%=lblStatus.ClientID%>').innerText = "Upload error!", "<span style='color:red;'>" + args.get_errorMessage() + "</span>";
}
function StartUpload(sender, args) {
document.getElementById('<%=lblStatus.ClientID%>').innerText = 'Uploading';
}
function UploadComplete(sender, args) {
var filename = args.get_fileName();
var contentType = args.get_contentType();
if (contentType.indexOf('video') == -1) {
document.getElementById('<%=lblStatus.ClientID%>').innerText = "Uploaded file must be a video!", "<span style='color:red;'>" + args.get_errorMessage() + "</span>";
document.getElementById('<%=AsyncFileUpload1.ClientID%>').text.style.backgroundColor = "Red";
}
else {
var text = "" + filename + "\n" + "Size: " + parseInt((args.get_length()) / 1048576) + " MB" + " (" + args.get_length()+") bytes";
document.getElementById('<%=lblStatus.ClientID%>').innerText = text;
}
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
<h1>Add Movies to storage</h1>
<p>File upload<p>
<br />
<asp:AsyncFileUpload ID="AsyncFileUpload1" Width="400px" runat="server" OnClientUploadError="uploadError"
OnClientUploadStarted="StartUpload" OnClientUploadComplete="UploadComplete" CompleteBackColor="Lime"
UploaderStyle="Modern" ErrorBackColor="Red" ClientIDMode="AutoID" ThrobberID="Throbber"
UploadingBackColor="#66CCFF" OnUploadedComplete="AsyncFileUpload1_UploadedComplete" />
<asp:Label class="lastoppimg" ID="Throbber" runat="server" CssClass="style1">
<img src="../Movies/LoadingImg.gif" style="left:auto; right:auto; height:32px; width:32px;" alt="loading" />
</asp:Label>
<br />
<asp:Button class="lastoppk" ID="Button1" runat="server" Text="Start Upload" OnClick="Button3_Click" />
<asp:Label ID="lblStatus" runat="server" Style="font-family: Arial; font-size: small;"></asp:Label>
</div>
</div>
Codebehind
protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
if (AsyncFileUpload1.HasFile)
{
string strPath = MapPath("~/Test/") + Path.GetFileName(e.filename);
AsyncFileUpload1.SaveAs(strPath);
}
}
Miro is actually using FFMpeg for its transcoding.
You can use FFMpeg yourself or easier, You can use it from .NET by using the MediaHandlerPro component. (They also have a free version)
Related
Filename is not getting from a fileuploader.I upload the image from a fileuploader and load that image in a box,at that point it work fine.but when i try to save it, i didn't get that filename from fileuploader
<div class="box box-right" style="width:19%">
<div>
<asp:Image ID="Avatar" runat="server" Height="157px" Width="177px" />
</div>
<div class="button">
<asp:FileUpload ID="FileUpload1" style="width:169px" onchange="previewFile()" runat="server" />
</div>
</div>
In aspx page :
fileName = FileUpload1.FileName;
if (FileUpload1.HasFile)
{
fileName = FileUpload1.FileName;
string fileName1 = Path.GetFileName(FileUpload1.PostedFile.FileName);
newfile = "images/" + fileName;
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/images/") + strname);
}
you haven't provided what exception or error you are getting and u r saying that u r not Using Update Panel
THen you can do that in c# like this
in aspx
<form id="form1" runat="server">
<asp:FileUpload id="FileUpload1" runat="server" />
<asp:Button runat="server" id="UploadButton" text="Upload" onclick="UploadButton_Click" />
</form>
in your code behind
protected void UploadButton_Click(object sender, EventArgs e)
{
if(FileUpload1.HasFile)
{
try
{
string filename = Path.GetFileName(FileUpload1.FileName);
FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
}
catch(Exception ex)
{
}
}
}
or through javascript like this
var fileName = document.getElementById("<%= FileUpload1.ClientID %>");
or
var fileName = document.getElementById("FileUpload1").value;
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/images/") + strname);
you used this line and for saving file u used "strname" ...Now i couldn't see strname getting value anywhere in the code.
You have this
fileName = FileUpload1.FileName;
string fileName1 = Path.GetFileName(FileUpload1.PostedFile.FileName);
so shouldn't u use
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/images/") + fileName );
After saving information from a page in c# net 4.0 I need to add some pics in multiple mode.
I can't use net 4.5.
The problem :
If I open the page with multiple upload in the browser IE 11 this works correctly, and you can select multiple pics to upload.
If I open the same page as multiple upload in a window popup on IE 11, you can't select multiple pics to upload, but only a pic.
What's the problem ?
My code below, thank you in advance.
.aspx markup (Default.aspx)
<form id="form1" runat="server">
<div>
<asp:Panel ID="upload01" runat="server" CssClass="pure-form pure-form-stacked">
<fieldset style="margin-left: 50px">
<legend style="font-weight: bold; color: Red; margin-left: 10px;">PICS</legend>
<div class="pure-g">
<div class="pure-u-1 pure-u-md-1-3">
<label for="Pics">Pics</label>
<p>
<asp:FileUpload ID="fileUpload" multiple="true" runat="server" />
</p>
<p>
<p>
<asp:Button ID="btUpload" Text="Upload Files"
OnClick="Upload_Files" runat="server" />
</p>
</p>
<p>
<asp:Label ID="lblFileList" runat="server"></asp:Label>
</p>
<p>
<asp:Label ID="lblUploadStatus" runat="server"></asp:Label>
</p>
<p>
<asp:Label ID="lblFailedStatus" runat="server"></asp:Label>
</p>
</div>
</div>
</fieldset>
</asp:Panel>
</div>
</form>
.cs code-behind
protected void btnSave_Click(object sender, ImageClickEventArgs e)
{
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "var Mleft = (screen.width/2)-(760/2);var Mtop = (screen.height/2)-(700/2);window.open( 'Default.aspx', null, 'height=700,width=760,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,top=\'+Mtop+\', left=\'+Mleft+\'' );", true);
}
EDIT #1
protected void Upload_Files(object sender, EventArgs e)
{
if (upload01.HasFile) // CHECK IF ANY FILE HAS BEEN SELECTED.
{
int iUploadedCnt = 0;
int iFailedCnt = 0;
HttpFileCollection hfc = Request.Files;
lblFileList.Text = "Select <b>" + hfc.Count + "</b> file(s)";
if (hfc.Count <= 10) // 10 FILES RESTRICTION.
{
for (int i = 0; i <= hfc.Count - 1; i++)
{
HttpPostedFile hpf = hfc[i];
if (hpf.ContentLength > 0)
{
if (!File.Exists(Server.MapPath("\\images\\") +
Path.GetFileName(hpf.FileName)))
{
DirectoryInfo objDir =
new DirectoryInfo(Server.MapPath("\\images\\"));
string sFileName = Path.GetFileName(hpf.FileName);
string sFileExt = Path.GetExtension(hpf.FileName);
// CHECK FOR DUPLICATE FILES.
FileInfo[] objFI =
objDir.GetFiles(sFileName.Replace(sFileExt, "") + ".*");
if (objFI.Length > 0)
{
// CHECK IF FILE WITH THE SAME NAME EXISTS (IGNORING THE EXTENTIONS).
foreach (FileInfo file in objFI)
{
string sFileName1 = objFI[0].Name;
string sFileExt1 = Path.GetExtension(objFI[0].Name);
if (sFileName1.Replace(sFileExt1, "") ==
sFileName.Replace(sFileExt, ""))
{
iFailedCnt += 1; // NOT ALLOWING DUPLICATE.
break;
}
}
}
else
{
// SAVE THE FILE IN A FOLDER.
hpf.SaveAs(Server.MapPath("\\images\\") +
Path.GetFileName(hpf.FileName));
iUploadedCnt += 1;
}
}
}
}
lblUploadStatus.Text = "<b>" + iUploadedCnt + "</b> file(s) Uploaded.";
lblFailedStatus.Text = "<b>" + iFailedCnt +
"</b> duplicate file(s) could not be uploaded.";
}
else lblUploadStatus.Text = "Max. 10 files allowed.";
}
else lblUploadStatus.Text = "No files selected.";
}
I think your approach is wrong for this problem
Please see this, I hope this help.
Click here
I am exporting a pdf from a json string from database. My export buttons are in a gridview control - Image buttons. I am using a Handler (ashx) file for exporting.
The problem is, after exporting the buttons on the page (one button and one command field) are not posting back. My handler code and aspx code are below
Handler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using System.IO;
using System.Web.UI;
using System.Data;
using GE.MSA.DataQuality.DataAccess;
using GE.MSA.DataQuality.DataAccess.Authentication;
using GE.MSA.DataQuality.DataAccess.EntityModel;
using Newtonsoft.Json;
namespace GE.MSA.DataQuality.Web
{
/// <summary>
/// Summary description for CreatePDF
/// </summary>
public class CreatePDF : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
int _id = Convert.ToInt32(context.Request.QueryString["Id"]);
string _report = context.Request.QueryString["Report"];
string _lockedfrom = context.Request.QueryString["LockedFrom"];
string _lockedto = context.Request.QueryString["LockedTo"];
string _docheader = (_report == "CostServiceReport" ? "Cost & Service Report - " : "Service Report - ") + "Locked from : " + _lockedfrom + " to " + _lockedto;
string _doctitle = _report + "-" + _lockedfrom + "-" + _lockedto + ".pdf";
DataTable _PDFReport = new DataTable();
if (_report == "CostServiceReport")
{
using (var db = new dbReferenceTablesEntities())
{
string csr = (from i in db.CS_Billing_LockPeriod
where i.ID == _id
select i.CostServiceReport).FirstOrDefault().ToString();
_PDFReport = (DataTable)JsonConvert.DeserializeObject(csr, _PDFReport.GetType());
}
}
else
{
if (_report == "ServiceReport")
{
using (var db = new dbReferenceTablesEntities())
{
string sr = (from i in db.CS_Billing_LockPeriod
where i.ID == _id
select i.ServiceReport).FirstOrDefault().ToString();
_PDFReport = (DataTable)JsonConvert.DeserializeObject(sr, _PDFReport.GetType());
}
}
}
Document pdfDoc = new Document(PageSize.A3, 20, 20, 20, 20);
pdfDoc.SetPageSize(iTextSharp.text.PageSize.A3.Rotate());
try
{
PdfWriter.GetInstance(pdfDoc, System.Web.HttpContext.Current.Response.OutputStream);
pdfDoc.Open();
Chunk c = new Chunk("" + _docheader + "", FontFactory.GetFont("Verdana", 15));
Paragraph p = new Paragraph();
p.Alignment = Element.ALIGN_CENTER;
p.Add(c);
pdfDoc.Add(p);
string clientLogo = context.Server.MapPath(".") + "/images/abc.png";
string imageFilePath = context.Server.MapPath(".") + "/images/abc.png";
iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageFilePath);
//Resize image depend upon your need
jpg.ScaleToFit(60f, 40f);
//Give space before image
jpg.SpacingBefore = 0f;
//Give some space after the image
jpg.SpacingAfter = 1f;
jpg.Alignment = Element.HEADER;
pdfDoc.Add(jpg);
Font font8 = FontFactory.GetFont("ARIAL", 7);
DataTable dt = _PDFReport;
if (dt != null & dt.Rows.Count > 0)
{
//Craete instance of the pdf table and set the number of column in that table
PdfPTable PdfTable = new PdfPTable(dt.Columns.Count);
PdfTable.HeaderRows = 1;
PdfPCell PdfPCell = null;
for (int i = 0; i < dt.Columns.Count; i++)
{
PdfPCell = new PdfPCell(new Phrase(new Chunk(dt.Columns[i].ColumnName.ToString(), FontFactory.GetFont("Verdana", 12))));
PdfPCell.HorizontalAlignment = Element.ALIGN_CENTER;
PdfPCell.VerticalAlignment = Element.ALIGN_MIDDLE;
PdfPCell.BackgroundColor = new Color(109, 159, 213);
PdfTable.AddCell(PdfPCell);
}
for (int rows = 0; rows < dt.Rows.Count; rows++)
{
for (int column = 0; column < dt.Columns.Count; column++)
{
PdfPCell = new PdfPCell(new Phrase(new Chunk(dt.Rows[rows][column].ToString(), font8)));
PdfTable.AddCell(PdfPCell);
}
}
//PdfTable.SpacingBefore = 15f; // Give some space after the text or it may overlap the table
pdfDoc.Add(PdfTable); // add pdf table to the document
}
pdfDoc.Close();
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("content-disposition", "attachment; filename= " + _doctitle);
System.Web.HttpContext.Current.Response.Write(pdfDoc);
context.Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
catch (DocumentException de)
{
System.Web.HttpContext.Current.Response.Write(de.Message);
}
catch (IOException ioEx)
{
System.Web.HttpContext.Current.Response.Write(ioEx.Message);
}
catch (Exception ex)
{
System.Web.HttpContext.Current.Response.Write(ex.Message);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
ASPX Page
<%# Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="LockForcing.aspx.cs" Inherits="GE.MSA.DataQuality.Web.LockForcing" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:ScriptManager ID="scriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
<h2>Lock Force Calculation</h2>
<div>
<fieldset>
<legend>Set Lock Period</legend>
<table>
<tr>
<td>
<label>Start Month</label></td>
<td>
<asp:DropDownList ID="ddlStartMonth" runat="server" Width="100%">
<asp:ListItem>01</asp:ListItem>
<asp:ListItem>02</asp:ListItem>
<asp:ListItem>03</asp:ListItem>
<asp:ListItem>04</asp:ListItem>
<asp:ListItem>05</asp:ListItem>
<asp:ListItem>06</asp:ListItem>
<asp:ListItem>07</asp:ListItem>
<asp:ListItem>08</asp:ListItem>
<asp:ListItem>09</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>11</asp:ListItem>
<asp:ListItem>12</asp:ListItem>
</asp:DropDownList></li></td>
<td></td>
<td>
<label>Start Year</label></td>
<td>
<asp:DropDownList ID="ddlStartYear" runat="server" Width="100%">
</asp:DropDownList></td>
</tr>
<tr>
<td>
<label>End Month</label></td>
<td>
<asp:DropDownList ID="ddlEndMonth" runat="server" Width="100%">
<asp:ListItem>01</asp:ListItem>
<asp:ListItem>02</asp:ListItem>
<asp:ListItem>03</asp:ListItem>
<asp:ListItem>04</asp:ListItem>
<asp:ListItem>05</asp:ListItem>
<asp:ListItem>06</asp:ListItem>
<asp:ListItem>07</asp:ListItem>
<asp:ListItem>08</asp:ListItem>
<asp:ListItem>09</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>11</asp:ListItem>
<asp:ListItem>12</asp:ListItem>
</asp:DropDownList></td>
<td></td>
<td>
<label>End Year</label></td>
<td>
<asp:DropDownList ID="ddlEndYear" runat="server" Width="100%">
</asp:DropDownList></td>
<td>
<asp:Button ID="btnLock" runat="server" Width="120px" Text="Lock" CssClass="submitButton"
BorderStyle="None" OnClick="btnLock_Click" />
</td>
<td>
<asp:Label runat="server" ID="lblLockMessage"></asp:Label>
<asp:Timer ID="Timer1" runat="server" Interval="5000" Enabled="false" OnTick="Timer1_Tick"></asp:Timer>
</td>
</tr>
</table>
</fieldset>
</div>
<div>
<table width="100%">
<tr>
<td>
<label>Lock Period Details</label>
</td>
<td align="right">
<asp:Label runat="server" ID="lblmsg"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2">
<asp:GridView ID="gvLockPeriod" runat="server" AutoGenerateColumns="false" CssClass="mGrid" OnRowDeleting="gvLockPeriod_RowDeleting"
DataKeyNames="Id">
<Columns>
<asp:CommandField ShowDeleteButton="true" ControlStyle-ForeColor="darkcyan" DeleteText="Unlock"></asp:CommandField>
<asp:BoundField DataField="FromDate" HeaderText="FromDate" />
<asp:BoundField DataField="ToDate" HeaderText="ToDate" />
<asp:TemplateField HeaderText="Cost&ServiceReport">
<ItemTemplate>
<asp:ImageButton ImageUrl="~/images/Pdf-16.png" runat="server" ToolTip="Download Cost & Service Report"
Visible='<%# Convert.ToBoolean(Eval("CostServiceReport")) %>'
PostBackUrl='<%#"CreatePDF.ashx?id="+Eval("Id")+"&Report=CostServiceReport"+"&LockedFrom="+Eval("fromdate")+"&LockedTo="+Eval("todate")+""%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ServiceReport">
<ItemTemplate>
<asp:ImageButton ImageUrl="~/images/Pdf-16.png" runat="server" ToolTip="Download Service Report"
Visible='<%# Convert.ToBoolean(Eval("ServiceReport")) %>'
PostBackUrl='<%#"CreatePDF.ashx?id="+Eval("Id")+"&Report=ServiceReport"+"&LockedFrom="+Eval("fromdate")+"&LockedTo="+Eval("todate")+""%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ModifiedBy" HeaderText="CreatedUser" />
<asp:BoundField DataField="ModifiedDate" HeaderText="CreatedDate" />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<div class="overlays" />
<div style="font-weight: bold; align-content: center" class="overlayContents">
<asp:Image ID="aspImg1" runat="server" ImageUrl="~/images/ajax-loader.GIF" />
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</asp:Content>
After flushing the response call the response end method.
context.Response.Flush();
System.Web.HttpContext.Current.Response.End();
I am creating a table which should read binary image from DB and display in Html table.
My Markup:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Table Test</title>
<style type="text/css">
.small-ad-wrapper{width:215px;height:195px;overflow:hidden;}
.small-ad-wrapper .portfolio-img-control{width:204px;height:134px;overflow:hidden;margin-bottom:3px;}
</style>
</head>
<body>
<form id="Form1" runat="server">
<div>
<br />
<asp:Button ID="cmdCreate" OnClick="cmdCreate_Click" runat="server" Text="Create" />
<br />
<br />
<asp:Table ID="tbl" runat="server" />
</div>
</form>
</body>
</html>
My Code Behind:
StringBuilder htmlTable = new StringBuilder();
htmlTable.Append("<table border='1'>");
htmlTable.Append(#"<tr style='background-color:green; color: White;'>
<th>Company Name</th>
</tr>");
int i = 1;
foreach (DataRow row in DT.Rows)
{
if (i == 1)
{
htmlTable.Append("<tr style='color: White;'>");
}
htmlTable.Append("<div class='portfolio-img-control'>");
byte[] bytes = (byte[])(byte[])row["LogoFile"];
string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
System.Web.UI.WebControls.Image imgNew = new System.Web.UI.WebControls.Image();
imgNew.ImageUrl = "data:image/png;base64," + base64String;
htmlTable.Append("<td>" + imgNew + "</td>");
htmlTable.Append("</div");
if (i == 3)
{
htmlTable.Append("</tr>");
i = 1;
}
else
i = i + 1;
}
htmlTable.Append("</table>");
DBDataPlaceHolder.Controls.Add(new Literal { Text = htmlTable.ToString() });
htmlTable.Append("<tr>");
htmlTable.Append("<td align='center' colspan='4'>There is no Record.</td>");
htmlTable.Append("</tr>");
But it gives me result "System.Web.UI.WebControls.Image" and doesnt show image at all.
How to do this? Please reply Thanks
Because you create a new asp.net image control, and try to use the object as string.
These lines must be remove...
System.Web.UI.WebControls.Image imgNew = new System.Web.UI.WebControls.Image();
imgNew.ImageUrl = "data:image/png;base64," + base64String;
htmlTable.Append("<td>" + imgNew + "</td>");
if you like to render it as string, must be change as:
htmlTable.AppendFormat("<td><img src=\"data:image/png;base64,{0}\"></td>", base64String);
Please note, I do not know if the rest of your code is bug free...
I have a c# web app that has a calendar - nothing special. The problem I have is that only the numbers can be clicked on and not the entire cell. I've added a onmouseover type handler that makes the cell change color when it's moused over but that's misleading because you can't click on the edge.
Is there any way in asp.net c# that I can make this calendar allow the entire cell to be clickable and not just the hypertext number of the date? I hope I've explained it well enough.
Thanks
<asp:Calendar ID="Calendar1" runat="server"
DayStyle-ForeColor="DarkBlue"
DayHeaderStyle-BackColor="#FEF6CB"
DayStyle-Height="25"
SelectedDayStyle-BackColor="#003F7D"
SelectedDayStyle-ForeColor="White"
DayNameFormat="FirstLetter"
ShowGridLines="true"
BorderColor="Black"
TitleStyle-BackColor="#003F7D"
TitleStyle-ForeColor="White"
TitleStyle-CssClass="CalHeader"
NextPrevStyle-CssClass="CalNextPrev"
NextPrevStyle-ForeColor="White"
OnVisibleMonthChanged="cal_ReserveDate_VisibleMonthChanged"
OnDayRender="cal_ReserveDate_DayRender"
OnSelectionChanged="cal_ReserveDate_SelectionChanged"
DayStyle-BorderColor="Black"
SelectedDayStyle-CssClass="CalendarSelectedDay"
Width="97%" />
UPDATE:
Here is the basic framework of the ascx page:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="BuyTourProductDialogGalaxy2.ascx.cs" Inherits="ConLib_Custom_BuyTourProductDialog2" %>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
function fixCalendar() {
var a = $('#<%=cal_ReserveDate.ClientID%> a ');
a.contents().wrap("<div/>");
}
</script>
<asp:UpdatePanel ID="upnl_Cal" runat="server" ChildrenAsTriggers="true" UpdateMode="Always">
<ContentTemplate>
<div class="BuyTourProductDialog">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td colspan="2" width="75%">
<asp:Label ID="lblInstructions" runat="server" Text="" EnableViewState="False" CssClass="ReservationInstructions" />
</td>
<td width="25%">
<span style="float: right;">
<asp:Button ID="btn_Reset" runat="server" Text="Reset" OnClick="btn_Reset_Click" Visible="false" CssClass="ResetButton" />
<asp:Button ID="btn_Reserve" runat="server" Text="Reserve" OnClick="btn_Reserve_Click" Visible="true" />
<asp:Button ID="btn_AddToCart" runat="server" Text="Add To Cart" Visible="false" OnClick="btn_AddToCart_Click" />
<asp:Button ID="btn_Continue" runat="server" Text="Continue" Visible="false" OnClick="btn_Continue_Click" />
</span>
</td>
</tr>
</table>
<%-- Calendar Panel --%>
<asp:Panel ID="pnl_GatewayCalendar" runat="server" Visible="false">
<table width="100%">
<%-- Header --%>
<tr>
<td align="center" colspan="2">
<asp:Label ID="lbl_SelectedDate" runat="server" Font-Bold="true" CssClass="SelectedDate" /><br />
</td>
</tr>
<tr>
<%-- Calendar side --%>
<td width="50%" valign="top">
<asp:Calendar ID="cal_ReserveDate" runat="server"
DayStyle-ForeColor="DarkBlue" DayHeaderStyle-BackColor="#FEF6CB" DayStyle-Height="25"
SelectedDayStyle-BackColor="#003F7D" SelectedDayStyle-ForeColor="White"
DayNameFormat="FirstLetter" ShowGridLines="true" BorderColor="Black"
TitleStyle-BackColor="#003F7D" TitleStyle-ForeColor="White" TitleStyle-CssClass="CalHeader"
NextPrevStyle-CssClass="CalNextPrev" NextPrevStyle-ForeColor="White"
OnVisibleMonthChanged="cal_ReserveDate_VisibleMonthChanged"
OnDayRender="cal_ReserveDate_DayRender" OnSelectionChanged="cal_ReserveDate_SelectionChanged"
DayStyle-BorderColor="Black" SelectedDayStyle-CssClass="CalendarSelectedDay" Width="97%" />
</td>
<%-- Event Times side --%>
<td valign="top">
<%-- Another section here for tour times. --%>
</td>
</tr>
</table>
</asp:Panel>
</div>
</ContentTemplate>
</asp:UpdatePanel>
I feel the following links might help you :
http://forums.asp.net/t/1278710.aspx/1
.net calendar - making the whole cell perform postback (clickable)
http://weblogs.sqlteam.com/jhermiz/archive/2007/12/10/Cool-Tricks-With-The-ASP.net-Calendar.aspx
http://forums.asp.net/t/1697353.aspx/1
http://forums.asp.net/t/1216321.aspx/1
The Calendar control doesn't allow you to make the whole cell clickable but you can force it with a little of jQuery if you don't mind using it.
Here's how:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </script>
<script>
$(function () {
var a = $('#<%=Calendar1.ClientID%> a');
//wrap the anchor text in a div to force the link to expand
a.contents().wrap("<div/>");
});
</script>
All you need to do is reference jQuery
Update: version for UpdatePanel
Place the following at the top of the page:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
function fixCalendar() {
var a = $('#<%=cal_ReserveDate.ClientID%> a ');
a.contents().wrap("<div/>");
}
</script>
<asp:ScriptManager ID="scriptManager" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="updatePanel" runat="server">
<ContentTemplate>
<asp:Calendar ID="cal_ReserveDate" runat="server"
... //etc
Width="97%" />
</ContentTemplate>
</asp:UpdatePanel>
Now, on Page_Load you need to always call the above script as so:
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "fixCalendar();", true);
}
Put this in the body of Default page
<body>
<form id="form1" runat="server">
<table title="mxit:table:full" style="width: 100%;" align="center">
<tr style="background-color: red; text-align: center;">
<td style="width: 25%;">
< Prev
</td>
<td style="width: 50%;">
<asp:Label ID="lblMonth" runat="server"></asp:Label>
<asp:Label ID="lblYear" runat="server"></asp:Label>
<br />
</td>
<td style="width: 25%">
Next >
</td>
</tr>
</table>
<asp:Label ID="lbltest" runat="server" Text=""></asp:Label>
</form>
</body>
Put this in the code Behind Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
if (Request.QueryString["id"] == "next")
{
if ((int)Session["currentMonth"] >= 12)
{
Session["currentMonth"] = 1;
Session["currentYear"] = (int)Session["currentYear"] + 1;
}
else
{
Session["currentMonth"] = (int)Session["currentMonth"] + 1;
}
DateTime dt = new DateTime((int)Session["currentYear"], (int)(Session["currentMonth"]), 1);
string obj = dt.DayOfWeek.ToString();
GetCalender(obj);
}
else if (Request.QueryString["id"] == "prev")
{
if ((int)Session["currentMonth"] <= 1)
{
Session["currentMonth"] = 12;
Session["currentYear"] = (int)Session["currentYear"] - 1;
}
else
{
Session["currentMonth"] = (int)Session["currentMonth"] - 1;
}
DateTime dt = new DateTime((int)Session["currentYear"], (int)(Session["currentMonth"]), 1);
string obj = dt.DayOfWeek.ToString();
GetCalender(obj);
}
else //this will run when we start the project
{
int currentYear = DateTime.Now.Year;
int currentMonth = DateTime.Now.Month;
Session["currentMonth"] = currentMonth;
Session["currentYear"] = currentYear;
DateTime dt = new DateTime((int)Session["currentYear"], (int)(Session["currentMonth"]), 1);
string obj = dt.DayOfWeek.ToString();
GetCalender(obj);
}
}
catch
{
Response.Redirect("Default.aspx");
}
}
}
private void GetCalender(string obj)
{
try
{
string[] months = new string[] {"January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November", "December"};
DayOfWeek objDayofweek = DateTime.Today.Date.DayOfWeek;
lbltest.Text = "<table style='width:100%' align='center'><colgroup span='7' style='width:15%'></colgroup><tr><td>Mon</td>";
lbltest.Text = lbltest.Text + "<td>Tue</td>";
lbltest.Text = lbltest.Text + "<td>Wed</td>";
lbltest.Text = lbltest.Text + "<td>Thu</td>";
lbltest.Text = lbltest.Text + "<td>Fri</td>";
lbltest.Text = lbltest.Text + "<td>Sat</td>";
lbltest.Text = lbltest.Text + "<td>Sun</td></tr><tr>";
int y = 1;
switch (obj.ToString())
{
case "Monday":
y = 1;
break;
case "Tuesday":
lbltest.Text = lbltest.Text + "<td> </td>";
y = 2;
break;
case "Wednesday":
lbltest.Text = lbltest.Text + "<td> </td>";
lbltest.Text = lbltest.Text + "<td> </td>";
y = 3;
break;
case "Thursday":
lbltest.Text = lbltest.Text + "<td> </td>";
lbltest.Text = lbltest.Text + "<td> </td>";
lbltest.Text = lbltest.Text + "<td> </td>";
y = 4;
break;
case "Friday":
lbltest.Text = lbltest.Text + "<td> </td>";
lbltest.Text = lbltest.Text + "<td> </td>";
lbltest.Text = lbltest.Text + "<td> </td>";
lbltest.Text = lbltest.Text + "<td> </td>";
y = 5;
break;
case "Saturday":
lbltest.Text = lbltest.Text + "<td> </td>";
lbltest.Text = lbltest.Text + "<td> </td>";
lbltest.Text = lbltest.Text + "<td> </td>";
lbltest.Text = lbltest.Text + "<td> </td>";
lbltest.Text = lbltest.Text + "<td> </td>";
y = 6;
break;
case "Sunday":
lbltest.Text = lbltest.Text + "<td> </td>";
lbltest.Text = lbltest.Text + "<td> </td>";
lbltest.Text = lbltest.Text + "<td> </td>";
lbltest.Text = lbltest.Text + "<td> </td>";
lbltest.Text = lbltest.Text + "<td> </td>";
lbltest.Text = lbltest.Text + "<td> </td>";
y = 7;
break;
}
for (int dayday = Convert.ToInt32(objDayofweek); dayday <= DateTime.DaysInMonth((int)Session["currentYear"], (int)(Session["currentMonth"])); dayday++)
{
if (y < 7)
{
lbltest.Text = lbltest.Text + "<td><a href='#Date=" + dayday.ToString() + "/" + Session["currentMonth"] + "/" + Session["currentYear"] + "'>" + dayday.ToString() + "</a></td>";
y++;
}
else
{
lbltest.Text = lbltest.Text + "<td><a href='#Date=" + dayday.ToString() + "/" + Session["currentMonth"] + "/" + Session["currentYear"] + "'>" + dayday.ToString() + "</a></td>";
y = 1;
lbltest.Text = lbltest.Text + "</tr><tr>";
}
}
lbltest.Text = lbltest.Text + "</tr></table>";
lblMonth.Text = months[(int)Session["currentMonth"] - 1].ToString();
lblYear.Text = Session["currentYear"].ToString();
}
catch
{
Response.Redirect("Default.aspx");
}
}
}