Monday, March 26, 2012
Set focus
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).
Thursday, March 22, 2012
Set HTML Attribute In Page_Load Event
Page_Load event. I can't see how to do this. The main problem is that I
can't see how to access the HTML object from this event. Can anyone help ?
BenBen,
Forthe element you need to specify runat=server and id=myHtml. Then VS will
define the element for you in code-behind as the page's protected member. In
any page method you can set an attribute as (c# syntax):
myHtml.Attributes["myAttribute"]="my string";
Eliyahu
"Ben Foster" <ben.foster@.nospam.com> wrote in message
news:OozPcRBGFHA.2180@.TK2MSFTNGP10.phx.gbl...
> I want to be able to set an attribute of the HTML object in the form's
> Page_Load event. I can't see how to do this. The main problem is that I
> can't see how to access the HTML object from this event. Can anyone help ?
> Ben
Eliyahu,
That works fine. Thanks.
Ben
"Eliyahu Goldin" <removemeegoldin@.monarchmed.com> wrote in message
news:%23TIxNYBGFHA.3244@.TK2MSFTNGP15.phx.gbl...
> Ben,
> Forthe element you need to specify runat=server and id=myHtml. Then VS
> will
> define the element for you in code-behind as the page's protected member.
> In
> any page method you can set an attribute as (c# syntax):
> myHtml.Attributes["myAttribute"]="my string";
> Eliyahu
> "Ben Foster" <ben.foster@.nospam.com> wrote in message
> news:OozPcRBGFHA.2180@.TK2MSFTNGP10.phx.gbl...
>> I want to be able to set an attribute of the HTML object in the form's
>> Page_Load event. I can't see how to do this. The main problem is that I
>> can't see how to access the HTML object from this event. Can anyone help
>> ?
>>
>> Ben
>>
>>
Set HTML Attribute In Page_Load Event
Page_Load event. I can't see how to do this. The main problem is that I
can't see how to access the HTML object from this event. Can anyone help ?
BenBen,
Forthe element you need to specify runat=server and id=myHtml. Then VS will
define the element for you in code-behind as the page's protected member. In
any page method you can set an attribute as (c# syntax):
myHtml.Attributes["myAttribute"]="my string";
Eliyahu
"Ben Foster" <ben.foster@.nospam.com> wrote in message
news:OozPcRBGFHA.2180@.TK2MSFTNGP10.phx.gbl...
> I want to be able to set an attribute of the HTML object in the form's
> Page_Load event. I can't see how to do this. The main problem is that I
> can't see how to access the HTML object from this event. Can anyone help ?
> Ben
>
Eliyahu,
That works fine. Thanks.
Ben
"Eliyahu Goldin" <removemeegoldin@.monarchmed.com> wrote in message
news:%23TIxNYBGFHA.3244@.TK2MSFTNGP15.phx.gbl...
> Ben,
> Forthe element you need to specify runat=server and id=myHtml. Then VS
> will
> define the element for you in code-behind as the page's protected member.
> In
> any page method you can set an attribute as (c# syntax):
> myHtml.Attributes["myAttribute"]="my string";
> Eliyahu
> "Ben Foster" <ben.foster@.nospam.com> wrote in message
> news:OozPcRBGFHA.2180@.TK2MSFTNGP10.phx.gbl...
>
Set mode in FormView on Page_Load
this code:
Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
FormView1.ChangeMode(FormViewMode.Insert)
End Sub
If I click the New button on the form everything works but not with
code.
Can someone please help me?
Regards,
Stry
Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) handles Me.Load
Try this inside your Page_Load:
If (Not IsPostBack) Then
FormView1.DefaultMode = FormViewMode.Insert
End If
Then again, I'm not sure if you're showing enough code.
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."
<staeri@.gmail.com> wrote in message
news:1144144823.902803.185090@.i39g2000cwa.googlegroups.com...
> I'm trying to set the FormView in insert mode but nothing happens with
> this code:
> Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
> FormView1.ChangeMode(FormViewMode.Insert)
> End Sub
> If I click the New button on the form everything works but not with
> code.
> Can someone please help me?
> Regards,
> S
>
Set mode in FormView on Page_Load
this code:
Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
FormView1.ChangeMode(FormViewMode.Insert)
End Sub
If I click the New button on the form everything works but not with
code.
Can someone please help me?
Regards,
Stry
Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) handles Me.Load
Try this inside your Page_Load:
If (Not IsPostBack) Then
FormView1.DefaultMode = FormViewMode.Insert
End If
Then again, I'm not sure if you're showing enough code.
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."
<staeri@.gmail.com> wrote in message
news:1144144823.902803.185090@.i39g2000cwa.googlegr oups.com...
> I'm trying to set the FormView in insert mode but nothing happens with
> this code:
> Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
> FormView1.ChangeMode(FormViewMode.Insert)
> End Sub
> If I click the New button on the form everything works but not with
> code.
> Can someone please help me?
> Regards,
> S