473,473 Members | 1,847 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Cannot access attributes control of servercontrol page calendar in default.aspx

6 New Member
I cannot access attributes control of server control page calendar in default.aspx

Dipti_Calendar.cs
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Web;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.HtmlControls;
  11. using System.Drawing;
  12.  
  13. namespace Dipti_Calendar
  14. {
  15.     [DefaultProperty("Text")]
  16.     [ToolboxData("<{0}:Dipti_Calendar runat=server></{0}:Dipti_Calendar>")]
  17.     public class Dipti_Calendar : Calendar
  18.     {
  19.         [Bindable(true)]
  20.         [Category("Appearance")]
  21.         [DefaultValue("")]
  22.         [Localizable(true)]
  23.         public string Text
  24.         {
  25.             get
  26.             {
  27.                 String s = (String)ViewState["Text"];
  28.                 return ((s == null)? "[" + this.ID + "]" : s);
  29.             }
  30.  
  31.             set
  32.             {
  33.                 ViewState["Text"] = value;
  34.             }
  35.         }
  36.  
  37.         public Color h_color
  38.         {
  39.             get
  40.             {
  41.                 // look for h_color in ViewState
  42.                 object o = ViewState["h_color"];
  43.                 if (o == null)
  44.                     return Color.Empty;
  45.                 else
  46.                     return (Color)o;
  47.             }
  48.             set
  49.             {
  50.                 ViewState["h_color"] = value;
  51.             }
  52.         }
  53.  
  54.         protected override void OnLoad(EventArgs e)
  55.         {
  56.             base.PrevMonthText = "Prev";
  57.             base.NextMonthText = "Next";
  58.             base.SelectedDate = System.DateTime.Now;           
  59.             base.OnLoad(e);
  60.         }
  61.         protected override void OnDayRender(TableCell c, CalendarDay d)
  62.         {
  63.             HtmlGenericControl div = new HtmlGenericControl("DIV");
  64.             Label lb = new Label();
  65.             lb.Text = d.Date.ToString("dd");
  66.             lb.ForeColor = System.Drawing.Color.ForestGreen;
  67.             string month = base.SelectedDate.ToString("MM");
  68.             int year=base.SelectedDate.Year;
  69.  
  70.             TextBox tb = new TextBox();
  71.             tb.ID = "tb" + "-" + d.Date.ToString("dd") + "-" + d.Date.ToString("MM") + "-" + d.Date.ToString("yyyy");           
  72.             tb.CssClass = "hoteldetail_cont";            
  73.             tb.Attributes.Add("runat", "server");
  74.  
  75.             if (year.ToString() != d.Date.ToString("yyyy") && month.ToString() != d.Date.ToString("MM"))
  76.             {
  77.                 tb.Attributes.Add("readonly", "true");
  78.                 tb.Attributes.Add("style", "background-color:#999999");
  79.             }         
  80.             div.Controls.Add(lb);
  81.             div.Controls.Add(tb);
  82.  
  83.             c.Attributes.Add("Class", "col-sm-2 dates_cont");
  84.             c.Controls.Add(div);
  85.             base.OnSelectionChanged();
  86.             base.OnDayRender(c, d);           
  87.         }
  88.  
  89.  
  90.         protected override void RenderContents(HtmlTextWriter output)
  91.         {
  92.             output.Write(Text);
  93.         }
  94.     }
  95. }
  96.  
