public void populateCategoryList() { using (DBConnect db = new DBConnect()) { categoryList = db.getCategoryNames(); foreach (Tuple <string, string> category in categoryList) { var image = "Images/quizCategories/" + category.Item1 + ".png"; // Todo: Handle .png as well, or just use .png probably if (!File.Exists(Server.MapPath(image))) { image = "Images/quizCategories/placeholder.png"; // Todo: Placeholder image that isn't a pile of random footballs } System.Web.UI.HtmlControls.HtmlButton cat = new System.Web.UI.HtmlControls.HtmlButton(); cat.ID = category.Item1; // set the ID of this element to the category name to keep things sane cat.Attributes.Add("runat", "server"); // Not sure if we need this, since the placeholder is already runat server cat.Attributes.Add("CommandArgument", category.Item1); // We don't really need to keep using this, we could just use the id, but it feels right cat.Attributes.Add("class", "categoryCard"); // the default state (not selected) cat.InnerHtml = String.Format("<h4>{1}</h4> <hr/> <img src =\"{2}\" alt=\"{1}\" />", category.Item1, category.Item2, image); // Putting our custom interface content into the element cat.ServerClick += new EventHandler(CategorySelected); // SEEMS to work like the OnClick did on an <asp:Button>. Took me like 4 hours to work out. displayCategories.Controls.Add(cat); // Add it to the placeholder, apparently asp.net handles the rest... } } }
protected void ShowDetails(object sender, EventArgs e) { System.Web.UI.HtmlControls.HtmlButton btn = (System.Web.UI.HtmlControls.HtmlButton)sender; GridViewRow gvr = (GridViewRow)btn.NamingContainer; string firstCellValue = gvr.Cells[1].Text; Session["FormType"] = FormSelect.SelectedItem.Text; Session["FirstCellVal"] = firstCellValue; Response.Redirect("DetailsPage.aspx"); }
protected void btnRemove_Click(object sender, EventArgs e) { System.Web.UI.HtmlControls.HtmlButton btn = (System.Web.UI.HtmlControls.HtmlButton)sender; ListViewDataItem item = (ListViewDataItem)btn.Parent; HiddenField hf = (HiddenField)item.FindControl("hf_TempID"); bool isNumeric = int.TryParse(hf.Value, out int iTempID); if (isNumeric) { ApplicationSession.SalesMaster.CollectionSalesDetail().RemoveAtTempID(iTempID); ShowListViewOrder(); } }
public void CategorySelected(object sender, EventArgs e) { System.Web.UI.HtmlControls.HtmlButton button = (System.Web.UI.HtmlControls.HtmlButton)sender; string selection = button.ID; selectedCategories = (List <string>)ViewState["selectedCategories"]; if (selectedCategories.Any(s => s == selection)) { selectedCategories.Remove(selection); ViewState["selectedCategories"] = selectedCategories; button.Attributes.Add("class", "categoryCard"); // Remove the class that highlights the card } else { selectedCategories.Add(selection); // As long as the value is valid we can just pass it straight in, because it doesn't come from the user. ViewState["selectedCategories"] = selectedCategories; // Put updated list back into view state button.Attributes.Add("class", "categoryCard categorySelected"); // Add the class that highlights the card } }
protected void SelectService(object sender, EventArgs e) { System.Web.UI.HtmlControls.HtmlButton button = (System.Web.UI.HtmlControls.HtmlButton)sender; string selection = button.ID; selectedServices = (List <string>)ViewState["selectedServices"]; // Read list out of view state if (selectedServices.Any(s => s == selection)) { selectedServices.Remove(selection); // If it's already in the list we want to remove it, this creates toggle behavior and prevents duplicates. ViewState["selectedServices"] = selectedServices; // Put updated list back into view state // Toggling needs to be represented // to the user as well button.Attributes.Add("class", "categoryCard"); // Remove the class that highlights the card } else { selectedServices = (List <string>)ViewState["selectedServices"]; // Take list out of view state selectedServices.Add(selection); // As long as the value is valid we can just pass it straight in, because it doesn't come from the user. ViewState["selectedServices"] = selectedServices; // Put updated list back into view state button.Attributes.Add("class", "categoryCard categorySelected"); // Remove the class that highlights the card } }
protected override void CreateChildControls() { inputGroup = new System.Web.UI.HtmlControls.HtmlGenericControl("div"); inputGroup.Attributes.Add("class", "input-group"); Controls.Add(inputGroup); ctrl = new System.Web.UI.HtmlControls.HtmlInputText(); ctrl.ID = "ctrl"; ctrl.Attributes.Add("class", "form-control"); ctrl.Attributes.Add("disabled", "disabled"); inputGroup.Controls.Add(ctrl); inputGroupButton = new System.Web.UI.HtmlControls.HtmlGenericControl(); inputGroupButton.Attributes.Add("class", "input-group-btn"); inputGroup.Controls.Add(inputGroupButton); PickerButton = new System.Web.UI.HtmlControls.HtmlButton(); PickerButton.ID = "PickerButton"; PickerButton.Attributes.Add("class", "btn btn-default"); PickerButton.InnerText = "..."; inputGroupButton.Controls.Add(PickerButton); ResetButton = new System.Web.UI.WebControls.Button(); ResetButton.ID = "ResetButton"; ResetButton.Attributes.Add("class", "btn btn-default"); ResetButton.Text = "Reset"; inputGroupButton.Controls.Add(ResetButton); ctrlvalue = new System.Web.UI.HtmlControls.HtmlInputHidden(); ctrlvalue.ID = "ctrlvalue"; ctrlvalue.Name = "ctrlvalue"; inputGroup.Controls.Add(ctrlvalue); }