Create Class in App_Code called BasePage.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web.UI;
class BasePage : System.Web.UI.Page
{
//Override two relevant methods that handle Loading and Saving of ViewState:
protected override object LoadPageStateFromPersistenceMedium()
{
object viewStateBag;
string m_viewState = (string)Session["ViewState"];
LosFormatter m_formatter = new LosFormatter();
try
{
viewStateBag = m_formatter.Deserialize(m_viewState);
}
catch
{
throw new HttpException("The View State is invalid.");
}
return viewStateBag;
}
protected override void SavePageStateToPersistenceMedium(object viewState)
{
MemoryStream ms = new MemoryStream();
LosFormatter m_formatter = new LosFormatter();
m_formatter.Serialize(ms, viewState);
ms.Position = 0;
StreamReader sr = new StreamReader(ms);
viewStateString = sr.ReadToEnd();
Session["ViewState"] = viewStateString;
ms.Close();
return;
}
}
and make all pages inhrit from BasePage class
Good Luck
Monday, December 15, 2008
Remove Cashing
Try this in Page Load
Good Luck
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Good Luck
Validate Image Size
Try this example :
<asp:CustomValidator ID="valFileSize" runat="server" ErrorMessage="The image exceeds 10 MB" onservervalidate="valFileSize_ServerValidate" Display="Dynamic" />
The method that actually performs the validation looks like this one:
protected void valFileSize_ServerValidate(object source, ServerValidateEventArgs args)
{
if (IsValid)
{
int maxSize = 5 * 1024 * 1024;
if (fileImage.PostedFile.ContentLength > maxSize)
{
args.IsValid = false;
}
}
}
and in web.config
<httpRuntime maxRequestLength="20480"/>
Good Luck
Subscribe to:
Posts (Atom)

