Category Archives: CheckBox

[RESOLVED] creat dynamic check boxes in check box selection

Hi friends,

   when we select a check boxes creat dynamic check boxes. I have a main catagory check box when we select this main catagory check box creat subcatagory check boxes related to main catagory dynamically.

    Thanks in advance,

Set the main checkbox to automatically submit the form, and see the following tutorial for how to add new controls (in your case, checkboxes) to the page dynamically:

http://www.4guysfromrolla.com/articles/081402-1.aspx

 

[RESOLVED] dynamically add checkboxes to a calendar control...

I want to add two checkboxes to selected days in a calendar control.  I can do that but I can not figure out how to get the checkboxes to fire an event.   I tried to get a button to fire and event by iterating through the panel without success either. Here is my code so far:

Thanks in advance,

Photon (Springfield, Missouri)

 

<%@ Page Title="" Language="VB" MasterPageFile="~/Default.master" AutoEventWireup="false" CodeFile="Caledar_Add.aspx.vb" Inherits="Admin_Caledar_Add" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
    
    <div id="home">
     <div id="Div" runat="server" style="width: 810px; height: 500px;">
   <div id="sidebar">
       
               
                 <asp:Button ID="Button_GetCheckBox" runat="server" Text="Button" />
                 <asp:Label id="Label1" runat="server" />
             </div>
       
             <asp:Panel ID="Panel1" runat="server">
           
       
       
      <div id="content">
          <h3><font face="Verdana">Adding Custom Content to Calendar</font></h3>
          <asp:Calendar id="Calendar1" runat="server"
                    ondayrender="Calendar1_DayRender"
                    onselectionchanged="Date_Selected"
                    ShowGridLines="true"
                    BorderWidth="1"
                    Font-Names="Verdana"
                    Font-Size="9px"
                    Width="500px"
                    VisibleDate="01/01/2011"
                    TitleStyle-BackColor="Red"
                    TitleStyle-Font-Size="12px"
                    TitleStyle-Font-Bold="true"
                     DayStyle-VerticalAlign="Top"
                    DayStyle-Height="50px"
                    DayStyle-Width="14%"
                    SelectedDate="1/1/0001"
                    SelectedDayStyle-BackColor="Red" />
                </asp:Panel>
  
  </div>
  </div>
  </div>

</asp:Content>

 

'**Code Behind**
Partial Class Admin_Caledar_Add

    Inherits System.Web.UI.Page

    Dim holidays(12, 31) As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        holidays(1, 1) = "New Year's Day"
        holidays(1, 26) = "Australia Day"
        holidays(2, 2) = "Groundhog Day"
        holidays(2, 14) = "Valentine's Day"
        holidays(3, 17) = "St. Patrick's Day"
        holidays(4, 1) = "April Fool's Day"
        holidays(5, 1) = "May Day"
        holidays(6, 15) = "My Birthday"
        holidays(7, 15) = "My Anniversary"
        holidays(8, 15) = "My Mother's Birthday"
        holidays(9, 24) = "Autumnal Equinox"
        holidays(12, 26) = "Boxing Day"

    End Sub
   

    Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As DayRenderEventArgs)

        Dim d As CalendarDay
        Dim c As TableCell

        d = e.Day
        c = e.Cell

        If d.IsOtherMonth Then
            c.Controls.Clear()
        Else
            Try
                Dim Hol As String = holidays(d.Date.Month, d.Date.Day)
                'Response.Write(Hol)
                If Hol <> "" Then
                   
                    Dim _checkbox_Delete As CheckBox = New CheckBox()
                    _checkbox_Delete.ID = "chkDynamicCheckBox_Delete"
                    _checkbox_Delete.Text = "Delete"
                    c.Controls.Add(New LiteralControl("<br>" + Hol.ToString + "<br/>"))
                    c.Controls.Add((_checkbox_Delete))
                   
                    AddHandler _checkbox_Delete.CheckedChanged, AddressOf _checkbox_Delete_CheckedChanged
                End If
            Catch exc As Exception
               
                Response.Write(exc.ToString())
            End Try
        End If
    End Sub

   


   

    Function _checkbox_Delete_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
        Dim objCheckbox = DirectCast(sender, CheckBox)
        Response.Write("test")
    End Function

   

    Protected Sub Button_GetCheckBox_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_GetCheckBox.Click
        For Each ctl As Control In Panel1.Controls
    
            If TypeOf ctl Is CheckBox Then
                'CType(ctl,CheckBox).ID
                Response.Write("test")
            End If
        Next ctl

    End Sub


