Showing posts with label shown. Show all posts
Showing posts with label shown. Show all posts

Thursday, March 29, 2012

set date on calendar in a FormView template

Hi,

My calendar is inside a FormView template as users are entering new dates.

I want the month shown to be the same as the last one they entered, but after an Insert, the control revert back to the current month.

I can fetch the moth via SQL or stoer in a cookie, but I don't know how to access the control, as it's embedded in the FormVIew.

Thanks if you can help.

NEIL

1protected void myFormView_DataBound(object sender, EventArgs e)2 {3 Calendar myCal = (Calendar)myFormView.FindControl("myCalendar");4// set the Visible Date in the calendar to the Current Month5 myCal.VisibleDate = DateTime.Now();6 }

Line 3 finds the Calendar Control within the FormView.

Line 5 sets the VisibleDate property of the calendar to the Current Month, or whatever date you want to place on the right side of the =.


Hi,

I'm writing in VB, can you translate?

Cheers,

NEIL


1Protected Sub FormView1_DataBound(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles FormView1.DataBound2Dim myCalAs Calendar =CType(FormView1.FindControl("myCalendar"), Calendar)3 myCal.VisibleDate = DateTime.Now4End Sub
 
If this is what you needed, please mark it as your answer...Thanks!!
 

Monday, March 26, 2012

Set focus

When my page is shown, I want the first textfield to have the focus. I found somewhere a solution for this :

in the page_load I call a routine :

SetFocusControl(Page, Me.txtNr.ID.ToString)

... and the SetFocusControl-routine :

Public Sub SetFocusControl(ByRef Pagina As System.Web.UI.Page,
ByVal ControlName As String)
' character 34 = "

Dim script As String = _
"<script language=" + Chr(34) + "javascript" + Chr(34) _
+ ">" + _
" var control = document.getElementById(" + Chr(34) + _
ControlName + Chr(34) + ");" & _
" if( control != null ){control.select();}" & _
"</script>"

Pagina.RegisterStartupScript("Focus", script)

End Sub

Now, all this works fine (field gets the focus and the whole contents is selected), but when I push TAB the focus goes to the Address-bar instead of the second textfield ??

Any idea why ? Are is there another 'better' solution to do this ?You need to set the tabindex property for each control on the page.

DJ
I don't know if this works, but I wonder why I haven't any problem when I go manualy (with mouse-click) to this first field and push on the TAB (this results correctly to the next field) ? So why not the first time ?

PS : all tabindexes are set to 0 for the moment.
In IE the address bar (unless otherwise specified) is the first to go to when you press tab. So I'm presuming because you haven't set tabindexes it will revert to the address bar again. Give it a try changing the tabindexes - I'm sure thats the problem.

DJ
Sorry, it's a long time ago but I become a father meanwhile...

I fill in the tabindex (login, password, persistent cookie and submit button), but it still goes to the address bar :cry:

Here's the HTML :

<body>
<form id="Form1" method="post" runat="server">
<H1 align="left"><FONT size="7"><IMG src="http://pics.10026.com/?src=Images/PROFORTRA.jpg"></FONT></H1>
<H1 align="left"><FONT size="7">Welcome</FONT></H1>
<H2 align="left">To access this site you have to log on first.</H2>
<P>
<TABLE class="TABLE" id="tlbLogin" style="WIDTH: 560px; HEIGHT: 130px" cellSpacing="1"
cellPadding="1" width="560" border="0">
<TR>
<TD style="WIDTH: 91px">Username
</TD>
<TD><asp:textbox id="UserName" tabIndex="1" runat="server" BackColor="LightGray" Width="160px"></asp:textbox> <asp:requiredfieldvalidator id="reqUserName" runat="server" ErrorMessage="Username is required !" ControlToValidate="UserName"></asp:requiredfieldvalidator></TD>
</TR>
<TR>
<TD style="WIDTH: 91px">Password</TD>
<TD><asp:textbox id="PassWord" tabIndex="2" runat="server" BackColor="LightGray" Width="160px" TextMode="Password"></asp:textbox> <asp:requiredfieldvalidator id="reqPassWord" runat="server" ErrorMessage="Password is required !" ControlToValidate="PassWord"></asp:requiredfieldvalidator></TD>
</TR>
<tr>
<td>Persistent Cookie</td>
<td><ASP:CHECKBOX id="Persist" tabIndex="3" runat="server"></ASP:CHECKBOX></td>
</tr>
</TABLE>
</P>
<P><asp:label id="lblFout" runat="server" ForeColor="Red" Font-Size="Medium"></asp:label></P>
<P><asp:button id="btnLogOn" tabIndex="4" runat="server" Text="Log On"></asp:button></P>
</form>
</body>
First off - congratulations!

Secondly - does this happen in all browsers?

DJ
Thx !

Since I'm just starting, I just try it on my notebook with IE (version 6.0.2900.2180).