Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all,
Vanilla are planning an update to the site on April 24th (next Wednesday). It is a major PHP8 update which is expected to boost performance across the site. The site will be down from 7pm and it is expected to take about an hour to complete. We appreciate your patience during the update.
Thanks all.

C# shopping basket, trying to remove an item...

  • 07-04-2009 2:02pm
    #1
    Closed Accounts Posts: 7,097 ✭✭✭


    Hi all,

    I've built a shopping basket/cart that works great, it works by adding a record to my database on a Button_Click event, and I display the contents of the records in my DB (the contents of the shopping cart), by using the solution below. What it does is append a new record to a string, using a while loop, each time something is added to the basket, which works great.

    The only problem I have now is if someone wants to remove something from the cart, I've been pulling out my hair trying to come up with a solution for this that is consistent with the approach below. It should be easy as I have a unique key for this table so every record has a unique ID that can be identified/deleted but where I'm stuck is I can't work out how to put a button or a hyperlink inside my while loop and bind the behaviour of this event handler to the unique ID in my DB??? Is it possible to put a button or a hyperlink (that does something besides bring you to another page), inside a label and also inside a while loop???

    What I need is if I have 3 items in my cart, I need 3 buttons or something else like a hyperlink beside each item, to remove it from the cart or more accurately to remove it from my DB. The while loop just runs through the table when the purchase button is clicked and picks out any records that share the same SessionID.

    SqlDataReader DataReader;
    DataReader = cmdy.ExecuteReader();

    if (DataReader.HasRows)
    {
    Label13.Text = "";

    while (DataReader.Read())
    {
    object obj1 = new object();
    obj1 = string.Format(DataReader["eq_type"].ToString());

    object obj2 = new object();
    obj2 = string.Format(DataReader["eq_make"].ToString());

    object obj3 = new object();
    obj3 = string.Format(DataReader["eq_model"].ToString());

    object obj4 = new object();
    obj4 = string.Format(DataReader["Component_Manufacturer"].ToString());

    object obj5 = new object();
    obj5 = string.Format(DataReader["Product_Description"].ToString());

    object obj6 = new object();
    obj6 = string.Format(DataReader["Retail_Price"].ToString());

    object obj7 = new object();
    obj7 = string.Format(DataReader["Item_ID"].ToString());



    string newstring = string.Concat(obj1," " + obj2, " " + obj3, "<br>" + obj4, " " + obj5, "<br> <p1>Retail Price: € " + obj6);
    Label13.Text += string.Format(newstring.ToString() + "<br><br>");

    Label16.Text = string.Format("Shopping Cart: € {0}", Convert.ToString(cmdu.ExecuteScalar()));

    Label8.Text = string.Format("Shipping Cost: € {0:F2}", Convert.ToDecimal(Delivery));

    //string FullTotal = Convert.ToString(cmdu.ExecuteScalar()) + Convert.ToString(cmdL.ExecuteScalar());
    //Label9.Text = string.Format(FullTotal);

    decimal Cart = Convert.ToDecimal(cmdu.ExecuteScalar());
    decimal Carry = Convert.ToDecimal(Delivery);

    decimal Cart_Total = Cart + Carry;
    //Label9.Text = Cart_Total.ToString();
    Label9.Text = string.Format("Total Invoice: € {0:F2}", Cart_Total);

    Any help hugely appreciated!


«13456789

Comments

  • Registered Users Posts: 2,426 ✭✭✭LowOdour


    Have to say that im not really gone on the idea of storing records in a database that may not get used. It means you could be hitting the database with 100 different products that may never get purchased.
    But thats not your question!

    inside the while loop you could generate some html, which will spit out the code for a html button. You could add the id of the product while generating the html and also an onclick call which would pass the id as a parameter. Have a javascript call that when the button is clicked, it shows a dialog box informing of the delete. Hit the ok button, it calls a delete page that deletes the record and returns you to the page with the other products.
    string = "< input type=\"button\" id = \""+GetIDFromDBHere+"\" onclick ="\"+CallJavaScriptHereWithID+"\" />";

    Couple of things...this can definately be done simpler than ive explained it, but its a start for you. You may not need the extra delete form, its only if you want to inform the user.


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    LowOdour wrote: »
    Have to say that im not really gone on the idea of storing records in a database that may not get used. It means you could be hitting the database with 100 different products that may never get purchased.
    But thats not your question!

    inside the while loop you could generate some html, which will spit out the code for a html button. You could add the id of the product while generating the html and also an onclick call which would pass the id as a parameter. Have a javascript call that when the button is clicked, it shows a dialog box informing of the delete. Hit the ok button, it calls a delete page that deletes the record and returns you to the page with the other products.
    string = "< input type=\"button\" id = \""+GetIDFromDBHere+"\" onclick ="\"+CallJavaScriptHereWithID+"\" />";

    Couple of things...this can definately be done simpler than ive explained it, but its a start for you. You may not need the extra delete form, its only if you want to inform the user.

    Hi LowOdour,

    I don't think your solution can be used for my problem because the while loop is in a codebehind C# page, separate from the HTML code...


  • Registered Users Posts: 2,790 ✭✭✭John_Mc


    Darragh29 wrote: »
    Hi LowOdour,

    I don't think your solution can be used for my problem because the while loop is in a codebehind C# page, separate from the HTML code...

    Put a runat=server in the <input> tag and you can access the clientID property of the control in the codebehind.

    < input type=\"button\" id = \""+GetIDFromDBHere+"\" onclick ="\"+CallJavaScriptHereWithID+"\" runat="server" />

    In the while loop then you could set the onclick property of the input type:

    GetIDFromDBHere.onclick="functionName('" + GetIDFromDBHere.ClientID +"');";


  • Registered Users Posts: 2,790 ✭✭✭John_Mc


    Another alternative is to add an asp.net button in the while loop. You could set it's ID, CommandName and CommandArgument to whatever type of button it is.

    Should be a simple enough solution. For me at least, it'd be easier than using javascript and a seperate form as suggested above


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Ok, I've decided to use an asp.net LinkButton to get me over this last hurdle...

    Right now, I have my LinkButton in my aspx page, but where I'm stuck is actually getting my while loop to create a new instance of the button for each record in my DB. Can I create an instance of a LinkButton from my codebehind page??? If I can, I think I can crack this...


  • Advertisement
  • Registered Users Posts: 2,790 ✭✭✭John_Mc


    Darragh29 wrote: »
    Ok, I've decided to use an asp.net LinkButton to get me over this last hurdle...

    Right now, I have my LinkButton in my aspx page, but where I'm stuck is actually getting my while loop to create a new instance of the button for each record in my DB. Can I create an instance of a LinkButton from my codebehind page??? If I can, I think I can crack this...

    You can create pretty much add anything in the code behind :)

    I'm writing this without a compiler so you'll probably need to correct the case in some places:
    LinkButton lb = new LinkButton();
    lb.id="delete_cmd" + n; //n is your index for looping or just a counter
    lb.Text="Delete";
    lb.CommandName="Delete";
    lb.CommandArgument=nRowID;
    lb.OnClick="EventHandlerName";
    //lb.OnClientClick="";
    //Set any other properties here
    
    //Then add to a container such as a placeholder or panel
    CartPanel.Controls.Add(lb);
    

    I know that you're new to this so I'll save you some future headache and advise you to lookup the .net page life cycle. You'll have all sorts of problems with dynamically added controls if you dont fully grasp it.


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    John_Mc wrote: »
    You can create pretty much add anything in the code behind :)

    I'm writing this without a compiler so you'll probably need to correct the case in some places:
    LinkButton lb = new LinkButton();
    lb.id="delete_cmd" + n; //n is your index for looping or just a counter
    lb.Text="Delete";
    lb.CommandName="Delete";
    lb.CommandArgument=nRowID;
    lb.OnClick="EventHandlerName";
    //lb.OnClientClick="";
    //Set any other properties here
    
    //Then add to a container such as a placeholder or panel
    CartPanel.Controls.Add(lb);
    

    I know that you're new to this so I'll save you some future headache and advise you to lookup the .net page life cycle. You'll have all sorts of problems with dynamically added controls if you dont fully grasp it.

    Ya see here is my problem, I have to get the LinkButton into my Label that is appended above, or at least I think I do if I want to stick with my approach above... So I can't use a placeholder then I think??? I dunno!


  • Registered Users Posts: 2,790 ✭✭✭John_Mc


    Darragh29 wrote: »
    Ya see here is my problem, I have to get the LinkButton into my Label that is appended above, or at least I think I do if I want to stick with my approach above... So I can't use a placeholder then I think??? I dunno!

    Sorry, you've lost me here. Why do you need to insert into a Label?


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    John_Mc wrote: »
    Sorry, you've lost me here. Why do you need to insert into a Label?

    Thanks for sticking with me so far John... This is my problem here, I use an appended string to display the shopping cart contents back to the aspx page, and then I display the value of the appended string in a Label. What I'm trying to do is come up with some way of putting a LinkButton that will delete, into the appended string, that goes into the Label.

    If I can't do this, I think I'll have to go backwards and come up with another way of displaying the shopping cart contents in the aspx page. :confused::confused::confused:


  • Registered Users Posts: 2,790 ✭✭✭John_Mc


    Darragh29 wrote: »
    Thanks for sticking with me so far John... This is my problem here, I use an appended string to display the shopping cart contents back to the aspx page, and then I display the value of the appended string in a Label. What I'm trying to do is come up with some way of putting a LinkButton that will delete, into the appended string, that goes into the Label.

    If I can't do this, I think I'll have to go backwards and come up with another way of displaying the shopping cart contents in the aspx page. :confused::confused::confused:

    Why cant you use a placeholder or panel instead of the label?

    You can add any control you want to the container without it being constrained to html markup (as would be the case in a label).

    You can still use the Appended string, but populate the container instead of the label.


  • Advertisement
  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    John_Mc wrote: »
    Why cant you use a placeholder or panel instead of the label?

    You can add any control you want to the container without it being constrained to html markup (as would be the case in a label).

    You can still use the Appended string, but populate the container instead of the label.

    OK, I'll give it a shot, I'm just nervous changing it because apart from the delete item issue, it works perfectly.... But I'll copy the page and change the new copy and see how I fare out...


  • Registered Users Posts: 2,790 ✭✭✭John_Mc


    Darragh29 wrote: »
    OK, I'll give it a shot, I'm just nervous changing it because apart from the delete item issue, it works perfectly.... But I'll copy the page and change the new copy and see how I fare out...

    Yeah make a backup of it so you have that to fall back on should thinks go wrong.

    The method I've suggested is relatively easy to implement and will be valuable learning for you. You may encounter problems with Postback but we can cross that bridge when we come to it.

    You'll probably be able to reuse most of your code, except where it sets the label value, instead create a new label with the value and add it to the panel/placeholder.

    Label lb = new Label();
    lb.ID="lblCartRow";
    lb.Text="Blah Blah";
    lb.CssClass="cartLabel";
    //Add to panel.

    panCar.Controls.Add(lb);

    If you're intending on having rows of these labels, then insert a literal control with "<div style="width:100%;">" before and </div> afterwards.

    You will also put your delete button in between these, and any other buttons you may want.


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    OK, I have my container working, I can read a field from my DB and click on my purchase button and it appears in the container. Do I just repeat this process to get the rest of the information that I had appended into my label, to now appear in the container?


  • Registered Users Posts: 2,790 ✭✭✭John_Mc


    Darragh29 wrote: »
    OK, I have my container working, I can read a field from my DB and click on my purchase button and it appears in the container. Do I just repeat this process to get the rest of the information that I had appended into my label, to now appear in the container?

    The answer to that really depends on what your requirements are...

    So you have the items displaying in the container, and you now want to add a delete button. Is that where you want to go from here?

    You just need to add some more logic to the loop which creates a Button/Linkbutton with command arguments that can be used to identify that record in the delete event handler. If you've added the cart item to the DB as a record, you can set the command arg to the records ID.
    Set the button event handler and finally, add the button to the panel.


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    John_Mc wrote: »
    The answer to that really depends on what your requirements are...

    So you have the items displaying in the container, and you now want to add a delete button. Is that where you want to go from here?

    You just need to add some more logic to the loop which creates a Button/Linkbutton with command arguments that can be used to identify that record in the delete event handler. If you've added the cart item to the DB as a record, you can set the command arg to the records ID.
    Set the button event handler and finally, add the button to the panel.

    I've managed to get the original data into the container and also the LinkButton to delete the record, which is appearing with each iteration of an item in my shopping cart (this was one obstacle that I couldn't overcome until you suggested using the container solution), and I've used:

    LNK.ID = string.Format(DataReader["Project_id"].ToString());

    To assign the ID of each LinkButton, to equal the unique ID for each item in my DB.

    Now I think all I need to do is write some code to go into the DB when each LinkButton is clicked and run an SQL query to delete the row WHERE Project_id = LinkButtonID, of something along those lines...

    This is my last question! On a Button Click, I can use:

    protected void Button1_Click(object sender, EventArgs e)

    {
    To do whatever I want to do...
    }

    But can I do the same with a LinkButton??? Also, what's the story with having an undefined number of LinkButtons, depending on the number of items within my cart???

    Here's my code sofar...

    string newstring = string.Concat(obj1," " + obj2, " " + obj3, "<br>" + obj4, " " + obj5, "<br>Retail Price: € " + obj6,"<BR>");

    Label lb = new Label();
    lb.ID = string.Format(DataReader["Project_id"].ToString());
    lb.Text = newstring.ToString();

    LinkButton LNK = new LinkButton();
    LNK.ID = string.Format(DataReader["Project_id"].ToString());
    LNK.Text = "Remove Item<BR><BR>";


    Label lb2 = new Label();
    lb2.ID = string.Format(DataReader["Project_id"].ToString());
    lb2.Text = string.Format(DataReader["Project_id"].ToString());
    lb2.CssClass = "cartLabel";
    //Add to panel.
    Panel1.Controls.Add(lb);
    Panel1.Controls.Add(LNK);


  • Registered Users Posts: 2,790 ✭✭✭John_Mc


    Darragh29 wrote: »
    This is my last question! On a Button Click, I can use:

    protected void Button1_Click(object sender, EventArgs e)

    {
    To do whatever I want to do...
    }

    But can I do the same with a LinkButton???

    Yeah you can. Just treat the Linkbutton the same as a normal button and you shouldnt have any problems.
    Darragh29 wrote: »
    Also, what's the story with having an undefined number of LinkButtons, depending on the number of items within my cart???

    I dont understand the question here?
    Darragh29 wrote: »
    Here's my code sofar...

    string newstring = string.Concat(obj1," " + obj2, " " + obj3, "<br>" + obj4, " " + obj5, "<br>Retail Price: € " + obj6,"<BR>");

    Label lb = new Label();
    lb.ID = string.Format(DataReader["Project_id"].ToString());
    lb.Text = newstring.ToString();

    LinkButton LNK = new LinkButton();
    LNK.ID = string.Format(DataReader["Project_id"].ToString());
    LNK.Text = "Remove Item<BR><BR>";


    Label lb2 = new Label();
    lb2.ID = string.Format(DataReader["Project_id"].ToString());
    lb2.Text = string.Format(DataReader["Project_id"].ToString());
    lb2.CssClass = "cartLabel";
    //Add to panel.
    Panel1.Controls.Add(lb);
    Panel1.Controls.Add(LNK);


    Why do you have lb2 there?

    I would give LNK an ID of something meaningful like "btnDelete_" + nIndex;

    I'd set the LNK.CommandName="Delete" and LNK.CommandArgument=string.Format(DataReader["Project_id"].ToString());

    Then in Button1_Click event handler, check if the CommandName is "Delete" and if so, extract the Project_id from the CommandArgument and use it to remove the item from the list.


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    My only issue with finishing this now is how to tie the following code:

    LinkButton Delete_Btn = new LinkButton();
    Delete_Btn.ID = string.Format(DataReader["Project_id"].ToString());
    Delete_Btn.Text = "Remove Item<BR><BR>";
    Delete_Btn.CommandName="Delete";
    Delete_Btn.CommandArgument = string.Format(DataReader["Project_id"].ToString());

    In with this event handler:

    protected void Delete_Btn_Click(object sender, EventArgs e)

    {
    Response.Write("My delete button works!");
    }

    What I'm trying to do here is just get the button to work, when I have that cracked, I can write whatever I need to write in the {} to get the record deleted, or I think I can!

    But when I do what I think I should be doing here...

    Delete_Btn.OnClientClick = Delete_Btn_Click();

    Or something to relate my Linkbutton to my event handler, I keep getting errors like, "No overload for method 'Delete_Btn_Click' takes '0' arguments"...

    I know I should take the time to sit down and get to grips with functions, methods and all that stuff, I did C and C++ in uni and just scrapped my way through it in first and second year without properly understanding how functions and methods work, I think I understood it for half an hour once and then it just slipped away again!


  • Registered Users Posts: 2,790 ✭✭✭John_Mc


    Darragh29 wrote: »
    My only issue with finishing this now is how to tie the following code:

    LinkButton Delete_Btn = new LinkButton();
    Delete_Btn.ID = string.Format(DataReader["Project_id"].ToString());
    Delete_Btn.Text = "Remove Item<BR><BR>";
    Delete_Btn.CommandName="Delete";
    Delete_Btn.CommandArgument = string.Format(DataReader["Project_id"].ToString());

    In with this event handler:

    protected void Delete_Btn_Click(object sender, EventArgs e)

    {
    Response.Write("My delete button works!");
    }

    What I'm trying to do here is just get the button to work, when I have that cracked, I can write whatever I need to write in the {} to get the record deleted, or I think I can!

    But when I do what I think I should be doing here...

    Delete_Btn.OnClientClick = Delete_Btn_Click();

    Or something to relate my Linkbutton to my event handler, I keep getting errors like, "No overload for method 'Delete_Btn_Click' takes '0' arguments"...

    I know I should take the time to sit down and get to grips with functions, methods and all that stuff, I did C and C++ in uni and just scrapped my way through it in first and second year without properly understanding how functions and methods work, I think I understood it for half an hour once and then it just slipped away again!

    It should be:

    Delete_Btn.OnClick="Delete_Btn_Click";

    Note that this is just the method name, not invoking the method like you were doing. In your case, you'd need to pass an object and event args because this is what the signature tells it to expect. By using Delete_Btn_Click() you're not passing these so that gives this takes 0 arguments error.

    Try that and let me know how it goes

    OnClientClick is for your client side Javascript functions.


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    John_Mc wrote: »
    It should be:

    Delete_Btn.OnClick="Delete_Btn_Click";

    Note that this is just the method name, not invoking the method like you were doing. In your case, you'd need to pass an object and event args because this is what the signature tells it to expect. By using Delete_Btn_Click() you're not passing these so that gives this takes 0 arguments error.

    Try that and let me know how it goes

    OnClientClick is for your client side Javascript functions.

    I haven't seen this error before, but this is what I'm after getting after trying the above. The reason I never tried this before I think is because when I use intellisense, the OnClick option isn't there when I type in Delete_Btn., but OnClientClick is there in the list of options I can use....

    CS0122: 'System.Web.UI.WebControls.LinkButton.OnClick(System.EventArgs)' is inaccessible due to its protection level

    :confused::confused::confused:


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    I've tried changing the OnClick to just Click, which is available on the intellisense list, I get the following error:

    The event 'System.Web.UI.WebControls.LinkButton.Click' can only appear on the left hand side of += or -=


  • Advertisement
  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Darragh29 wrote: »
    I haven't seen this error before, but this is what I'm after getting after trying the above. The reason I never tried this before I think is because when I use intellisense, the OnClick option isn't there when I type in Delete_Btn., but OnClientClick is there in the list of options I can use....

    CS0122: 'System.Web.UI.WebControls.LinkButton.OnClick(System.EventArgs)' is inaccessible due to its protection level

    :confused::confused::confused:

    I'd hazard a guess and say that the OnClick event is declared as private instead of protected.

    I'm a little lost on what your trying to do and its probably to late to jump in here as John_Mc is doing a good job. Sounds to me like you could use a Repeater control though, and binding a datatable to that.

    The repeater control will render all the neccessary controls and html for you and allow you to bind to events in your code behind. I've attached a simple project that demonstrates this (for future reference :)). Its vs2008, if you need an earlier version let me know.

    Just a couple of pointers for good practice, they're only small things:
    object obj1 = new object();
    obj1 = string.Format(DataReader["eq_type"].ToString())
    

    Is somewhat ineffiecent. If you going to concat strings then you should use strings. The following would be better, you don't need to use string.Format either.
    String obj1 = DataReader["eq_type"].ToString();
    


    I'd recommend avoiding the use HTML tags in your code behind too. Better to render your HTML in the aspx page, takes a little more thought but saves major headaches later on.


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Thanks for that Phil, when I get my Delete_Btn working, I'll get rid of my objects as you suggested...

    What I can't understand is why I don't have an option OnClick for my Delete_Btn??? I just want to create an event hander to make something happen when the my LinkButton is clicked. I think I've the hard part done, the button appears where it should and all is well there, I just can't make it work!

    I've put in my:

    protected void Delete_Btn_Click(object sender, EventArgs e)
    {
    Response.Write("Hello World!");
    }

    And I have:

    LinkButton Delete_Btn = new LinkButton();
    Delete_Btn.ID = string.Format(DataReader["Project_id"].ToString());
    Delete_Btn.Text = "Remove Item<BR><BR>";
    Delete_Btn.CommandName="Delete";
    Delete_Btn.CommandArgument = string.Format(DataReader["Project_id"].ToString());
    Delete_Btn.OnClick += Delete_Btn_Click;

    Panel1.Controls.Add(Product_Label);
    Panel1.Controls.Add(Delete_Btn);

    I just need to connect up the two... John's been great for the help with this, I'm 99% of the way there!


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Delete_Btn.Click += new EventHandler(Delete_Btn_Click);
    

    Should see you right.


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Thanks a mill for that Phil, it's building successfully now by the event won't fire for me...


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Have you put a breakpoint on the event to make sure it isn't firing?


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Evil Phil wrote: »
    Have you put a breakpoint on the event to make sure it isn't firing?

    Just tried that Phil and it defo ain't firing...


  • Registered Users Posts: 2,790 ✭✭✭John_Mc


    Darragh29 wrote: »
    Just tried that Phil and it defo ain't firing...

    As I said before, this is most likely due to a problem caused by the .net page life cycle.

    Where is your method that adds the controls to the page being called? The controls need to be added to the page before the Event handler is invoked. Try putting the method call in the Page_Load event.


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    John_Mc wrote: »
    As I said before, this is most likely due to a problem caused by the .net page life cycle.

    Where is your method that adds the controls to the page being called? The controls need to be added to the page before the Event handler is invoked. Try putting the method call in the Page_Load event.

    Is this the method?

    LinkButton Delete_Btn = new LinkButton();

    I need to get my head around (a) Methods, (b) Arguments and (c) Functions, I don't know how I got through 2 years of uni with this!


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    John_Mc wrote: »
    As I said before, this is most likely due to a problem caused by the .net page life cycle.

    Where is your method that adds the controls to the page being called? The controls need to be added to the page before the Event handler is invoked. Try putting the method call in the Page_Load event.

    Hi John, I've read up on the .net page life cycle and most if not all of it has gone completely over my head!


  • Advertisement
  • Registered Users Posts: 2,790 ✭✭✭John_Mc


    Yeah it's pretty confusing at first but it's imperative if you want to dynamically add controls.

    I'm not even sure if method is the correct term, but you have a piece of code that adds the controls to the page. Do you have that code in the Page_Load event or is it in its own function? If its the latter then you need to call that function within the Page_Load event.

    Basically the page is recreated every time you postback, if you don't then the event handler doesnt fire. Be sure that your code isnt within if(!IsPostback).


Advertisement