Thursday, August 19, 2010

Do Post Back Handling

[asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="300000"]//For Five Minute
[/asp:Timer]

[script language="javascript" type="text/javascript"]

function DoPostBack() {
__doPostBack('Timer1', 'My Argument');
}

[/script]

Add in Webconfige file

[httpHandlers]
[add verb="GET,HEAD" path="ScriptResource.axd" validate="false" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/]
[/httpHandlers]

Friday, August 13, 2010

Pass query string in link button

[asp:LinkButton ID="lnkNav" runat="server" Text='[%#Eval("CategoryName")%]' PostBackUrl='[%#"~/Subcategory.aspx?CId="+Eval("CategoryId") %]'][/asp:LinkButton]

Friday, August 6, 2010

Upload multiple files

In .aspx file

[script type="text/javascript"]
function addElement() {
var ni = document.getElementById('myDiv');
var numi = document.getElementById('theValue');
var num = (document.getElementById('theValue').value - 1) + 2;
numi.value = num;
var newdiv = document.createElement('div');
var divIdName = 'my' + num + 'Div';
newdiv.setAttribute('id', divIdName);
newdiv.innerHTML = '[input type="file" name="attachment" id="attachment"/][input type="Button" value="Remove" onclick="removeElement(' + divIdName
+ ')"/]';
ni.appendChild(newdiv);
}


function removeElement(divNum) {
var d = document.getElementById('myDiv');
d.removeChild(divNum);
}

[/script]
[table]
[tr]
[td style="width: 295px"]
Upload Image Logo:
[/td]
[td]
[input type="file" name="attachment" runat="server" id="attachment" onchange="document.getElementById('moreUploadsLink').style.display =
'block';" /]
[div id="moreUploadsLink" style="display: none;"]
[a href="javascript:addElement();" style="font-size:12px;color:White;"]Upload More Images For Sliding[/a]
[/div]
[input type="hidden" value="0" id="theValue" /]
[div id="myDiv"]
[/div]
[/td]
[/tr]
[/table]
In .cs file


HttpFileCollection uploadFiles = HttpContext.Current.Request.Files;
for (int i = 1; i < uploadFiles.Count; i++)
{

HttpPostedFile uploadFile = uploadFiles[i];
if (uploadFile.FileName != null && uploadFile.FileName != "")
{
try
{
uploadFile.SaveAs(Server.MapPath("~/flash/banner/content/images/") + "\\" + Path.GetFileName(uploadFile.FileName));
strImageUrl = "~/flash/banner/content/images/" + Path.GetFileName(uploadFile.FileName);
strImageName = Path.GetFileName(uploadFile.FileName);

tblAlbum objAlbum = new tblAlbum();
objAlbum.PicName = strImageName;
objAlbum.PicUrl = strImageUrl;
objAlbum.BrandId = intBrandId;
db.tblAlbums.InsertOnSubmit(objAlbum);
db.SubmitChanges();
}
catch (Exception ex)
{
}

}
}

Calling Css from code behind

private void CssSelect()
{
if (Request.QueryString["Id"] == "2")
{
lnk2.Attributes.Add("class", "selected");
}
else if (Request.QueryString["Id"] == "3")
{
lnk3.Attributes.Add("class", "selected");
}
else if (Request.QueryString["Id"] == "4")
{
lnk4.Attributes.Add("class", "selected");
}
else if (Request.QueryString["Id"] == "5")
{
lnk5.Attributes.Add("class", "selected");
}
else
{
lnk1.Attributes.Add("class", "selected");
}
}

Write on XML file

private void WriteXml()
{
int intSubCatId = 0;
if (Request.QueryString["SId"] != null)
{
intSubCatId = Convert.ToInt32(Request.QueryString["SId"]);

var result = from subcat in db.tblSubCategories
join alb in db.tblAlbums on subcat.SubCategoryId equals alb.SubCatId
where subcat.SubCategoryId == intSubCatId
select new { FlashImage = alb.PicUrl };

if (result.Count() > 0)
{
string strxmlDocpath = Server.MapPath("~/flash/banner/xml/banner.xml");
XmlTextWriter writer = null;
try
{
writer = new XmlTextWriter(strxmlDocpath, Encoding.UTF8);
writer.Formatting = Formatting.Indented; writer.WriteStartDocument(true);

writer.WriteComment("This file was generated from an ASPX file");

writer.WriteStartElement("banner");

writer.WriteAttributeString("width", "597");
writer.WriteAttributeString("height", "354");
writer.WriteAttributeString("startWith", "1");

foreach (var query in result)
{
string strImage = query.FlashImage;
string strSlideImg = strImage.Replace("~/flash/banner/", "");
writer.WriteStartElement("item");
writer.WriteElementString("path", null, strSlideImg);
writer.WriteElementString("title", null, "");
writer.WriteElementString("target", null, "_blank");
writer.WriteElementString("link", null, "");
writer.WriteElementString("bar_color", null, "0xffffff");
writer.WriteElementString("bar_transparency", null, "40");
writer.WriteElementString("caption_color", null, "0xffffff");
writer.WriteElementString("caption_transparency", null, "60");
writer.WriteElementString("stroke_color", null, "0xffffff");
writer.WriteElementString("stroke_transparency", null, "60");
writer.WriteElementString("slideshowTime", null, "8");
writer.WriteEndElement();

}


writer.WriteEndElement();
writer.Flush();
writer.Close();
XmlDocument doc = new XmlDocument();
doc.Load(strxmlDocpath);

doc.Save(strxmlDocpath);
}
catch (Exception ex)
{

}
finally
{

}
Flash.Visible = true;
}
else
{
Flash.Visible = false;
}
}


}