• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 30
  • Last Modified:

Capture selected date from asp calendar control

I am try to use the asp:calendar control within an update panel within a div
The purpose of the div is  to use a jquery function to make it visible and not visible

The jquery function works, the code behind gets the value from the control but the page does not show the value within the textbox.


    <div ID="divCalendarInv" class="CenterScreen">
        <asp:UpdatePanel ID="updPnlCalendarInv" runat="server">
        <ContentTemplate>
            <asp:Calendar ID="CalendarInv" runat="server" Width="200px" OnSelectionChanged="CalendarInv_SelectionChanged"  BackColor="Blue" ForeColor="White"></asp:Calendar>
        </ContentTemplate>
        </asp:UpdatePanel>
    </div>

protected void CalendarInv_SelectionChanged(object sender, EventArgs e)
{
	txtInvoiceDate.Text = CalendarInv.SelectedDate.ToString("MM/dd/yyyy");
	ScriptManager.RegisterStartupScript(this.Page, GetType(),  "SetV", "SetVisibility('divCalendarInv')", true);
}

   function SetVisibility(ctlid)
    {      
        if ($('#' + ctlid).css('display') == 'none')
        {
            $('#' + ctlid).show(); 
        }
        else
        {
            $('#' + ctlid).hide(); 
        }
    }

Open in new window

Can anyone explain this behavior and how to fix it?

Thanks in advance
eequestion.txt
0
CSUGDEN
Asked:
CSUGDEN
  • 4
  • 3
1 Solution
 
leakim971PluritechnicianCommented:
let's forget javascript a bit and remove lines 12, 15 to 25.
do it work? could you see the date in txtInvoiceDate ?
we don't see txtInvoiceDate in your code
0
 
CSUGDENAuthor Commented:
Sorry about the exclusion

                       <tr>
                            <td><asp:Label ID="Label4" runat="server" Text="Invoice Id:" CssClass="LabelWidthRight"></asp:Label></td>
                            <td><asp:TextBox ID="txtInvoiceId" runat="server" CssClass="textentry" ViewStateMode="Enabled"></asp:TextBox></td>
                        </tr>

Using a table within a master page
0
 
CSUGDENAuthor Commented:
The div is necessary to hide or make the calendar appear without a page turn
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
leakim971PluritechnicianCommented:
if you remove all your stuff about visibility and ZERO javascript, do your code put the date in the textbox ?
0
 
CSUGDENAuthor Commented:
Nice try. That doesn't work. Something has to make the div holding the calendar disappear
Originally I used a panel but I  didn't like the response going back to the server
so I changed the panel to a div and wanted to use jquery.

Now that I have removed the jquery the div needs to appear

<asp:Label ID="LabelInv" runat="server" Text="Invoice Date:" CssClass="LabelWidthRight"></asp:Label>
<asp:TextBox ID="txtInvoiceDate" runat="server" CssClass="textentry"></asp:TextBox>
<img alt="O" src="Images/Calendar-BusinessMonthView_16.png" class="BtnSpacerSmall" onclick='???'/>
0
 
leakim971PluritechnicianCommented:
Now that I have removed the jquery the div needs to appear

1 - By default the div MUST appear.
2 - ASAP you hide it with javascript or css

But again, it MUST be VISIBLE by default.
0
 
CSUGDENAuthor Commented:
I resorted to the calendarexetender enclosed within a panel.
As explained, the panel had to be visible by default in order for this to work.
The control did not appear until the button was clicked even though the panel was initially visible.
So the solution worked.
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now