Hi Shiva,
Thanks for ur relpy..
Now I'm using user control page(.ascx) as webpart in sharepoint. When I use the my code there. same problem is there..
Only one time button is clilcked after that no other button is click able...
i'm sending u code .. its a big one..
Not even the Drop down is doing post back.
Its working fine when tested on visual studio .... but when used as web part problem is cuming..
Please help me...
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 WebServiceNewBusiness;
using System.Collections.Generic;
using HarleysvilleLife.BenefitsPlatformValueObjects;
using HarleysvilleLife.NewBusiness;
using System.IO;
using System.Drawing.Imaging;
using System.Diagnostics;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.xml;
using System.Text;
public partial class WebUserControlNew : System.Web.UI.UserControl
{
List<HarleysvilleLife.BenefitsPlatformValueObjects.cVOPoliciesCertificate> objListVOPoliciesCertificate;
WebServiceNewBusiness.cVOPoliciesCertificate[] objListVOPoliciesCertificateWeb;
WebServiceNewBusiness.BenefitsPlatformNewBusiness objWebService ;
//HarleysvilleLife.NewBusiness.cBOPoliciesandCertificate objBOPoliciesandCertificate;
WebServiceNewBusiness.cVOPoliciesCertificate[] objListVOPoliciesCertificateProductWeb;
WebServiceNewBusiness.cVOPoliciesCertificate[] objListVOPoliciesCertificateClassesWeb;
String UserADID;
String Role;
protected void Page_Load(object sender, EventArgs e)
{
UserADID = @"puneodc\278145";
Role = "employer";
//UserADID = SPContext.Current.Web.CurrentUser.LoginName.ToString();
//Role = SPContext.Current.Web.CurrentUser.Groups[0].Name.ToString();
try
{
if (!IsPostBack)
{
//Get the detail for Policy & Certificate
objListVOPoliciesCertificate= new List<HarleysvilleLife.BenefitsPlatformValueObjects.cVOPoliciesCertificate>();
objListVOPoliciesCertificateWeb =new WebServiceNewBusiness.cVOPoliciesCertificate[1000];
//objBOPoliciesandCertificate = new HarleysvilleLife.NewBusiness.cBOPoliciesandCertificate();
//objListVOPoliciesCertificate = objBOPoliciesandCertificate.GetpoliciesandCertificateListforEmployer(@"PUNEODC/281330", "887");
objWebService = new BenefitsPlatformNewBusiness();
objListVOPoliciesCertificateWeb = objWebService.GetpoliciesandCertificateListforEmployer(UserADID, Role);
gdPolicyCertificateAll.DataSource = objListVOPoliciesCertificateWeb;
gdPolicyCertificateAll.DataBind();
// Session["PoliciesCertificate"] = objListVOPoliciesCertificate;
}
invisibleErrorMsg();
//else
//{
// if (Session["PoliciesCertificate"] != null)
// objListVOPoliciesCertificate = (List<HarleysvilleLife.BenefitsPlatformValueObjects.cVOPoliciesCertificate>)Session["PoliciesCertificate"];
//}
}
catch (Exception ex)
{
showError(ex.Message);
}
}
public void AddDefaultInDrp(DropDownList drp)
{
try
{
System.Web.UI.WebControls.ListItem ltDefault = new System.Web.UI.WebControls.ListItem();
ltDefault.Value = "-1";
ltDefault.Text = "Select";
drp.Items.Insert(0, ltDefault);
drp.SelectedValue = "-1";
}
catch (Exception ex)
{
showError(ex.Message);
}
}
private void Call_Web_Service_Method(int CurrentIndex)
{
string grpNumber;
string fpassword = "W5LGB3N";
string fuserName = "WSLGBEN";
string fDrawer = "LIFG";
Int32 fPackageType = 2004500;
int DocId = 39;
int pageNumber = -1;
string ftempDin ="";
Label lbl = (Label)gdPolicyCertificateAll.Rows[CurrentIndex].FindControl("lblGrpNumber");
if (lbl != null)
grpNumber = lbl.Text;
try
{
//// Creating object of Imageright webservices
//as73imgrttst01.IRWebService CallWebService = new as73imgrttst01.IRWebService();
//// Calling GetPages web method.
//as73imgrttst01.IRPage[] ArrayOfIRPages = CallWebService.GetPages(fuserName, fpassword, fDrawer, grpNumber, DocId, pageNumber, ftempDin);
////Calling GetMultiPagePdf web method and passing output of GetPages as a parameter
//byte[] PdfDocument = CallWebService.GetMultiPagePdf(fuserName, fpassword, ArrayOfIRPages, true, true);
//long pdflength = PdfDocument.Length;
//// Storing Multipage pdf in a memory stream
//System.IO.MemoryStream streamPDF = new System.IO.MemoryStream(PdfDocument, true);
//long fileLength = streamPDF.Length;
//byte[] Buffer = new byte[(int)fileLength];
//// Reading from buffer
//streamPDF.Read(Buffer, 0, (int)fileLength);
//streamPDF.Close();
//Response.ContentType = "application/pdf";
//Response.AddHeader("content-disposition", "attachment;filename=Temp.pdf");
//Response.BinaryWrite(Buffer);
//Response.Flush();
//Response.End();
OpenPDF();
}
catch (Exception ex)
{
showError(ex.Message);
}
}
void OpenPDF()
{
try
{
string filename = @"D:\Blue hills.JPG";
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
// Create a byte array of file stream length
byte[] ImageData = new byte[fs.Length];
//Read block of bytes from stream into the byte array
fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length));
//Close the File Stream
fs.Close();
MemoryStream m = new MemoryStream();
Document document = new Document();
Response.ContentType = "application/pdf";
PdfWriter writer = PdfWriter.GetInstance(document, m);
writer.CloseStream = false;
document.Open();
PdfContentByte cb = writer.DirectContent;
//bm.SelectActiveFrame(FrameDimension.Page, k);
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(ImageData);
img.ScalePercent(72f / 200f * 100);
img.SetAbsolutePosition(50, 50);
cb.AddImage(img);
document.NewPage();
document.Close();
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=ExportTest.pdf");
Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length);
Response.OutputStream.Flush();
Response.OutputStream.Close();
Response.Flush();
//Response.Close();
Response.End();
// Response.Clear();
m.Close();
}
catch(Exception ex)
{
showError(ex.Message);
}
}
protected void imgBtnPolicy_Click(object sender, ImageClickEventArgs e)
{
try
{
int CurrentIndex = ((System.Web.UI.WebControls.GridViewRow)(((System.Web.UI.WebControls.Image)(sender)).Parent.Parent)).RowIndex;
Session["CurrentIndex"] = CurrentIndex;
string cProductID = getProductID(gdPolicyCertificateAll.Rows[CurrentIndex],"Policy");
//string cProductID = (((DropDownList)gdPolicyCertificateAll.Rows[CurrentIndex].FindControl("drpViewCertificate")).SelectedValue).ToString();
if (cProductID == "-1")
{
showError("Please Select Product Catagory "); ;
}
else
{
Call_Web_Service_Method(CurrentIndex);
//((ImageButton)sender).PostBackUrl = "Defalt.aspx?NEW=2";
// Server.Transfer("Default.aspx?NEW=2");
}
}
catch (Exception ex)
{
showError(ex.Message);
}
}
string getProductID(GridViewRow gdRow,string Event)
{
try
{
if (Event == "Certificate")
{
if (((DropDownList)gdRow.FindControl("drpViewCertificate")).Items.Count > 0)
{
// if (Session["DrpOrLbl"].ToString() == "Drp")
return (((DropDownList)gdRow.FindControl("drpViewCertificate")).SelectedValue).ToString();
}
else
return (((Label)gdRow.FindControl("lblViewCertificateID")).Text).ToString();
}
else if (Event == "Policy")
{
if (((DropDownList)gdRow.FindControl("drpViewPolicy")).Items.Count > 0)
{
// if (Session["DrpOrLbl"].ToString() == "Drp")
return (((DropDownList)gdRow.FindControl("drpViewPolicy")).SelectedValue).ToString();
}
else
return (((Label)gdRow.FindControl("lblViewPolicyID")).Text).ToString();
}
else
return "";
}
catch (Exception ex)
{
showError(ex.Message);
return null;
}
}
protected void imgBtnCertificate_Click(object sender, ImageClickEventArgs e)
{
try
{
int CurrentIndex = ((System.Web.UI.WebControls.GridViewRow)(((System.Web.UI.WebControls.Image)(sender)).Parent.Parent)).RowIndex;
Session["CurrentIndex"] = CurrentIndex;
string cProductID = getProductID(gdPolicyCertificateAll.Rows[CurrentIndex],"Certificate");
//string cProductID = (((DropDownList)gdPolicyCertificateAll.Rows[CurrentIndex].FindControl("drpViewCertificate")).SelectedValue).ToString();
if (cProductID == "-1")
{
showError("Please Select Product Catagory "); ;
}
else
{
Wizard1.ActiveStepIndex = 1;
invisibleErrorMsg();
}
}
catch (Exception ex)
{
showError(ex.Message);
}
}
void invisibleErrorMsg()
{
lblError1.Visible = false;
lblError2.Visible = false;
lblError1.Text = "";
lblError2.Text = "";
}
protected void Wizard1_ActiveStepChanged(object sender, EventArgs e)
{
try
{
if (Wizard1.ActiveStepIndex == 1)
{
int index = gdPolicyCertificateAll.Rows.Count;
if (index != 0)
{
if (Session["CurrentIndex"] != null)
index = (int)Session["CurrentIndex"];
string cPlanID = (((Label)gdPolicyCertificateAll.Rows[index].FindControl("lblPlanID")).Text).ToString();
string cProductID = getProductID(gdPolicyCertificateAll.Rows[index],"Certificate");
//(((DropDownList)gdPolicyCertificateAll.Rows[index].FindControl("drpViewCertificate")).SelectedValue).ToString();
objWebService = new BenefitsPlatformNewBusiness();
objListVOPoliciesCertificateClassesWeb = objWebService.GetClassesAsPerProductCatagoryType(UserADID, Role, Convert.ToInt64(cPlanID), Convert.ToInt64(cProductID));
gdPolicyCertificateClasses.DataSource = objListVOPoliciesCertificateClassesWeb;
gdPolicyCertificateClasses.DataBind();
}
else
showError("There is no Policy & Certificate issued");
}
}
catch(Exception ex)
{
showError(ex.Message);
}
}
protected void gdPolicyCertificateAll_DataBound(object sender, EventArgs e)
{
GridView gd = (GridView)sender;
long PlanTypeID;
DropDownList drpPolicy;
DropDownList drpCertificate;
Label lblPolicy;
Label lblCertificate;
Label lblPolicyID;
Label lblCertificateID;
int i;
try
{
for(i=0;i<objListVOPoliciesCertificateWeb.Length;i++)
{
PlanTypeID = Convert.ToInt64( objListVOPoliciesCertificateWeb[i].PlanID);
//objListVOPoliciesCertificateProduct = new List<HarleysvilleLife.BenefitsPlatformValueObjects.cVOPoliciesCertificate>();
objListVOPoliciesCertificateProductWeb = new WebServiceNewBusiness.cVOPoliciesCertificate[1000];
//objListVOPoliciesCertificateProduct = objBOPoliciesandCertificate.GetProductNameListforEmployer(@"PUNEODC/281330", "887", PlanTypeID);
objListVOPoliciesCertificateProductWeb = objWebService.GetProductNameListforEmployer(UserADID, Role, PlanTypeID);
if (gd.Rows[i].FindControl("drpViewPolicy") != null && gd.Rows[i].FindControl("drpViewCertificate") != null)
{
drpPolicy = (DropDownList)gd.Rows[i].FindControl("drpViewPolicy");
drpCertificate = (DropDownList)gd.Rows[i].FindControl("drpViewCertificate");
lblPolicy = (Label)gd.Rows[i].FindControl("lblViewPolicy");
lblCertificate = (Label)gd.Rows[i].FindControl("lblViewCertificate");
lblPolicyID = (Label)gd.Rows[i].FindControl("lblViewPolicyID");
lblCertificateID = (Label)gd.Rows[i].FindControl("lblViewCertificateID");
if (objListVOPoliciesCertificateProductWeb.Length > 1)
{
drpPolicy.DataSource = objListVOPoliciesCertificateProductWeb;
drpPolicy.DataValueField = "ProductID";
drpPolicy.DataTextField = "ProductName";
drpPolicy.DataBind();
AddDefaultInDrp(drpPolicy);
drpCertificate.DataSource = objListVOPoliciesCertificateProductWeb;
drpCertificate.DataValueField = "ProductID";
drpCertificate.DataTextField = "ProductName";
drpCertificate.DataBind();
AddDefaultInDrp(drpCertificate);
lblPolicy.Visible = false;
lblCertificate.Visible = false;
}
else
{
drpPolicy.Visible = false;
drpCertificate.Visible = false;
lblPolicyID.Text = objListVOPoliciesCertificateProductWeb[0].ProductID;
lblCertificateID.Text = objListVOPoliciesCertificateProductWeb[0].ProductID;
lblCertificate.Text = objListVOPoliciesCertificateProductWeb[0].ProductName;
lblPolicy.Text = objListVOPoliciesCertificateProductWeb[0].ProductName;
}
}
}
}
catch (Exception ex)
{
showError(ex.Message);
}
}
protected void gdPolicyCertificateAll_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void lblSubGrpnumber_Click(object sender, EventArgs e)
{
try
{
int CurrentIndex = ((System.Web.UI.WebControls.GridViewRow)(((System.Web.UI.WebControls.Button)(sender)).Parent.Parent)).RowIndex;
Call_Web_Service_Method(CurrentIndex);
//((ImageButton)sender).PostBackUrl = "Defalt.aspx?NEW=2";
// Server.Transfer("Default.aspx?NEW=2");
}
catch (Exception ex)
{
showError(ex.Message);
}
}
void showError(string errMsg)
{
lblError1.Visible = true;
lblError2.Visible = true;
lblError1.Text = errMsg;
lblError2.Text = errMsg;
}
protected void drpViewPolicy_SelectedIndexChanged(object sender, EventArgs e)
{
if (((DropDownList)sender).SelectedIndex != -1)
invisibleErrorMsg();
}
protected void drpViewCertificate_SelectedIndexChanged(object sender, EventArgs e)
{
if (((DropDownList)sender).SelectedIndex != -1)
invisibleErrorMsg();
}
}