Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a datalist with images alongwith a button control 'addtocart' within item template.
In order to stop image flickering, I have put this button alone inside update panel.
When I click this 'addtocart' button , I want 'button Checkout' to be enabled true.
This 'Checkout' button is inside footer template of that datalist. The problem is that the 'checkout' button is not getting enabled. Please guide me.

XML
<asp:UpdatePanel ID="dd" runat="server"  >
   <ContentTemplate>
         <asp:Button ID="AddToCart"  runat = "server" Text='Add to Cart'   BackColor="DarkSlateBlue" Width="100px"  Style=" font-family:Arial" ForeColor="White" commandname="myevent">
    </asp:Button>
    </ContentTemplate>
    </asp:UpdatePanel>
    </p>
    </td>
    </tr>
    </table>
    </ItemTemplate>
<FooterStyle  BackColor="AliceBlue"  />
<FooterTemplate>
<br />
    <asp:Button ID="BtnCheckOut"  runat = "server" Text='Checkout'   Enabled="false"
    Width="100px"  onclick="CheckOutBtn_Click" style="z-index: 1; width:80px;cursor:pointer;
    margin-left:350px ; font-family:Arial;  text-align:center; height:22px;  font-weight:600; " > </asp:Button>
<br />



C#
public void dl_item_command(Object sender, DataListCommandEventArgs e)
  {
      if (e.CommandName == "myevent") // check commandname here
      {
          v_FirstSessionTag = "*";
          Session["FirstSessionTag"] = v_FirstSessionTag;
          Button CheckOutBtn = (Button)DataList1.Controls[DataList1.Controls.Count - 1].FindControl("BtnCheckOut");
          CheckOutBtn.Enabled = true;
Posted
Comments
Ahmed Bensaid 17-Feb-14 11:09am    
Try dd.FindControl("BtnCheckOut") ...

1 solution

C#
Button CheckOutBtn = dd.FindControl("BtnCheckOut") as Button;
CheckOutBtn.Enabled = true;

Or else try to put breakpoint and see what is actually happening over there.

-KR
 
Share this answer
 
Comments
S.Rajendran from Coimbatore 17-Feb-14 11:22am    
When I use your code, I get error at line 'dd.FindControl' stating that 'cannot use local variable before it is declared'
Krunal Rohit 17-Feb-14 11:24am    
Have you tried breakpoints ?
-KR
S.Rajendran from Coimbatore 18-Feb-14 11:32am    
I put breakpoint. It enters 'if(e.CommandName=Myevent..) and also crosses ChkButton.Enabled=true;', but enabled true is not happenning.
S.Rajendran from Coimbatore 17-Feb-14 11:27am    
If I use :
Button CheckOutBtn = (Button)DataList1.Controls[DataList1.Controls.Count - 1].FindControl("BtnCheckOut");
CheckOutBtn.Enabled = true;
i get no error but the 'BtnCheckOut' is not getting enabled.
Krunal Rohit 17-Feb-14 11:30am    
Okay it seems that page is posting back.
so try this,
if(!IsPostBack)
{
Button CheckOutBtn = (Button)DataList1.Controls[DataList1.Controls.Count - 1].FindControl("BtnCheckOut");
CheckOutBtn.Enabled = true;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900