Default.aspx
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
  2.  <%@ Register Assembly="Dipti_Calendar" TagPrefix="DiptiCalendar" Namespace="Dipti_Calendar"  %>
  3.  <!DOCTYPE html>
  4.  <meta charset="utf-8"> 
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <meta name="description" content="">
  8.  <meta name="author" content=""> 
  9. <html xmlns="http://www.w3.org/1999/xhtml">
  10.  <head runat="server"> 
  11. <title></title> 
  12. <link href="http://bytes.com/css/bootstrap.min.css" rel="stylesheet" /> 
  13. <link href="http://bytes.com/css/bootstrap.css" rel="stylesheet" />
  14.  <link href="http://bytes.com/css/calendar.css" rel="stylesheet" />
  15.  
  16.  <script src="http://bytes.com/js/jquery-1.11.0.js" type="text/javascript"></script> 
  17. <script src="http://bytes.com/js/bootstrap.min.js" type="text/javascript"></script>
  18.  </head>
  19.  
  20.  <body>
  21.  <form id="form1" runat="server">
  22.  <div class="container">
  23.  <DiptiCalendar:Dipti_Calendar ID="DC" runat="server" OnDayRender="DC_DayRender" TitleStyle-CssClass="month_cont" DayHeaderStyle-CssClass="weekname_cont" > 
  24. </DiptiCalendar:Dipti_Calendar> 
  25. </div>
  26.  
  27.  <div class="btnsave"> 
  28. <asp:ImageButton ID="btnsave" runat="server"  ImageUrl="http://bytes.com/~/Images/sale-save.png" Width="80px" OnClick="btnsave_Click" />
  29.  </div> 
  30. <asp:Label ID="lbldate" runat="server" Text="1"></asp:Label>
  31.  <asp:Label ID="lblcelldata" runat="server" Text="2"></asp:Label>
  32.  </form>
  33.  </body>
  34.  </html>
  35.  
Default.aspx.cs
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Drawing;
  8. using System.Data.SqlClient;
  9. using System.Data;
  10. using Dipti_Calendar;
  11. //using System.Web.UI.ControlCollection;
  12.  
  13. public partial class _Default : System.Web.UI.Page
  14. {
  15.     Dipti_Calendar.Dipti_Calendar dcal = new Dipti_Calendar.Dipti_Calendar();
  16.  
  17.     protected void Page_Load(object sender, EventArgs e)
  18.     {        
  19.     }
  20.  
  21.     protected void DC_DayRender(object sender, DayRenderEventArgs e)
  22.     {
  23.  
  24.  
  25.     }
  26.     protected void btnsave_Click(object sender, ImageClickEventArgs e)
  27.     {
  28.     }
  29.  
  30. }
Jan 20 '15 #1
5 1603
Dipti Dhiman
6 New Member
Dont know how to access lb and tb control in default.aspx.cs... :-(

on save button click, i want to access data of all textbox for a given month and to save it into database
Jan 20 '15 #2
Frinavale
9,735 Recognized Expert Moderator Expert
Huh?
You have a Dipti_Calendar defined in your ASP.NET code for the Default.aspx page:
Expand|Select|Wrap|Line Numbers
  1. <DiptiCalendar:Dipti_Calendar ID="DC" runat="server" OnDayRender="DC_DayRender" TitleStyle-CssClass="month_cont" DayHeaderStyle-CssClass="weekname_cont" > 
  2. </DiptiCalendar:Dipti_Calendar> 
  3.  
But I don't see you using that control in your C#, server-side code....

Have you tried something like:
Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3.   DC.h_color = Color.Pink;
  4. }
I really don't understand where the problem is...

-Frinny
Jan 20 '15 #3
Dipti Dhiman
6 New Member
I m getting the control of lb and tb in DC_DayRender function but i want to access the same on btnsave_Click....
Here is my Code
Expand|Select|Wrap|Line Numbers
  1.     protected void DC_DayRender(object sender, DayRenderEventArgs e)
  2.     {
  3.         Label x = (Label)DC.Labelx;
  4.         var lbltext = DC.lb.Text;
  5.  
  6.         TextBox t = (TextBox)DC.tb;
  7.         var textboxid = DC.tb.ID;
  8.         var textboxdata = DC.tb.Text;
  9.  
  10.  
  11.     }
  12.     protected void btnsave_Click(object sender, ImageClickEventArgs e)
  13.     {
  14.         string x=DC.lb.ID.ToString();         
  15.     }
  16.  
and what i want to do is :
1.Here is my stored procedure
Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDURE antilogin.calendarinsert
  2.     @date nvarchar(50),
  3.     @value int
  4. AS
  5.  
  6.     insert into Calendar(Cal_date,Cal_value)
  7.      values(@date,@value)
  8.  
  9.      select * from Calendar
  10.     RETURN
  11.  
