By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,954 Members | 1,540 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,954 IT Pros & Developers. It's quick & easy.

problem in selected date in Calender control

Vkas
P: 78
i had created my own web calender control!!!!
it consist
1} text box (it display's the selected date)
2} button (it hide and show the calender control)
3} calender control (use for the selection of the date)


How it works!!!!
user clicks on the button calender control becomes visible
user selects a date from calender control
which is displayed in the text box

as the user select the date the calender control hides!!!
Now for changing the selected date again the procedure works perfectly

but
problem is that


if the user again click the same date which is selected by him already so the request should not be postback

any good guide by any one


plzzzz plzzzzz its urgent
Feb 19 '09 #1
Share this Question
Share on Google+
21 Replies


shweta123
Expert 100+
P: 692
Hi,

Please refer the following link:
http://discuss.joelonsoftware.com/de...et.12.206133.4


@Vkas
Feb 19 '09 #2

Vkas
P: 78
should i send my code
please help me
Feb 23 '09 #3

shweta123
Expert 100+
P: 692
Hi,

Calendar control in Asp .Net does not contain property called as Autopostback.
You can check "SelectionMode" property.Using "SelectionMode" property, you can set the value of this property to None to not allowing to select the date to the user.
Feb 23 '09 #4

Vkas
P: 78
can you further explain me it because me not expert like you plz

i would be very thankful to u
Feb 23 '09 #5

Vkas
P: 78
hi toooo

if it does not have auto posback property then ihow should i solve this baaad problem
Feb 23 '09 #6

Frinavale
Expert Mod 5K+
P: 9,731
The ASP.NET Calendar control must post back to the server when the user selects a date. That's just the way that it's been designed.

You could look into using the Ajax Calendar Extender instead.

-Frinny
Feb 23 '09 #7

Vkas
P: 78
mean it the final i have to study Ajax server controls

ok thank you now how to get good , easy knowledge of AJAX Server controls

tell me some good web links
Feb 24 '09 #8

Frinavale
Expert Mod 5K+
P: 9,731
Is there something wrong with the link I sent you to?
It's a free tool kit with Ajax Server controls....what more could you ask for?
Feb 24 '09 #9

shweta123
Expert 100+
P: 692
Hi,

You can also refer the following link :
http://www.codeproject.com/KB/aspnet...ted_Dates.aspx
Feb 24 '09 #10

Vkas
P: 78
no

the links are ok

thanks to you both for you help
Feb 25 '09 #11

Vkas
P: 78
i have created it but i had another problem that i want to use the value that is stored inthe text box in other pages how can i do that any idea?
Feb 25 '09 #12

Vkas
P: 78
i had created my own web calender control!!!
(Calender.ascx)