End Class

 

I haven't got a response  so I will try again in a more focused way.  I have created a calendar control using ASP.net visual studio express 2008.  In the dayrender event, I have dynamically created  checkboxes.  My problem is I am not able to fire an event through an event handler.  What am I not doing correctly?  Below is my code:

Thanks in advance,

Photon

 

<%@ Page Title="" Language="VB" MasterPageFile="~/Default.master" AutoEventWireup="false" CodeFile="testcalendar.aspx.vb" Inherits="Admin_testcalendar" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
    <div id="content">
         
  <h3><font face="Verdana">Adding Custom Content to Calendar</font></h3>

    <asp:Calendar id="Calendar1" runat="server"
                    ondayrender="Calendar1_DayRender"
                    ShowGridLines="true"
                    BorderWidth="1"
                    Font-Names="Verdana"
                    Font-Size="9px"
                    Width="500px"
                    VisibleDate="01/01/2011"
                    TitleStyle-BackColor="Red"
                    TitleStyle-Font-Size="12px"
                    TitleStyle-Font-Bold="true"
                     DayStyle-VerticalAlign="Top"
                    DayStyle-Height="50px"
                    DayStyle-Width="14%"
                    SelectedDate="1/1/0001"
                    SelectedDayStyle-BackColor="Red" />
                   
    </div>

</asp:Content>

'***Code Behind****

Partial Class Admin_testcalendar
    Inherits System.Web.UI.Page

    Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
       
        e.Cell.Text = ""
        Dim c As New CheckBox()
        c.Text = e.Day.DayNumberText
        AddHandler c.CheckedChanged, AddressOf _checkbox_CheckedChanged
        c.AutoPostBack = True

        e.Cell.Controls.Add(c)

    End Sub

    Protected Sub _checkbox_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
        Dim objCheckbox = DirectCast(sender, CheckBox)

        'this response.write does not fire when a checkbox is checked
        Response.Write("test")
    End Sub
End Class


 

 

 

 

Hi,

Photon

I have dynamically created  checkboxes.  My problem is I am not able to fire an event through an event handler.  What am I not doing correctly
 

When we dynamically add control in page. We should notice that in page_Init as well as page_load is the best period for us to add control.

Calendar1_DayRender evnet is a very later event in page life cycle. So "AddHandler c.CheckedChanged, AddressOf _checkbox_CheckedChanged" will not trigger the event.

Alternative way is to use Page.ClientScript.GetPostBackEventReference to add a postback event manually to checkbox.

Like:

protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Form["__EVENTTARGET"] != null)
            {
                Response.Write(Request.Form["__EVENTARGUMENT"]);
            }
        }


  protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
        {
            e.Cell.Text = "";
            CheckBox cb = new CheckBox();
            cb.ID = "cb_" + e.Day.Date.ToString();
            cb.Text = e.Day.DayNumberText;
            cb.Attributes["onclick"] = Page.ClientScript.GetPostBackEventReference(cb, "CheckChanged");  //add postback event(javascript)
           

            e.Cell.Controls.Add(cb);
        }


And also the calendar can not remain the checkbox checked state on postback, so you need to use some state management object to store the checkbox checked list and remain them manually.

Hope this can help you.

[RESOLVED] Checkbox_Changed event

Hi All,

So if I have a Checkbox_Changed event with some code in it and a few variables etc, how can I then reference these variables in the main part of my code? I don't seem to be able to reference these atm.

Below is a example of my code

protected void Button1_Click(object sender, EventArgs e)
        {
            string newStartDay = SDay.Text;                                             //All variables matched up to controls on the form.
            string newStartMonth = SMonth.Text;
            string newStartYear = SYear.Text;
            string newCompleteStartDate = "";
            string newEndDay = EDay.Text;
            string newEndMonth = EMonth.Text;
            string newEndYear = EYear.Text;
            string newCompleteEndDate = "";
            DateTime startdt = DateTime.MinValue;
            DateTime enddt = DateTime.MinValue;
            

            if ((Convert.ToInt32(newStartDay)) != 0 | newStartMonth != "Select" | (Convert.ToInt32(newStartYear)) != 0)     //picks up the values in the start date options and makes them in a string
            {
                newCompleteStartDate = newStartDay + " " + newStartMonth + " " + newStartYear;
                startdt = Convert.ToDateTime(newCompleteStartDate);
            }


                 

            

         

                        

            //string queryValuesRedirect = "WebResponsePage.aspx?";
            //queryValuesRedirect += "QueryValues=" + startdt + " " + enddt + " " + TextBoxValue + " " + newCountryEF;
            //Response.Redirect(queryValuesRedirect);
            

        }




protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        {
            int i = 0;
            string[] Array = new string[100000000];
            foreach (ListItem item in Country.Items)
            {
                item.Selected = true;
                Array[i] = item.ToString();
                i = i + 1;
            }


        }


So say I want to reference the Array in Checkbox1_CheckedChanged under the button click how do I do this? I tried changing it from "Protected to Public" and that didnt help.

many thanks

For arrays - You can use Session Arrays described here..

http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=63

for variables - to use across functions, you can use straight forward session variables.

Hello there!

I not sure I follow what you trying to do. But in order to access variables on different parts of code you need to declare them as Class variables.

You cannot access your Array because of the scope in which is declared. Declare it on the class level and intantiate it on the checkbox1_checkedChanged event then you will be able to access it outside. 

Hi, as you've defined your variables within the control events they stay local and are only accessable within those events. To be able to use the variables within all control events set up your variables at the page class level. Also consider using properties.

See: http://msdn.microsoft.com/en-us/library/x9fsa0sw(v=vs.80).aspx#Y84


[RESOLVED] how to change orientation of webparts from vertical to horizontal in catelog zone

dear experts,


by default  closed webparts are listed in catelog zone vertically

for example,

[checkbox]  [webpart 1]

[checkbox]  [webpart 2]

[checkbox]  [webpart 3]


any one guide me which property is used to list them horizontally?

i want them like

[checkbox]  [webpart 1]   [checkbox]  [webpart 2]    [checkbox]  [webpart 3]


any help would be appreciated.


Hi,

You can use

 LayoutOrientation="Horizontal"

Regards
Shabir
<asp:CatalogZone ID="CatalogZone1" runat="server" BackColor="#F7F6F3" BorderColor="#CCCCCC"
                    BorderWidth="1px" Font-Names="Verdana" Padding="6" LayoutOrientation="Horizontal" >
                    <ZoneTemplate>
                    <asp:PageCatalogPart ID="PageCatalogPart1" runat="server" />


                     <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" runat="server"  Title="Web Parts"  LayoutOrientation="Horizontal">
                        <WebPartsTemplate>
                           

                        </WebPartsTemplate>
                   </asp:DeclarativeCatalogPart>




                    </ZoneTemplate>
                    <PartLinkStyle Font-Size="0.8em" />
                    <PartTitleStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.8em" ForeColor="White" />
                    <EditUIStyle Font-Names="Verdana" Font-Size="0.8em" ForeColor="#333333" />
                    <PartStyle BorderColor="#F7F6F3" BorderWidth="5px" />
                    <HeaderVerbStyle Font-Bold="False" Font-Size="0.8em" Font-Underline="False" ForeColor="#333333" />
                    <PartChromeStyle BorderColor="#E2DED6" BorderStyle="Solid" BorderWidth="1px" />
                    <EmptyZoneTextStyle Font-Size="0.8em" ForeColor="#333333" />
                    <SelectedPartLinkStyle Font-Size="0.8em" />
                    <VerbStyle Font-Names="Verdana" Font-Size="0.8em" ForeColor="#333333" />
                    <LabelStyle Font-Size="0.8em" ForeColor="#333333" />
                    <FooterStyle BackColor="#E2DED6" HorizontalAlign="Right" />
                    <HeaderStyle BackColor="#E2DED6" Font-Bold="True" Font-Size="0.8em" ForeColor="#333333" />
                    <InstructionTextStyle Font-Size="0.8em" ForeColor="#333333" />
                </asp:CatalogZone>





Hi,

You can try to set the PartStyle:

<PartStyle
            GridLines="Horizontal"
            HorizontalAlign="Center"
/>

 

Hope this can help you.

[RESOLVED] gridview update not firing with required field validator

I have a gridview that contains a textbox, a drop down, and a checkbox.  The commandfield of the gridview has ShowEditButton="true".  All of the gridview updating takes place in the "_OnRowUpdating" event.  I have a Panel above the gridview with a table and some fields.  Everything in the gridview works perfectly, the edit, the update etc., however, when I add a requiredfieldvalidator to the panel above the gridview, the gridview update functionality no longer works. e.g., clicking the update button does not appear to fire.  If I comment out the requiredfieldvalidator, everything works fine. 

Assign a ValidationGroup to your Validator and whatever Buttons, etc., that are supposed to trigger the validation.