I'm stuck with this for more than two days. I have a table which has two columns. One has an update panel which contains a Grid and few other controls, the other column has a panel to which I' m adding an imagebutton dynamically. the imagebutton is correctly
added and the event fires too. My question is when the image button is posted back the update panel is getting refreshed. I do not know what is causing this. my update panel looks like this
Since you're using a Triggers collection in your UpdatePanel you should have the UpdateMode="Conditional". First try that and see if it fixes your problem.
Also, with your image posting back, since it is not in an UpdatePanel it will postback and update the entire page, thus refreshing your UpdatePanel.
Remember: mark posts that helped you as the answer to aid future readers
I tried update mode= "Conditional"It did not help. I put it back in the grid view which is in the Update panel. I' m trying this right now it still posts back when I click this checkbox Please help
foreach (DataRow dr in dt.Rows)
{
String s, m, r = "";
s = dr[0].ToString();
m = dr[1].ToString();
r = dr[2].ToString();
PrintLabels(s, m, r, printer);
}
Yes. When I debug the application soon after the checkbox is clicked it is going back to reload the images which is one of the columns in the Gridview. I have declared it autopostack is as false. Not able to fgure out what is causing it. I can you send you
my entire code if you wnated to look at it.
Thanks for your suggestion. I tried this on a sample page it worked. When I put it in the main page I' m using in the application it doesnt work. I have pasted my page can you please look into it and let me know what could be causing it.
Amulu
Member
118 Points
251 Posts
Update Panel
May 02, 2008 03:36 PM|LINK
Hello,
I'm stuck with this for more than two days. I have a table which has two columns. One has an update panel which contains a Grid and few other controls, the other column has a panel to which I' m adding an imagebutton dynamically. the imagebutton is correctly added and the event fires too. My question is when the image button is posted back the update panel is getting refreshed. I do not know what is causing this. my update panel looks like this<
asp:UpdatePanel ID="UpdatePanel1" runat="server" > <ContentTemplate>All the controls here
</
ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click" /> </Triggers>
</asp:UpdatePanel><td>
<Panel>
imagebutton control is added dynamically.
</Panel>
Please help!!
Thanks
Mythili
whatispunk
Contributor
4074 Points
876 Posts
Re: Update Panel
May 02, 2008 06:40 PM|LINK
Since you're using a Triggers collection in your UpdatePanel you should have the UpdateMode="Conditional". First try that and see if it fixes your problem.
Also, with your image posting back, since it is not in an UpdatePanel it will postback and update the entire page, thus refreshing your UpdatePanel.
Why UpdatePanels Are Dangerous
Why You Should Not Place Your Whole Site In An UpdatePanel
Amulu
Member
118 Points
251 Posts
Re: Update Panel
May 02, 2008 06:55 PM|LINK
I tried update mode= "Conditional"It did not help. I put it back in the grid view which is in the Update panel. I' m trying this right now it still posts back when I click this checkbox Please help
thanks
Mythili
<div dir=ltr align=left><asp:TemplateField><ItemTemplate></div> <div> </div> <div dir=ltr align=left><asp:CheckBox id="chkPrintLabel" runat="server" AutoPostBack="False"></asp:CheckBox></div> <div> </div> <div dir=ltr align=left> </div> <div> </div> <div dir=ltr align=left></ItemTemplate><HeaderTemplate>
<asp:ImageButton Id="imgPrint" runat="server" OnClick="imgPrint_Click" tooltip="Print" backcolor="transparent"
ImageURL="~/Images/Labelsmall.Gif" AutoPostBack="True" > </asp:ImageButton></div> <div> </div> <div dir=ltr align=left></HeaderTemplate>
</asp:TemplateField></div> <div> </div> <div dir=ltr align=left>
protected void imgPrint_Click(object sender, EventArgs e)
{
HyperLink hl = new HyperLink();
ImageButton btn = (ImageButton)sender;
try
{
foreach (GridViewRow gvr in gvSearchItems.Rows)
{
CheckBox cbSel = (CheckBox)gvr.FindControl("chkPrintLabel");
if (cbSel.Checked && printer>0)
{
int StyleID = (int)gvSearchItems.DataKeys[gvr.RowIndex].Value;</div> <div> </div> <div dir=ltr align=left> </div> <div> </div> <div dir=ltr align=left> DataTable dt = DAItem.SearchItemsLabels(StyleID);
foreach (DataRow dr in dt.Rows)
{
String s, m, r = "";
s = dr[0].ToString();
m = dr[1].ToString();
r = dr[2].ToString();
PrintLabels(s, m, r, printer);
}
}</div> <div> </div> <div dir=ltr align=left> }
}
catch
{</div> <div> </div> <div dir=ltr align=left>
}
}</div> <div dir=ltr align=left> </div>
whatispunk
Contributor
4074 Points
876 Posts
Re: Update Panel
May 02, 2008 08:33 PM|LINK
What is "it" referring to?
I don't see how that checkbox is causing a postback since you've explicitly declared AutoPostBack="'False".
Is that your question?
Me confused [:S]
Why UpdatePanels Are Dangerous
Why You Should Not Place Your Whole Site In An UpdatePanel
Amulu
Member
118 Points
251 Posts
Re: Update Panel
May 02, 2008 08:43 PM|LINK
Yes. When I debug the application soon after the checkbox is clicked it is going back to reload the images which is one of the columns in the Gridview. I have declared it autopostack is as false. Not able to fgure out what is causing it. I can you send you my entire code if you wnated to look at it.
Amulu
Member
118 Points
251 Posts
Re: Update Panel
May 02, 2008 08:47 PM|LINK
whatispunk
Contributor
4074 Points
876 Posts
Re: Update Panel
May 02, 2008 09:15 PM|LINK
Use this website
http://www.pastey.net/
to paste all your code in then post the resulting links to this thread.
Why UpdatePanels Are Dangerous
Why You Should Not Place Your Whole Site In An UpdatePanel
ferrymeidian...
Member
500 Points
126 Posts
Re: Update Panel
May 03, 2008 05:12 PM|LINK
HI Mythili,
Put your Panel (container of ImageButton) inside an UpdatePanel.
<asp:UpdatePanel ID="UpdatePanel2" runat="server" >
<ContentTemplate><asp:Panel>
imagebutton control is added dynamically.
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
It will solve the problem.
HTH
Ferry
Regards,
Ferry Meidianto
www.meidianto.com
Amulu
Member
118 Points
251 Posts
Re: Update Panel
May 05, 2008 12:32 AM|LINK
Hello i pasted the code for you. Please help.
I dont know if you need my code behind page also, I di not paste it there. Here it is
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 Roman.Data.DataAccess; using Roman.Data.BO; using System.Runtime.InteropServices; using Loftware.LLMControl; public partial class Development_SearchItems : System.Web.UI.Page { private string user = null; private int printer; public bool CheckItem { get { if (ViewState["CheckItem"] != null) return (bool)ViewState["CheckItem"]; else return false; } set { ViewState["CheckItem"] = value; } } protected void Page_Load(object sender, EventArgs e) { user = Membership.GetUser().ProviderUserKey.ToString(); printer = DAPrinter.GetPrinter(user); if (!IsPostBack) { ViewState["SortExpression"] = "FullStyleNum"; ViewState["SortDirection"] = "Asc"; ddlResultsPerPage.SelectedValue = Profile.ItemResutsPerPage.ToString(); LoadLookup(ddlMarketCode, 3); LoadLookup(ddlPresentation, 9); LoadCategory(ddlTheme, 1); LoadLookup(ddlStoneName, 15); LoadLookup(ddlDivision, 2); LoadLookup(ddlSampleStatus, 12); LoadLookup(ddlAddUOM, 11); foreach (ListItem li in ddlAddUOM.Items) { if (li.Text.Trim().ToLower() == "each") li.Selected = true; } LoadLookup(ddlAddMarketCode, 3); LoadVendors(); LoadUsers(); if (!Roman.PDS.Utility.VerifySecurity(eSecurity.AddProduct)) { pnlAddStyle.Visible = false; } if (!Roman.PDS.Utility.VerifySecurity(eSecurity.ViewProduct)) { Response.Redirect("~/Error.aspx?ErrorMessage=You do not have permission to view a style"); } if (!Roman.PDS.Utility.VerifySecurity(eSecurity.ViewProductCost)) { gvSearchItems.Columns[8].Visible = false; } if (!Roman.PDS.Utility.VerifySecurity(eSecurity.ViewProductPrice)) { gvSearchItems.Columns[7].Visible = false; } } } protected string GetImageThumb(string imageID) { return "~/ImageHandler.aspx?Thumbnail=1&ImageID=" + imageID; } protected string GetImage(string imageID) { return "~/ImageHandler.aspx?ImageID=" + imageID; } private void LoadUsers() { string[] designers = Roles.GetUsersInRole("attributeDesigner"); string[] merchandisers = Roles.GetUsersInRole("attributeMerchandiser"); ddlDesigners.Items.Clear(); ddlDesigners.Items.Add(new ListItem("", "")); foreach (string designer in designers) { ddlDesigners.Items.Add(new ListItem(designer, Membership.GetUser(designer).ProviderUserKey.ToString())); } ddlMerchandisers.Items.Clear(); ddlMerchandisers.Items.Add(new ListItem("", "")); foreach (string merchandiser in merchandisers) { ddlMerchandisers.Items.Add(new ListItem(merchandiser, Membership.GetUser(merchandiser).ProviderUserKey.ToString())); } } protected void gvSearchItems_RowEditing(object sender, GridViewEditEventArgs e) { Response.Redirect("EditItem.aspx"); } protected void btnSearch_Click(object sender, EventArgs e) { Search(); } private void LoadVendors() { DataTable dt = DAVendor.GetAllVendors(); ddlVendors.Items.Clear(); ddlVendors.Items.Add(new ListItem("", "0")); foreach (DataRow drow in dt.Rows) { ddlVendors.Items.Add(new ListItem(drow["Name"].ToString(), drow["VendorID"].ToString())); } } private void LoadCategory(DropDownList ddl, int catType) { System.Collections.Generic.List<Category> cats = DACategory.GetCategoriesByType(catType); ddl.Items.Clear(); ddl.Items.Add(new ListItem("", "0")); foreach (Category cat in cats) { ddl.Items.Add(new ListItem(cat.Name, cat.CategoryID.ToString())); } } private void LoadLookup(DropDownList ddl, int lookupType) { System.Collections.Generic.List<LookUp> lus = DALookUp.GetLookupsByType(lookupType); ddl.Items.Clear(); ddl.Items.Add(new ListItem("", "0")); foreach (LookUp lu in lus) { ddl.Items.Add(new ListItem(lu.Text, lu.LookUpID.ToString())); } } private void BindItems(DataView dt) { gvSearchItems.DataSource = dt; gvSearchItems.PageSize = Profile.ItemResutsPerPage; gvSearchItems.DataBind(); dlSearchItems.DataSource = dt; dlSearchItems.DataBind(); if (dt.Count > 0) { int from, to; from = Profile.ItemResutsPerPage * gvSearchItems.PageIndex + 1; if (from + Profile.ItemResutsPerPage - 1 > dt.Count) to = dt.Count; else to = from + Profile.ItemResutsPerPage - 1; lblResults.Text = from.ToString() + "-" + to.ToString() + " of " + dt.Count.ToString() + " Results"; lblResults.Visible = true; } else { lblResults.Visible = false; } } private void Search() { switch (RadioButtonList1.SelectedValue) { case "0": gvSearchItems.Columns[1].Visible = true; gvSearchItems.Visible = true; dlSearchItems.Visible = false; break; case "1": gvSearchItems.Columns[1].Visible = false; gvSearchItems.Visible = true; dlSearchItems.Visible = false; break; case "2": gvSearchItems.Visible = false; dlSearchItems.Visible = true; break; default: break; } DateTime from, to; decimal listFrom, listTo, firstFrom, firstTo; from = DateTime.Parse("1/1/1900"); if (txtFrom.Text != "" && !DateTime.TryParse(txtFrom.Text, out from)) { updSearchCriteria.Update(); txtFrom.Text = ""; } to = DateTime.MaxValue; if (txtTo.Text != "" && !DateTime.TryParse(txtTo.Text, out to)) { updSearchCriteria.Update(); txtTo.Text = ""; } listFrom = -1000; if (txtListFrom.Text != "" && !decimal.TryParse(txtListFrom.Text, out listFrom)) { updSearchCriteria.Update(); txtListFrom.Text = ""; } listTo = 999999; if (txtListTo.Text != "" && !decimal.TryParse(txtListTo.Text, out listTo)) { updSearchCriteria.Update(); txtListTo.Text = ""; } firstFrom = -1000; if (txtFirstFrom.Text != "" && !decimal.TryParse(txtFirstFrom.Text, out firstFrom)) { updSearchCriteria.Update(); txtFirstFrom.Text = ""; } firstTo = 999999; if (txtFirstTo.Text != "" && !decimal.TryParse(txtFirstTo.Text, out firstTo)) { updSearchCriteria.Update(); txtFirstTo.Text = ""; } int division = 0; int category = 0; int classVal = 0; int line = 0; int.TryParse(ddlDivision.SelectedValue, out division); int.TryParse(ddlCategory.SelectedValue, out category); int.TryParse(ddlClass.SelectedValue, out classVal); int.TryParse(ddlLine.SelectedValue, out line); DataTable dt = DAItem.SearchItems(txtDescription.Text, txtFullStyleNum.Text, int.Parse(ddlMarketCode.SelectedValue), division, category, classVal, line, ddlDesigners.SelectedValue, ddlMerchandisers.SelectedValue, int.Parse(ddlStoneName.SelectedValue), txtStoneName.Text, int.Parse(ddlPresentation.SelectedValue), int.Parse(ddlTheme.SelectedValue), int.Parse(ddlVendors.SelectedValue), int.Parse(ddlSampleStatus.SelectedValue), from, to, listFrom, listTo, firstFrom, firstTo, txtCustomerProposal.Text, txtPONum.Text); DataView dv = new DataView(dt); dv.Sort = string.Format("{0} {1}", ViewState["SortExpression"], ViewState["SortDirection"]); Profile.ItemResutsPerPage = int.Parse(ddlResultsPerPage.SelectedValue); BindItems(dv); } protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { Search(); } protected void btnCreateStyle_Click(object sender, EventArgs e) { decimal targetFirstCost = 0m; decimal.TryParse(txtAddTargetFirstCost.Text, out targetFirstCost); int itemID = DAItem.InsertItemNewBase(int.Parse(ddlAddDivision.SelectedValue), txtAddDescription.Text, txtAddDescription2.Text, int.Parse(ddlAddUOM.SelectedValue), targetFirstCost, int.Parse(ddlAddMarketCode.SelectedValue), int.Parse(ddlAddCategory.SelectedValue), int.Parse(ddlAddClass.SelectedValue), int.Parse(ddlAddLine.SelectedValue), cbSKUPlan.Checked, (Guid)Membership.GetUser().ProviderUserKey); MarketPlan mp = DAMarketPlan.GetMarketPlanByMarketCodeandDivision(int.Parse(ddlAddMarketCode.SelectedValue), int.Parse(ddlAddDivision.SelectedValue)); System.Collections.Generic.Dictionary<string, object> vals = new System.Collections.Generic.Dictionary<string, object>(); if (ddlAddDivision.SelectedItem.Text.Trim().ToLower() == "costume") vals.Add("CostingBaseSilver", 0); else vals.Add("CostingBaseSilver", 1); // Add market plan values if it exists decimal targetMargin = 0m; if (mp != null) { vals.Add("CostingSilverMarket", mp.ProjSilverCost); DataTable dtVolMar = DAVolMar.GetCategoriesByMarketPlan(mp.MarketPlanID); foreach (DataRow drow in dtVolMar.Rows) { if ((int.Parse(ddlAddCategory.SelectedValue) == (int)drow["CategoryID"] && (int)drow["ClassID"] == 0) || (int.Parse(ddlAddCategory.SelectedValue) == (int)drow["CategoryID"] && (int)drow["ClassID"] == int.Parse(ddlAddClass.SelectedValue))) { targetMargin = (decimal)drow["Margin"]; } } } vals.Add("TargetMargin", targetMargin); DAItem.UpdateItem(itemID, vals); Response.Redirect("EditItem.aspx?itemID=" + itemID.ToString()); } protected void ddlResultsPerPage_SelectedIndexChanged(object sender, EventArgs e) { gvSearchItems.PageIndex = 0; Search(); } protected void gvSearchItems_PageIndexChanged(object sender, EventArgs e) { } protected void gvSearchItems_PageIndexChanging(object sender, GridViewPageEventArgs e) { gvSearchItems.PageIndex = e.NewPageIndex; Search(); } protected void ddlDivision_SelectedIndexChanged(object sender, EventArgs e) { if (ddlDivision.SelectedValue == "0") { LoadCategory(ddlCategory, 4); LoadCategory(ddlClass, 7); LoadCategory(ddlLine, 2); ddlCategory.Enabled = false; ddlClass.Enabled = false; ddlLine.Enabled = false; } else { LookUp lu = DALookUp.GetLookup(int.Parse(ddlDivision.SelectedValue)); Roman.PDS.Utility.LoadCategory(ddlCategory, 4, "div" + lu.TypeValue.Trim()); ddlClass.SelectedValue = "0"; ddlLine.SelectedValue = "0"; ddlCategory.Enabled = true; ddlClass.Enabled = false; ddlLine.Enabled = false; } } protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e) { if (ddlCategory.SelectedValue == "0") { LoadCategory(ddlClass, 7); LoadCategory(ddlLine, 2); ddlClass.Enabled = false; ddlLine.Enabled = false; } else { Roman.PDS.Utility.LoadCategory(ddlClass, 7, ddlCategory.SelectedValue); ddlLine.SelectedValue = "0"; ddlClass.Enabled = true; ddlLine.Enabled = false; } } protected void ddlClass_SelectedIndexChanged(object sender, EventArgs e) { if (ddlClass.SelectedValue == "0") { LoadCategory(ddlLine, 2); ddlLine.Enabled = false; } else { Roman.PDS.Utility.LoadCategory(ddlLine, 2, ddlClass.SelectedValue); ddlLine.Enabled = true; } } protected void gvSearchItems_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (!Roman.PDS.Utility.VerifySecurity(eSecurity.AuditProduct)) { Panel pnl = (Panel)e.Row.Cells[0].FindControl("pnlAudit"); pnl.Visible = false; } //For printing labels if (Roman.PDS.Utility.VerifySecurity(eSecurity.PrintLabels) && printer > 0) { gvSearchItems.Columns[9].Visible =true; } if (Roman.PDS.Utility.VerifySecurity(eSecurity.PrintLabels) && printer <= 0) { gvSearchItems.Columns[9].Visible = false; } e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.gvSearchItems, "Select$" + e.Row.RowIndex); } } protected void imgPrint_Click(object sender, EventArgs e) { HyperLink hl = new HyperLink(); ImageButton btn = (ImageButton)sender; try { foreach (GridViewRow gvr in gvSearchItems.Rows) { CheckBox cbSel = (CheckBox)gvr.FindControl("chkPrintLabel"); if (cbSel.Checked && printer>0) { int StyleID = (int)gvSearchItems.DataKeys[gvr.RowIndex].Value; DataTable dt = DAItem.SearchItemsLabels(StyleID); foreach (DataRow dr in dt.Rows) { String s, m, r = ""; s = dr[0].ToString(); m = dr[1].ToString(); r = dr[2].ToString(); PrintLabels(s, m, r, printer); } } } } catch { } } protected void gvSearchItems_Sorting(object sender, GridViewSortEventArgs e) { if (ViewState["SortExpression"].ToString() == e.SortExpression) { ViewState["SortExpression"] = e.SortExpression; if (ViewState["SortDirection"].ToString().ToLower() == "desc") ViewState["SortDirection"] = "ASC"; else ViewState["SortDirection"] = "DESC"; } else { ViewState["SortExpression"] = e.SortExpression; if (e.SortDirection == SortDirection.Ascending) ViewState["SortDirection"] = "ASC"; else ViewState["SortDirection"] = "DESC"; } Search(); } private void PrintLabels(string style, string List, string Market, int printer) { Loftware.LLMControl.LoftClient CWebX1; CWebX1 = new Loftware.LLMControl.LoftClient(); try { CWebX1.Login("loftrf.tsiag.com", 2723); CWebX1.GetLabel("roman\\misc_labels\\marketsticker.lwl"); CWebX1.PrinterNumber = printer; CWebX1.SetData("mktcode", Market); CWebX1.SetData("style", style); CWebX1.SetData("retail", List); CWebX1.Quantity = 2; // int i = CWebX1.PrintJob(); } catch (Exception ex) { Label1.Text = ex.ToString(); } } }Thanks
Mythili
Amulu
Member
118 Points
251 Posts
Re: Update Panel
May 05, 2008 01:00 PM|LINK
Thanks for your suggestion. I tried this on a sample page it worked. When I put it in the main page I' m using in the application it doesnt work. I have pasted my page can you please look into it and let me know what could be causing it.
Thanks
Mythili