Thursday, November 5, 2009

Ajax webpart class inheriting the Webpart class

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;

namespace AuctionsWP
{
public class clsLoadAuctionsWP:WebPart
{
#region "Global variable declarations"

protected Control _control = null;
protected string _exception = String.Empty;

//This UserControls is a folder in the VirtualServer
//directory of your Sharepoint WebApplication.
//We have to create this folder in the VirtualServer
//directory and copy the UserControl at that location
protected string UserControlPath = @"~/UserControls/";

protected string UserControlFileName = @"UCAuctions.ascx";

#endregion

#region "Create Child Controls method to create the controls for the webpart"

protected override void CreateChildControls()
{
this.FixFormAction();

try
{
_control = this.Page.LoadControl(UserControlPath + UserControlFileName);
this.Controls.Add(_control);

}
catch (Exception ex)
{
_exception += "CREATE ERROR:" + ex.Message;
}
finally
{
base.CreateChildControls();
}
}
#endregion

#region "RenderControls method , to render the controls inside the webpart class"

protected override void RenderContents(HtmlTextWriter writer)
{
try
{
base.RenderContents(writer);
}
catch (Exception ex)
{
_exception += "RENDER ERROR:" + ex.Message;
}
}

#endregion

#region "Fix form Action method"
private void FixFormAction()
{
//STaging Script
if (this.Page.Form != null)
{
string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
if (formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
{
this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
}
}
ScriptManager.RegisterStartupScript(this, typeof(clsLoadAuctionsWP), "UpdatePanelFixup", "_spOriginalFormAction = document.forms[0].action;_spSuppressFormOnSubmitWrapper=true;", true);


//// Production Script
//if (this.Page.Form != null)
//{
// String fixupScript = @"_spBodyOnLoadFunctionNames.push(""_initFormActionAjax""); ";
// ScriptManager.RegisterStartupScript(this, typeof(clsLoadAuctionsWP), "UpdatePanelFixup", fixupScript, true);
//}

}
#endregion
}
}

User Control Code behind for Ajax webpart

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 UtilityClass;
using TejariErrorHandler;

namespace AuctionsWP
{
public partial class UCAuctions : System.Web.UI.UserControl
{
#region "Global variable declarations"

DataSet dsCurrentAuctions = null;
bool isTenRecords = true;
DataTable dtTemp = new DataTable("Auctions");
clsTejariErrorHandler objErrorHandler = new clsTejariErrorHandler();
clsAuctionsMiddleTier objCurrentAuctions = new clsAuctionsMiddleTier();
string strUserID, strCountryCode, strCompany="";
int intUserID, intNumberOfRows;
int intSiteLang;
DataSet dsCompany;
DataSet dsCountry;

#endregion

#region "Page load event"
protected void Page_Load(object sender, EventArgs e)
{
// wlblMessage.Text = DateTime.Now.ToString();
try
{
imgAucDivClose.Attributes.Add("OnClick", "CloseAuctionDiv();");

if (!Page.IsPostBack)
{
// divAuctions.Visible = false;
AssignUrlDivLinks();
divAuctions.Style.Add("visibility", "hidden");
wlnkEditAuctions.Attributes.Add("OnClick", "return fnAuctionDivVisible();");
LoadAuctionsData();
wlnkEditAuctions.Style.Add("visibility", "hidden");

if (Request.Cookies["LoginCookie"] == null)
{
wlblAuctionCountry.Enabled = false;
wddlistAuctionsCountry.Enabled = false;
wlblCompany.Enabled = false;
wddlistCompany.Enabled = false;
wlblAuctionsNo.Enabled = false;
wddlistAuctionsNo.Enabled = false;
wlnkbtnSubmit.Enabled = false;
wlblAuctionCaption.Enabled = false;
wtxtAuctionCaption.Enabled = false;
wlnkbtnDefaultSettings.Enabled = false;

}

#region "Code to populate the Drop down controls inside the Div"

// "Code to assign the Cached dataset to the dataset object for Company and Country"
dsCompany = (DataSet)Cache["cacheCompany"];
dsCountry = (DataSet)Cache["cacheCountry"];


// "Code to get data directly from the database for Company and Country if the cache is null"
if (dsCompany == null)
{
// Fetch data directly from the database, and assign it to the dataset object.
dsCompany = PopulateCompany();
Cache.Insert("cacheCompany", dsCompany, null, DateTime.Now.AddHours(2), TimeSpan.Zero);
}

if (dsCountry == null)
{
// Fetch data directly from the database, and assign it to the dataset object.
dsCountry = PopulateCountry();
Cache.Insert("cacheCountry", dsCountry, null, DateTime.Now.AddDays(7), TimeSpan.Zero);
}


// Assigning the values to the drop down controls
wddlistCompany.Items.Clear();
wddlistCompany.DataSource = dsCompany;
wddlistCompany.DataTextField = "Company";
wddlistCompany.DataValueField = "Company";
wddlistCompany.DataBind();
wddlistCompany.Items.Insert(0, new ListItem("All Company", ""));

wddlistAuctionsCountry.Items.Clear();
wddlistAuctionsCountry.DataSource = dsCountry;
wddlistAuctionsCountry.DataTextField = "CountryName";
wddlistAuctionsCountry.DataValueField = "CountryCode";
wddlistAuctionsCountry.DataBind();
wddlistAuctionsCountry.Items.Insert(0, new ListItem("All Country", "TGL"));

// Method call to populate the Auctions count
PopulateNoOfDays();

#endregion


}

}
catch (Exception ex)
{
objErrorHandler.LogError(ex, false);
// wlblMessage.Text = "ERROR AUCTIONS :" + ex.Message;
// Server.ClearError();
}
}

#endregion

#region "Method to load Auction data"
protected void LoadAuctionsData()
{
string strCountryCode = "";

#region "Code to check the Country Selected"
if (Request.QueryString["Code"] != null)
{
strCountryCode = Request.QueryString["Code"].ToString();
// Response.Write("Query STRING: " + strCountryCode + "
");
}
else if (HttpContext.Current.Session["sessSelectedCountry"] != null)
{
strCountryCode = HttpContext.Current.Session["sessSelectedCountry"].ToString().Substring(0, 3);
// Response.Write("Session: " + strCountryCode + "
");
}
else
{
strCountryCode = "TGL";
// Response.Write("Default: " + strCountryCode + "
");
}
#endregion

#region "Code to get the Site Language and Set the Labels Text as per the site language"
clsUtility objUtility = new clsUtility();
// Update the Text of the Webpart header to ENGLISH,ARABIC,CHINESE language
//string strSiteName = "Tejari";
string strSiteName = objUtility.GetLang();
SetLanguageSpecHeaderText(strSiteName);

#endregion

#region "Code to check whether the user is logged In or Not and set the customized setting if customized"


if (Request.Cookies["LoginCookie"] != null)
{
// Check if the User has clicked on the Default Setting link
if (Convert.ToInt32(ViewState["vwAuctionsDefautSettings"]) != 1)
{
/* START: Commneted for Testing in the Local Project */
HttpCookie objCookie = Request.Cookies.Get("LoginCookie");
strUserID = objCookie.Values["ID"].ToString();
intUserID = objCurrentAuctions.GetUserID(strUserID);
/* END: Commneted for Testing in the Local Project */


DataSet dsPersonalize = objCurrentAuctions.GetPersonalizationInfo(intUserID);

Session["sessUserCustomizationInfo"] = dsPersonalize;

DataSet dsCustomizationInfo = null;

if (Session["sessUserCustomizationInfo"] != null)
{
dsCustomizationInfo = (DataSet)Session["sessUserCustomizationInfo"];
}
DataView dvCustomizationInfo = new DataView();

dvCustomizationInfo = (DataView)dsCustomizationInfo.Tables[0].DefaultView;

dvCustomizationInfo.RowFilter = "Type='" + "SCA" + "'";


// wlblAucSignUp1.Text = "COUNT: " + dvCustomizationInfo.Count.ToString() + " :: "+ dvCustomizationInfo[0].Row["CountryCode"].ToString() ;

if (dvCustomizationInfo.Count > 0)
{
// wlblAucSignUp1.Text = "asfdsfdsf...";

strCountryCode = dvCustomizationInfo[0].Row["CountryCode"].ToString();
intNumberOfRows = Convert.ToInt32(dvCustomizationInfo[0].Row["TotalRec"].ToString());
strCompany = dvCustomizationInfo[0].Row["Company"].ToString();

if (strSiteName.Equals("Tejari"))
{

if (dvCustomizationInfo[0].Row["EnglishTitle"].ToString() != "")
{
wlblCurrentAuctions.Text = dvCustomizationInfo[0].Row["EnglishTitle"].ToString();
wtxtAuctionCaption.Text = dvCustomizationInfo[0].Row["EnglishTitle"].ToString();

}
else
{

SetLanguageSpecHeaderText(strSiteName);
}
}
else if (strSiteName.Equals("Arabic"))
{

if (dvCustomizationInfo[0].Row["ArabicTitle"].ToString() != "")
{
wtxtAuctionCaption.Text = dvCustomizationInfo[0].Row["ArabicTitle"].ToString();
wlblCurrentAuctions.Text = dvCustomizationInfo[0].Row["ArabicTitle"].ToString();

}
else
{
SetLanguageSpecHeaderText(strSiteName);

}

}
else if (strSiteName.Equals("Chinese"))
{

if (dvCustomizationInfo[0].Row["ChineseTitle"].ToString() != "")
{
wtxtAuctionCaption.Text = dvCustomizationInfo[0].Row["ChineseTitle"].ToString();
wlblCurrentAuctions.Text = dvCustomizationInfo[0].Row["ChineseTitle"].ToString();

}
else
{
SetLanguageSpecHeaderText(strSiteName);
}
}
}
else
{
// SetLanguageSpecHeaderText(strSiteName);
wtxtAuctionCaption.Text = "CURRENT AUCTIONS";
// wlblAucSignUp1.Text = "asfdsfdsf";
intNumberOfRows = 10;
}

}
else
{
intNumberOfRows = 10;
}
}
else
{
intNumberOfRows = 10;
}
#endregion

#region "Code to set the header label alignment to right for arabic sites"
if (strSiteName == "Arabic")
{
tdSellersOpportunities.Align = "right";
tdCurrentAuctions.Align = "right";
wimgAuctionsLink.Visible = false;
}
#endregion

#region "Code to assign the Cached dataset to the dataset object"
//Assigning the Cached dataset to the dataset object
dsCurrentAuctions = (DataSet)Cache["cacheCurrentAuctions"];
#endregion

#region "Code to fetch the data directly from the database "
// If the dataset is null , fetch the data directly from the database.
if (dsCurrentAuctions == null)
{
// Fetch data directly from the database, and assign it to the dataset object.

dsCurrentAuctions = objCurrentAuctions.GetAuctionsData();

// Define the timelines for the expiry of the Cache. And add the dataset to the
// Cache variable cacheCurrentAuctions.
ViewState["vwStateNew"] = null;
ViewState["vwStateClosing"] = null;
Cache.Insert("cacheCurrentAuctions", dsCurrentAuctions, null, DateTime.Now.AddHours(2), TimeSpan.Zero);
}
#endregion


DataView dvStatus = new DataView();
DataView dvCurrentAuctions = new DataView();

dvCurrentAuctions = (DataView)dsCurrentAuctions.Tables[0].DefaultView;
dtTemp = dsCurrentAuctions.Tables[0].Clone();

if (strCountryCode != "TGL")
{
if (strCompany != "")
{
dvCurrentAuctions.RowFilter = "CountryCode='" + strCountryCode + "' and Company='"+strCompany;
}
else
{
dvCurrentAuctions.RowFilter = "CountryCode='" + strCountryCode + "'";
}
if (dvCurrentAuctions.Count < 10)
{
isTenRecords = false;
dvCurrentAuctions.RowFilter = "";
}
}
dvStatus = dvCurrentAuctions;

if (isTenRecords == true && strCountryCode != "TGL")
{
if(strCompany!="")
{
dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Company='" + strCompany + "'and Status='N'";
}
else
{
dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Status='N'";
}
}
else
{
if (strCompany != "")
{
dvStatus.RowFilter = "Company='" + strCompany+ "' and Status='N'";
}
else
{
dvStatus.RowFilter = "Status='N'";
}

}
int intNewCount = dvStatus.Count;


if (isTenRecords == true && strCountryCode != "TGL")
{
if (strCompany != "")
{
dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Company='" + strCompany + "'and Status='C'";
}
else
{
dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Status='C'";
}
}
else
{
if (strCompany != "")
{
dvStatus.RowFilter = "Company='" + strCompany + "'and Status='C'";

}
else
{
dvStatus.RowFilter = "Status='C'";
}
}
int intCloseCount = dvStatus.Count;


// Code to Filter the Records
#region "Code to filter the records for the selected country if both the 'New' and 'Closing' auctions is greater then 5 "
if (intNewCount > (intNumberOfRows / 2) && intCloseCount > (intNumberOfRows / 2))
{
if (isTenRecords == true && strCountryCode != "TGL")
{
if (strCompany != "")
{
dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Company='" + strCompany + "' and Status='N'";
}
else
{
dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Status='N'";
}
}
else
{
if (strCompany != "")
{
dvStatus.RowFilter = "Company='" + strCompany + "' and Status='N'";
}
else
{
dvStatus.RowFilter = "Status='N'";
}
}


#region "Logic for Ajax to shuffle the records-- Status as New "
int intStartNew;

if (ViewState["vwStateNew"] == null)
{
intStartNew = 0;
}
else
{
intStartNew = Convert.ToInt32(ViewState["vwStateNew"]) + 1;
}

if (intStartNew >= dvStatus.Count)
{
intStartNew = 0;
}
#endregion

for (int intCounter = intStartNew; intCounter < intStartNew + (intNumberOfRows / 2); intCounter++)
{
dtTemp.ImportRow((DataRow)dvStatus[intCounter].Row);

if (intCounter >= dvStatus.Count - 1)
{
intCounter = -1;
ViewState["vwStateNew"] = intCounter;
break;
}
ViewState["vwStateNew"] = intCounter;
}



// dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Status='C'";


if (isTenRecords == true && strCountryCode != "TGL")
{
if (strCompany != "")
{
dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Company='" + strCompany + "' and Status='C'";
}
else
{
dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Status='C'";
}
}
else
{
if (strCompany != "")
{
dvStatus.RowFilter = "Company='" + strCompany + "' and Status='C'";
}
else
{
dvStatus.RowFilter = "Status='C'";
}
}

#region "Logic for Ajax to shuffle the records-- Status as Closing"
int intStartClosing;

if (ViewState["vwStateClosing"] == null)
{
intStartClosing = 0;
}
else
{
intStartClosing = Convert.ToInt32(ViewState["vwStateClosing"]) + 1;
}

if (intStartClosing >= dvStatus.Count)
{
intStartClosing = 0;
}
#endregion

for (int intCounter = intStartClosing; intCounter < intStartClosing + (intNumberOfRows / 2); intCounter++)
{
dtTemp.ImportRow(dvStatus[intCounter].Row);

if (intCounter >= dvStatus.Count - 1)
{
intCounter = -1;
ViewState["vwStateClosing"] = intCounter;
break;
}

ViewState["vwStateClosing"] = intCounter;
}


}
#endregion

#region "Code to filter the records for the selected country if both the 'New' and 'Closing' auctions is less then 5 "
else if (intNewCount <= (intNumberOfRows / 2) && intCloseCount <= (intNumberOfRows / 2))
{
// dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Status='N'";
if (isTenRecords == true && strCountryCode != "TGL")
{
if (strCompany != "")
{
dvStatus.RowFilter = "CountryCode='" + strCountryCode + "'and Company='" + strCompany + "' and Status='N'";
}
else
{
dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Status='N'";
}
}
else
{
if (strCompany != "")
{
dvStatus.RowFilter = "Company='" + strCompany + "' and Status='N'";
}
else
{
dvStatus.RowFilter = "Status='N'";
}
}


for (int intCounter = 0; intCounter < dvStatus.Count; intCounter++)
{
dtTemp.ImportRow(dvStatus[intCounter].Row);
}


// dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Status='C'";
if (isTenRecords == true && strCountryCode != "TGL")
{
if (strCompany != "")
{
dvStatus.RowFilter = "CountryCode='" + strCountryCode + "'and Company='" + strCompany + "' and Status='C'";
}
else
{
dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Status='C'";
}

}
else
{
if (strCompany != "")
{
dvStatus.RowFilter = "Company='" + strCompany + "' and Status='C'";
}
else
{
dvStatus.RowFilter = "Status='C'";
}
}

for (int intCounter = 0; intCounter < dvStatus.Count; intCounter++)
{
dtTemp.ImportRow(dvStatus[intCounter].Row);
}
}
#endregion

#region "Code to filter the records for the selected country if the 'New' auctions is less then 5 and closing auction is greater then 5 "

else if (intNewCount <= (intNumberOfRows / 2) && intCloseCount >= (intNumberOfRows / 2))
{
// dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Status='N'";
if (isTenRecords == true && strCountryCode != "TGL")
{
if (strCompany != "")
{
dvStatus.RowFilter = "CountryCode='" + strCountryCode + "'and Company='" + strCompany + "' and Status='N'";
}
else
{
dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Status='N'";
}

}
else
{
if (strCompany != "")
{
dvStatus.RowFilter = "Company='" + strCompany + "' and Status='N'";
}
else
{
dvStatus.RowFilter = "Status='N'";
}
}


for (int intCounter = 0; intCounter < dvStatus.Count; intCounter++)
{
dtTemp.ImportRow(dvStatus[intCounter].Row);

}

// dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Status='C'";

if (isTenRecords == true && strCountryCode != "TGL")
{
if (strCompany != "")
{
dvStatus.RowFilter = "CountryCode='" + strCountryCode + "'and Company='" + strCompany + "' and Status='C'";
}
else
{
dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Status='C'";
}

}
else
{
if (strCompany != "")
{
dvStatus.RowFilter = "Company='" + strCompany + "' and Status='C'";
}
else
{
dvStatus.RowFilter = "Status='C'";
}
}

#region "Logic for Ajax to shuffle the records-- Status as Closing"
int intStartClosing;

if (ViewState["vwStateClosing"] == null)
{
intStartClosing = 0;
}
else
{
intStartClosing = Convert.ToInt32(ViewState["vwStateClosing"]) + 1;
}

if (intStartClosing >= dvStatus.Count)
{
intStartClosing = 0;
}
#endregion


for (int intCounter = intStartClosing; intCounter < (intNumberOfRows + intStartClosing - intNewCount) && intCounter < dvStatus.Count; intCounter++)
{
dtTemp.ImportRow(dvStatus[intCounter].Row);

if (intCounter >= dvStatus.Count - 1)
{
intCounter = -1;
ViewState["vwStateClosing"] = intCounter;
break;
}

ViewState["vwStateClosing"] = intCounter;

}


}
#endregion

#region "Code to filter the records for the selected country if the 'New' auction is greater then 5 and 'Closing' auctions is less then 5 "
else if (intNewCount >= (intNumberOfRows / 2) && intCloseCount <= (intNumberOfRows / 2))
{
// dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Status='N'";
if (isTenRecords == true && strCountryCode != "TGL")
{
if (strCompany != "")
{
dvStatus.RowFilter = "CountryCode='" + strCountryCode + "'and Company='" + strCompany + "' and Status='N'";
}
else
{
dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Status='N'";
}
}
else
{
if (strCompany != "")
{
dvStatus.RowFilter = "Company='" + strCompany + "' and Status='N'";
}
else
{
dvStatus.RowFilter = "Status='N'";
}
}

#region "Logic for Ajax to shuffle the records-- Status as New "
int intStartNew;

if (ViewState["vwStateNew"] == null)
{
intStartNew = 0;
}
else
{
intStartNew = Convert.ToInt32(ViewState["vwStateNew"]) + 1;
}

if (intStartNew >= dvStatus.Count)
{
intStartNew = 0;
}
#endregion


for (int intCounter = intStartNew; intCounter < (intNumberOfRows + intStartNew - intCloseCount) && intCounter < dvStatus.Count; intCounter++)
{
dtTemp.ImportRow(dvStatus[intCounter].Row);

if (intCounter >= dvStatus.Count - 1)
{
intCounter = -1;
ViewState["vwStateClosing"] = intCounter;
break;
}
ViewState["vwStateClosing"] = intCounter;

}

// dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Status='C'";
if (isTenRecords == true && strCountryCode != "TGL")
{
if (strCompany != "")
{
dvStatus.RowFilter = "CountryCode='" + strCountryCode + "'and Company='" + strCompany + "' and Status='C'";
}
else
{
dvStatus.RowFilter = "CountryCode='" + strCountryCode + "' and Status='C'";
}
}
else
{
if (strCompany != "")
{
dvStatus.RowFilter = "Company='" + strCompany + "' and Status='C'";
}
else
{
dvStatus.RowFilter = "Status='C'";
}
}


for (int intCounter = 0; intCounter < dvStatus.Count; intCounter++)
{
dtTemp.ImportRow(dvStatus[intCounter].Row);
// dtTemp.AcceptChanges();
}

}
#endregion

// Code to Filter the Records
wdgrCurrentAuctions.DataSource = dtTemp;
wdgrCurrentAuctions.DataBind();
}
#endregion

#region "ItemDataBound event of the datagrid"
protected void wdgrCurrentAuctions_ItemDataBound(object sender, DataGridItemEventArgs e)
{
try
{
string strDislayText = string.Empty;
string strStatus = string.Empty;

if (e.Item.ItemIndex < 0) { }
else
{
strDislayText = dtTemp.Rows[e.Item.ItemIndex]["Company"].ToString();
strStatus = dtTemp.Rows[e.Item.ItemIndex]["Status"].ToString();

HyperLink whyprlnkCurrentAuction = (HyperLink)e.Item.FindControl("wlnkCompany");
HyperLink whyprlnkCurrentStatus = (HyperLink)e.Item.FindControl("wlnkStatus");
Image wimgCurrentStatus = (Image)e.Item.FindControl("wimgStatus");
whyprlnkCurrentAuction.NavigateUrl = ConfigurationManager.AppSettings["AuctionUrl"].ToString().Replace("[AID]", dtTemp.Rows[e.Item.ItemIndex]["AuctionHeaderId"].ToString());
whyprlnkCurrentAuction.ToolTip = dtTemp.Rows[e.Item.ItemIndex]["AuctionHeaderId"].ToString();

whyprlnkCurrentAuction.Text = strDislayText;
if (strStatus == "N")
{
wimgCurrentStatus.ImageUrl = "/Images/NewStatus.gif";
}
else
{
wimgCurrentStatus.ImageUrl = "/Images/CloseStatus.gif";
}
}
}
catch (Exception ex)
{
objErrorHandler.LogError(ex, false);
}
}
#endregion

#region "Function to Set Language Specific Header Text"
protected void SetLanguageSpecHeaderText(string strSiteName)
{
DataSet dsLanguage = new DataSet();
dsLanguage.ReadXml(ConfigurationManager.AppSettings["pathLanguageFile"].ToString());
DataView dvLanguage = dsLanguage.Tables[0].DefaultView;
dvLanguage.RowFilter = "id='wlblSellersOpportunities'";
if (dvLanguage.Count > 0)
{
wlblSellersOpportunities.Text = dvLanguage[0][strSiteName].ToString();
}
dvLanguage.RowFilter = "id='wlblCurrentAuctions'";
if (dvLanguage.Count > 0)
{
if (Request.Cookies["LoginCookie"] == null)
{
wlblCurrentAuctions.Text = dvLanguage[0][strSiteName].ToString();
wtxtAuctionCaption.Text = dvLanguage[0][strSiteName].ToString();
}


}
dvLanguage.RowFilter = "id='wlblClosing'";
if (dvLanguage.Count > 0)
{
wlblClosing.Text = dvLanguage[0][strSiteName].ToString();
}
dvLanguage.RowFilter = "id='wlblNew'";
if (dvLanguage.Count > 0)
{
wlblNew.Text = dvLanguage[0][strSiteName].ToString();
}

#region "START: For Div Popup"

dvLanguage.RowFilter = "id='wlblAuctionInfo'";
if (dvLanguage.Count > 0)
{
wlblAuctionInfo.Text = dvLanguage[0][strSiteName].ToString();
}

dvLanguage.RowFilter = "id='wlblMsgAucPlease'";
if (dvLanguage.Count > 0)
{
wlblMsgAucPlease.Text = dvLanguage[0][strSiteName].ToString();
}
dvLanguage.RowFilter = "id='hyplnkAucSignIn'";
if (dvLanguage.Count > 0)
{
hyplnkAucSignIn.Text = dvLanguage[0][strSiteName].ToString();
}
dvLanguage.RowFilter = "id='wlblMsgAucConfig'";
if (dvLanguage.Count > 0)
{
wlblMsgAucConfig.Text = dvLanguage[0][strSiteName].ToString();
}
dvLanguage.RowFilter = "id='wlblAucSignUp1'";
if (dvLanguage.Count > 0)
{
wlblAucSignUp1.Text = dvLanguage[0][strSiteName].ToString();
}
dvLanguage.RowFilter = "id='hyplnkAucSignUp'";
if (dvLanguage.Count > 0)
{
hyplnkAucSignUp.Text = dvLanguage[0][strSiteName].ToString();
}
dvLanguage.RowFilter = "id='wlblAucSignUp2'";
if (dvLanguage.Count > 0)
{
wlblAucSignUp2.Text = dvLanguage[0][strSiteName].ToString();
}

#endregion

}
#endregion

#region "Timer Tick event"
protected void tmrCurrentAuctions_Tick(object sender, EventArgs e)
{
// wlblMessage.Text = DateTime.Now.ToString();
LoadAuctionsData();
}
#endregion

#region "Edit Button Click for Personalization settings"
protected void wlnkEditAuctions_Click(object sender, EventArgs e)
{

}
#endregion

#region "Method to populate the No Of Days"
protected void PopulateNoOfDays()
{
wddlistAuctionsNo.Items.Add(new ListItem("Default", "10"));
wddlistAuctionsNo.Items.Add(new ListItem("6", "6"));
wddlistAuctionsNo.Items.Add(new ListItem("12", "12"));
wddlistAuctionsNo.Items.Add(new ListItem("18", "18"));
wddlistAuctionsNo.Items.Add(new ListItem("24", "24"));
}
#endregion

#region "Method to Populate the Company List"
protected DataSet PopulateCompany()
{
DataSet dsCompany = new DataSet();
dsCompany = objCurrentAuctions.GetCompanyData();
return dsCompany;

}
#endregion

#region "Method to populate the Country"
protected DataSet PopulateCountry()
{
DataSet dsCountry = new DataSet();
dsCountry = objCurrentAuctions.GetCountry();
return dsCountry;
}
#endregion

#region "Submit Button Method"
protected void wlnkbtnSubmit_Click(object sender, EventArgs e)
{
// tmrCurrentAuctions.Enabled = true;
// divAuctions.Visible = false;
divAuctions.Style.Add("visibility", "hidden");

//wlnkEditAuctions.Attributes.Add("disabled", "false");
wlnkEditAuctions.Enabled = true;


#region "Getting the Site Language"
string strSiteName = "Tejari";
// string strSiteName = objUtility.GetLang();

if (strSiteName == "Tejari")
{
intSiteLang = 0;
}
else if (strSiteName == "Arabic")
{
intSiteLang = 1;
}
else if (strSiteName == "Chinese")
{
intSiteLang = 2;
}
#endregion


// Assign the values to the variables

/*START: Commented for Testing purpose */
HttpCookie objCookie = Request.Cookies.Get("LoginCookie");
strUserID = objCookie.Values["ID"].ToString();
intUserID = objCurrentAuctions.GetUserID(strUserID);

int intUID = intUserID;

/*START: Commented for Testing purpose */
//int intUID = 0;

int intRecCount = Convert.ToInt32(wddlistAuctionsNo.SelectedItem.Value);
string strCountry = wddlistAuctionsCountry.SelectedItem.Value.ToString();
string strComp = wddlistCompany.SelectedItem.Value.ToString();
string strWPTitle=wtxtAuctionCaption.Text;

int intInsertSucc = objCurrentAuctions.InsertCustomizationInfo(intUID, "SCA", intRecCount, strCountry, strComp, intSiteLang, strWPTitle);

if (intInsertSucc == 1)
{
// wlblMsgAucPlease.Text = "Customization Successfull";
}

ViewState["vwStateNew"] = null;
ViewState["vwStateClosing"] = null;

}
#endregion

#region "Code to roll back to the default settings of the webpart"
protected void wlnkbtnDefaultSettings_Click(object sender, EventArgs e)
{
divAuctions.Style.Add("visibility", "hidden");
wlnkEditAuctions.Enabled = true;
ViewState["vwAuctionsDefautSettings"] = 1;
LoadAuctionsData();
}
#endregion

#region "Code for the Asynchronous timer loading drop down controls"
protected void tmrAsychrAuctions_Tick(object sender, EventArgs e)
{

// wlblMsgAucPlease.Text = "";
//divAuctions.Style.Add("visibility", "hidden");
// string strSiteName = "Tejari";
// string strSiteName = objUtility.GetLang();
// SetLanguageSpecHeaderText(strSiteName);


#region "Logic for Personalization of Webpart"
//START: Logic to check the Personalization settings of the user for this webpart
//clsAuctionsMiddleTier objMyAuctions = new clsAuctionsMiddleTier();


// Getting the UserID for the current logged In user.
if (Request.Cookies["LoginCookie"] != null)
{
wlblAuctionCountry.Enabled = true;
wddlistAuctionsCountry.Enabled = true;
wlblCompany.Enabled = true;
wddlistCompany.Enabled = true;
wlblAuctionsNo.Enabled = true;
wddlistAuctionsNo.Enabled = true;
wlnkbtnSubmit.Enabled = true;
wlblAuctionCaption.Enabled = true;
wtxtAuctionCaption.Enabled = true;
wlnkbtnDefaultSettings.Enabled = true;

/* START: Commneted for Testing in the Local Project */
HttpCookie objCookie = Request.Cookies.Get("LoginCookie");
strUserID = objCookie.Values["ID"].ToString();

intUserID = objCurrentAuctions.GetUserID(strUserID);

/* END: Commneted for Testing in the Local Project */

//intUserID = 0;

DataSet dsCustomizationInfo = null;

if (Session["sessUserCustomizationInfo"] != null)
{
dsCustomizationInfo = (DataSet)Session["sessUserCustomizationInfo"];
}
DataView dvCustomizationInfo = new DataView();

dvCustomizationInfo = (DataView)dsCustomizationInfo.Tables[0].DefaultView;
dvCustomizationInfo.RowFilter = "Type='" + "SCA" + "'";

if (dvCustomizationInfo.Count > 0)
{
strCountryCode = dvCustomizationInfo[0].Row["CountryCode"].ToString();
intNumberOfRows = Convert.ToInt32(dvCustomizationInfo[0].Row["TotalRec"].ToString());
strCompany = dvCustomizationInfo[0].Row["Company"].ToString();

if (strCountryCode != "TGL" && strCountryCode != "")
{
// wddlistAuctionsCountry.Items.FindByValue(strCountryCode).Selected = true;
}

if (strCompany != "")
{
// wddlistCompany.Items.FindByValue(strCompany).Selected = true;
}

}

}
else
{
wlblAuctionCountry.Enabled = false;
wddlistAuctionsCountry.Enabled = false;
wlblCompany.Enabled = false;
wddlistCompany.Enabled = false;
wlblAuctionsNo.Enabled = false;
wddlistAuctionsNo.Enabled = false;
wlnkbtnSubmit.Enabled = false;
wlblAuctionCaption.Enabled = false;
wtxtAuctionCaption.Enabled = false;
wlnkbtnDefaultSettings.Enabled = false;
// SetLanguageSpecHeaderText(strSiteName);
//wlblMsgAucPlease.Text = "Please login to configure...";
}



#endregion
tmrAsychr.Enabled = false;


}
#endregion

#region "Method to asign the links urls to the div htperlinks"
protected void AssignUrlDivLinks()
{
// wlblMsgAucPlease.Text = "";
//divAuctions.Style.Add("visibility", "hidden");
string strSiteName = "Tejari";
// string strSiteName = objUtility.GetLang();

if (strSiteName == "Tejari")
{
//wlblAuctionInfo.Text = ConfigurationManager.AppSettings["AuctionInfoEng"].ToString();

hyplnkAucSignIn.NavigateUrl = "/Tejari/Membership/Login.aspx?PID=91";
hyplnkAucSignUp.NavigateUrl = "/Tejari/MemberShip/AlertRegistration.aspx?PID=68";
}
else if (strSiteName == "Arabic")
{
// wlblAuctionInfo.Text = ConfigurationManager.AppSettings["AuctionInfoArabic"].ToString();
hyplnkAucSignIn.NavigateUrl = "/Tejari/Membership/Login.aspx?PID=91";
hyplnkAucSignUp.NavigateUrl = "/Tejari/MemberShip/AlertRegistration.aspx?PID=68";
}
else if (strSiteName == "Chinese")
{
// wlblAuctionInfo.Text = ConfigurationManager.AppSettings["AuctionInfoChinese"].ToString();
hyplnkAucSignIn.NavigateUrl = "/Tejari/Membership/Login.aspx?PID=91";
hyplnkAucSignUp.NavigateUrl = "/Tejari/MemberShip/AlertRegistration.aspx?PID=68";
}
}
#endregion

}
}

Ajax Webpart User Control Design Code

<%@ Control Language="C#" AutoEventWireup="true" Codebehind="UCAuctions.ascx.cs"
Inherits="AuctionsWP.UCAuctions" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>




dir="ltr">






















Text="Seller Opportunities" ForeColor="#002A5C">  








  
AlternateText="Tejari" />
       
ForeColor="white" OnClick="wlnkEditAuctions_Click">





























 

class="HandCursor" />































































ForeColor="#CE712B" OnClick="wlnkbtnSubmit_Click">
















Font-Overline="false" Font-Bold="true" ForeColor="#CE712B" OnClick="wlnkbtnDefaultSettings_Click">



















Closed Status 


New Status 





AutoGenerateColumns="false" Width="100%" CellPadding="4" GridLines="Horizontal"
BorderStyle="Double" BorderColor="#D8DFE7" BorderWidth="1px" OnItemDataBound="wdgrCurrentAuctions_ItemDataBound"
ShowHeader="False">















OnTick="tmrCurrentAuctions_Tick">




Prev project Web Config