2.I want to check each date(to store as Cal_Date) and respected value stored in textbox(to store as Cal_value),of Calendar, on btnsave_Click..
as
Expand|Select|Wrap|Line Numbers
  1.  protected void btnsave_Click(object sender, ImageClickEventArgs e)
  2.     {
  3.         string x=DC.lb.ID.ToString();     
  4.     //  lbldate.Text= 
  5.         // lblcelldata.Text=
  6.         //dbclass db = new dbclass();
  7.         //db.cmd.Connection = db.conr;
  8.         //db.cmd.CommandType = CommandType.StoredProcedure;
  9.         //db.cmd.CommandText = "calendarinsert";
  10.         ////db.cmd.Parameters.Add("@date", SqlDbType.NVarChar).Value = lbldate.Text;
  11.         ////db.cmd.Parameters.Add("@value", SqlDbType.NVarChar).Value = lblcelldata.Text;
  12.         //db.da.SelectCommand = db.cmd;
  13.         //try
  14.         //{
  15.         //    db.con.Open();
  16.         //    db.cmd.ExecuteNonQuery();
  17.         //}
  18.  
  19.         //catch
  20.         //{
  21.  
  22.         //}
  23.  
  24.         //finally
  25.         //{
  26.         //    db.con.Close();
  27.         //}
  28.     }
Jan 21 '15 #4
Dipti Dhiman
6 New Member
Also i perform some changes in Dipti_Calendar.cs to access controls as:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Web;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.HtmlControls;
  11. using System.Drawing;
  12.  
  13. namespace Dipti_Calendar
  14. {
  15.     [DefaultProperty("Text")]
  16.     [ToolboxData("<{0}:Dipti_Calendar runat=server></{0}:Dipti_Calendar>")]
  17.     public class Dipti_Calendar : Calendar
  18.     {
  19.         public TextBox tb = new TextBox();
  20.         public Label lb = new Label();      
  21.  
  22. [Bindable(true)]
  23.         [Category("Appearance")]
  24.         [DefaultValue("")]
  25.         [Description("Description for text")]
  26.         [Localizable(true)]
  27.  
  28.         public string TextBoxx
  29.         {
  30.             get
  31.             {
  32.                 String s = (String)ViewState["Text"];
  33.                 return ((s == null) ? "[" + this.ID + "]" : s);
  34.                 //object tbx = ViewState["TextBoxx"];
  35.                 //return (Control)tbx;
  36.             }
  37.             set
  38.             {
  39.                 ViewState["TextBoxx"] = value;
  40.             }
  41.         }
  42.         [
  43.         Bindable(true),
  44.         Category("Appearance"),
  45.         DefaultValue(""),
  46.         Description("The text for the name label.")
  47.         ]
  48.         public Object Labelx
  49.         {
  50.             get
  51.             {                
  52.                // object lb = ViewState["Label"];
  53.                 return (Object)lb;
  54.                 //return lb.Text;
  55.             }
  56.  
  57.             set
  58.             {
  59.                 ViewState["Label"] =value;
  60.             }
  61.         }
  62.  
  63.         public Color h_color
  64.         {
  65.             get
  66.             {
  67.                 // look for h_color in ViewState
  68.                 object o = ViewState["h_color"];
  69.                 if (o == null)
  70.                     return Color.Empty;
  71.                 else
  72.                     return (Color)o;
  73.             }
  74.             set
  75.             {
  76.                 ViewState["h_color"] = value;
  77.             }
  78.         }
  79.  
  80.         protected override void OnLoad(EventArgs e)
  81.         {
  82.             base.PrevMonthText = "Prev";
  83.             base.NextMonthText = "Next";
  84.             base.SelectedDate = System.DateTime.Now;
  85.             base.OnLoad(e);
  86.         }
  87.  
  88.         protected override void OnDayRender(TableCell c, CalendarDay d)
  89.         {
  90.             HtmlGenericControl div = new HtmlGenericControl("DIV");       
  91.             lb.Text = d.Date.ToString("dd");
  92.             lb.ID = "lb-" + d.Date.ToString("dd") + "-" + d.Date.ToString("MM") + "-" + d.Date.ToString("yyyy");
  93.             lb.ForeColor = System.Drawing.Color.ForestGreen;
  94.             string month = base.SelectedDate.ToString("MM");
  95.             int year=base.SelectedDate.Year;
  96.  
  97.             tb.ID = "tb" + "-" + d.Date.ToString("dd") + "-" + d.Date.ToString("MM") + "-" + d.Date.ToString("yyyy");           
  98.             tb.CssClass = "hoteldetail_cont";            
  99.             tb.Attributes.Add("runat", "server");            
  100.  
  101.  
  102.             div.Controls.Add(lb);
  103.             div.Controls.Add(tb);
  104.  
  105.             c.Attributes.Add("Class", "col-sm-2 dates_cont");
  106.             c.Controls.Add(div);
  107.  
  108.             base.OnSelectionChanged();            
  109.             base.OnDayRender(c, d);           
  110.         }
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.         protected override void RenderContents(HtmlTextWriter output)
  118.         {
  119.             output.Write(TextBoxx);
  120.             output.Write(Labelx);
  121.         }
  122.     }
  123. }