it consist
Expand|Select|Wrap|Line Numbers
  1. 1} text box (it display's the selected date)
  2. 2} image button (it hide and show the calender control)
  3. 3} calender control (use for the selection of the date)[/b]
  4.  
  5. the code behind is (Calender.ascx.vb)
  6. [b]Partial Class calender
  7.     Inherits System.Web.UI.UserControl
  8.     Private mdtmValue As Date
  9.  
  10.     Public Property Value() As Date
  11.         Get
  12.             Return Me.mdtmValue
  13.         End Get
  14.         Set(ByVal value As Date)
  15.             Me.mdtmValue = value
  16.         End Set
  17.     End Property
  18.  
  19.     Public Sub calender_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
  20.  
  21.         If Me.mdtmValue.ToString("dd/MM/yyyy") <> "01/01/0001" Then
  22.             'Me.txtdate.Text = Me.mdtmValue.ToString("dd/MM/yyyy")
  23.             Me.txtdate.Text = Me.myCalendar.SelectedDate
  24.             Me.mdtmValue = Me.myCalendar.SelectedDate
  25.         End If
  26.     End Sub
  27.  
  28.     Public Sub myCalendar_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles myCalendar.SelectionChanged
  29.  
  30.         Me.mdtmValue = Me.myCalendar.SelectedDate
  31.         txtdate.Text = Me.mdtmValue.ToString("dd/MM/yyyy")
  32.         Me.myCalendar.Visible = False
  33.         If Not (IsPostBack) Then
  34.             If txtdate.Text = Me.myCalendar.SelectedDate Then
  35.  
  36.  
  37.             End If
  38.         End If
  39.  
  40.  
  41.  
  42.  
  43.     End Sub
  44.  
  45.  
  46.  
  47.     Protected Sub btnshow_Click1(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnshow.Click
  48.         If (myCalendar.Visible = True) Then
  49.             myCalendar.Visible = False
  50.         Else
  51.             myCalendar.Visible = True
  52.  
  53.         End If
  54.     End Sub
  55. End Class

How it works!!!!
user clicks on the button calender control becomes visible
user selects a date from calender control hides
displaying the date in text box
as the user select the date the calender control hides!!!
Now for changing the selected date again the procedure works perfectly

but
problem is that

if the user again click the same date which is selected by him already so the request should not be postback and the calender should not hide
i had also done this but little confusingly
as u will see in the code!

2ndly
now i want to use my (Calender.ascx) in other pages
i drag and drop
it works
but how to get the value of the textbox in that page???????
Feb 25 '09 #13

Vkas
P: 78
hi ,

shweta

can u tell me that how to use the value if my web user control in other pages
Feb 25 '09 #14

shweta123
Expert 100+
P: 692
Hi,

You should write a property in your calendar control in order to get the selected date.
e.g.

Expand|Select|Wrap|Line Numbers
  1.     private string m_date; 
  2.     public String myDate
  3.     {
  4.         get
  5.         {
  6.             return m_date;
  7.         }
  8.  
  9.         set
  10.         {
  11.             m_date = value;
  12.         }
  13.   }
Now, in other aspx pages you can use the above property called as mydate as follows :

e.g.
Expand|Select|Wrap|Line Numbers
  1.  
  2.       public void SetDate()
  3.         {
  4.           //Set the myDate property of web user control equal to today'a date.
  5.          WebUserControl1.myDate = DateTime.Today.ToShortDateString();
  6.  
  7.         //Display the selected date of web user control
  8.          lbldate.Text = WebUserControl1.myDate;
  9.      }
  10.  
Feb 25 '09 #15

P: 38
use this code for your calendar.ascx page
Expand|Select|Wrap|Line Numbers
  1. <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
  2.   <INPUT type="button" value="..." onclick="OnClick()"><br>
  3. <div id="divCalendar" style="DISPLAY: none; POSITION: absolute">
  4.   <asp:Calendar id="Calendar1" runat="server" BorderWidth="2px"
  5.                 BackColor="White" Width="200px"
  6.     ForeColor="Black" Height="180px" Font-Size="8pt"
  7.                       Font-Names="Verdana" BorderColor="#999999"
  8.     BorderStyle="Outset" DayNameFormat="FirstLetter" CellPadding="4">
  9.        </asp:Calendar>
  10. </div>
  11. <script>
  12. function OnClick()
  13. {
  14.   if( divCalendar.style.display == "none")
  15.     divCalendar.style.display = "";
  16.   else
  17.     divCalendar.style.display = "none";
  18. }
  19. </script>
AND FOR calendar.ascx.vb this code
Expand|Select|Wrap|Line Numbers
  1. Partial Class SampleUserControl
  2.     Inherits System.Web.UI.UserControl
  3.  
  4.  
  5.     Private Sub Calendar1_SelectionChanged(ByVal sender As System.Object, _
  6.    ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
  7.  
  8.         TextBox1.Text = Calendar1.SelectedDate.ToShortDateString()
  9.         Dim div As System.Web.UI.Control = Page.FindControl("divCalendar")
  10.  
  11.         If TypeOf div Is HtmlGenericControl Then
  12.             CType(div, HtmlGenericControl).Style.Add("display", "none")
  13.         End If
  14.     End Sub
  15.  
  16. End Class

I also use this code in my pages and it is working
Feb 25 '09 #16

Frinavale
Expert Mod 5K+
P: 9,731
Another suggestion would be to write JavaScript that displays the calendar when the Button is clicked

Expand|Select|Wrap|Line Numbers
  1. function ShowCalendar(clientIdOfThePanelCalendarIsIn)
  2. {
  3.     var panel = document.getElementById(clientIdOfThePanelCalendarIsIn);
  4.     panel.style.display = "block";
  5.     panel.style.position = "absolute";
  6. }
Call the JavaScript function that shows the calendar when the Button is clicked client side:
Expand|Select|Wrap|Line Numbers
  1. Public Sub calender_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.    If IsPostback = False Then
  3.     btnshow.Attributes.Add("onclick","ShowCalendar('"+PanelThatContainsTheCalendar.ClientID+"'); return false;")
  4.     PanelThatContainsTheCalendar.style.Remove("display")
  5.     PanelThatContainsTheCalendar.style.Add("display","none")
  6.  
  7.      '.........
  8.     End If
  9.  
  10.      '.........
  11. End Sub
Now in your ASP code you have to Place the Calendar control in a panel:

Expand|Select|Wrap|Line Numbers
  1. <asp:Panel id="PanelThatContainsTheCalendar" runat="server" >
  2.     <asp:Calendar ID="myCalendar" runat="server"></asp:Calendar>
  3. </asp:Panel>
  4.  
Please note that the style for the panel has been set to have a display = none. This means that the panel will not be shown in the browser. The JavaScript changes this style to be display = block which shows the panel. Now the problem here is that the Calendar requires a post back to the server in order to work. This will cause the page to be sent back to the server and reloaded in the browser. Since the page is reloaded, the style will be set back to display = none....

So there are a few ways to get around this.
The first is to place the calendar in an UpdatePanel. This will cause a partial page update to happen and the style wont be changed:

Expand|Select|Wrap|Line Numbers
  1. <asp:Panel id="PanelThatContainsTheCalendar" runat="server" style="display:none;"> 
  2.     <asp:UpdatePanel id="CalendarUpdate" runat="server">
  3.         <asp:Calendar ID="myCalendar" runat="server"></asp:Calendar>
  4.     </asp:UpdatePanel>
  5. </asp:Panel>
  6.  
(Note that the UpdatePanel requires that a ScriptManager exist)

Please be aware that if any other control causes a full page postback on the page, the calendar will not be shown when the page is re-displayed. To fix this make sure to set the style of the panel that contains the calendar in the calendar's SelectionChanged event:
Expand|Select|Wrap|Line Numbers
  1. Sub myCalendar_Selection_Changed(sender As Object, e As EventArgs) Handles myCalendar.SelectionChanged
  2.  
  3.     PanelThatContainsTheCalendar.style.Remove("display")
  4.     PanelThatContainsTheCalendar.style.Add("display","block")
  5. End Sub




The other way to do this is not to use JavaScript.

You'd let your button post back to the server and you would have to display the calendar then. In this case you don't need to place the Calendar in a panel.

In your page load event for this solution, you would set the myCalendar .Visible = False if it's the first time the page loads.

When the user clicks the button set the myCalendar .Visible = True to display it.
Feb 25 '09 #17

Vkas
P: 78
hi to all ov the people Shweta,Alamodgal,and frinavale

very very thanks to u all !
i am trying to implement the three of fthe method today hope that they works successfully because i understand them easily!!

wawooo!!! very great thanks to u three !

i will tease u a lill ! more in future!
Feb 27 '09 #18

Vkas
P: 78
Hi alam when i run the page then it gives this error

'OnClick' is not a member of 'ASP.newcontrol_ascx'.

y?
Feb 27 '09 #19

Vkas
P: 78
hello shwetta!!! its for u

i had define the property as
Expand|Select|Wrap|Line Numbers
  1. Private mdtmValue As Date
  2.  
  3.    Public Property Value() As Date
  4.         Get
  5.             Return Me.mdtmValue
  6.         End Get
  7.         Set(ByVal value As Date)
  8.             Me.mdtmValue = value
  9.         End Set
  10.     End Property



and the name of my WebuserControl is (Calender.ascx)

but when write
Expand|Select|Wrap|Line Numbers
  1. Calender.mtdmdate = DateTime.Today.ToShortDateString();
it dont gives value!!!
mean my mtdmDate is not shown when i press the dot button!
help me Shweta!
Feb 27 '09 #20

Frinavale
Expert Mod 5K+
P: 9,731
It's probably not a good idea to name your user control "Calendar" because there is an existing Asp.Net Calendar control...also it's probably not a good idea to name your property "Value" either.

But, choice of names aside, you cannot do this:
Expand|Select|Wrap|Line Numbers
  1. Calender.mtdmdate = DateTime.Today.ToShortDateString()
The reason is because the mdtmValue variable is private. Therefore, it is not accessible to any calling code.

That is the whole reason why you created the property: to be able to get and set the private member.

You should be using your property:
Expand|Select|Wrap|Line Numbers
  1. Calender.Value= DateTime.Today.ToShortDateString()

Again, it is advisable to chose better names.

Out of curiosity, what language are you using?
Because you cannot have semi colons (;) in VB.NET but you've defined a VB.NET property....
Feb 27 '09 #21

Vkas
P: 78
hi Expert
ya i got you things next time i would make good choice of names
and i am using Vb.net !
i havent use (;) in my code !
ok i will try to impliment the thing you had told me

Again very thanks!
Feb 28 '09 #22

Post your reply

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