Jan 21 '15 #5
Frinavale
9,735 Recognized Expert Moderator Expert
You need to use using public properties in your Dipti_Calendar to expose things that you require in your ASPX page to do what you need to do.

For example, your Dipti_Calendar control should contain a public "Date" property so that you can access the selected date in the Button Click event code that is part of your ASPX page....this way you can call your stored procedure and pass it the appropriate value as the date parameter. You will also need to have a "CalendarValue" property that will give you access to the information that should be provided to your stored procedure as the value parameter.

As for your second question....

You should probably not be adding controls dynamically to your page unless you fully understand what is entailed with this process.

Instead you should just open the Dipti_Calendar.aspx file and add the controls where every you want them to be.

-Frinny
Jan 21 '15 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Blue Ball | last post by:
I have setup the global.asax, so that everytime server encounters an error, I will be notified by email. Now, my web site is up and running. However, EVERY TIME I update the "default.aspx" by...
2
by: adiel | last post by:
Hello, I am trying to access the properties and methods from a user control within the code-behind file for a webform but I am receiving the message: Name 'MenuBar1' is not declared It does...
6
by: William Parker | last post by:
I have a web control I made called header.ascx. It has its own properties and methods I defined. But I cannot figure out how to access this control from my code behind page. I can create the...
2
by: rodchar | last post by:
Hey all, I have an asp.net page called default.aspx. when I visit this site i type in http://myDirectory/ because I know that the name default.aspx will be assumed. However, when i goto this...
1
by: digitalego | last post by:
Sorry if the title is a little confusing... Here is the problem. I am working with a "default.aspx" page that uses a user control I made: ------------------------------ | default.aspx ...
9
by: David Veeneman | last post by:
I'm just getting started with ASP.NET, using VS 2005. As an exercise, I opened the root web site in VS 2005 and created a simple welcome page. I saved the page as Default.aspx and made sure that...
3
by: Joey | last post by:
I have several asp.net 2.0 apps written in VS2005 in C#. For each one, I like to create and track page view events, increment counters, etc. I do this in a block on each page, like this... ...
4
by: cj | last post by:
When I start a new web app it has a default.aspx in it. Every example I see tell me to add a new aspx file for my pages. What is up with default.aspx?
4
by: =?Utf-8?B?SmFwZQ==?= | last post by:
Can I refer to the controls on default.aspx from the masterpage? I have a form on the masterpage which sends information that is in a gridview in the default.aspx page.
0
by: Swapnil Mahajan | last post by:
Hi I have solution with MVP pattern using WCSF. My all pages able to load master page except Default.aspx page in website directory. As my page having all necessary things for master page. My aspx...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.