Showing posts with label setfocus. Show all posts
Showing posts with label setfocus. Show all posts

Monday, March 26, 2012

set focus

hi..suppose there is only one textbox in the form and one command
button...
can anyone tell me how can i setfocus of textbox when page is load?
should i do that by java script?please send me coding how to do that?
and can anyone tell me how can i send mail to the group of user?and how
can i add user in the vb.net?
i am developing one web application for one designing institute and
they want mailing facility so if i send one mail then all the member of
institute get that mail and for that i am supposed to create one group
for that...and any member can leave any time and one can be a member
of the institute so no of user are not fixed so tell me how can i do?i
did coding for sending one mail to the single user but i don't know how
to do for the group?should i take one array?please send me the code
snippet and it's better if it's in visual basic and not asp..thanks a
lot in advance
NilIf you are in 2.0, use method SetFocus.
In 1.1 you need to do it in with javascript in the body's onload event.
And it is always a good idea to post different questions in separate
threads.
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"nil" <NileshThakker786@.gmail.com> wrote in message
news:1165315092.234534.218860@.73g2000cwn.googlegroups.com...
> hi..suppose there is only one textbox in the form and one command
> button...
> can anyone tell me how can i setfocus of textbox when page is load?
> should i do that by java script?please send me coding how to do that?
>
> and can anyone tell me how can i send mail to the group of user?and how
> can i add user in the vb.net?
> i am developing one web application for one designing institute and
> they want mailing facility so if i send one mail then all the member of
> institute get that mail and for that i am supposed to create one group
> for that...and any member can leave any time and one can be a member
> of the institute so no of user are not fixed so tell me how can i do?i
> did coding for sending one mail to the single user but i don't know how
> to do for the group?should i take one array?please send me the code
> snippet and it's better if it's in visual basic and not asp..thanks a
> lot in advance
>
> Nil
>
Nil,
Eliyahu is right on. Here's what the javascript would look like if you are
using the 1.1 framework:
<script type='text/javascript'>
textbox = document. getElementById('[Replacewithnameofcontro
l]');
if (textbox)
{
textbox.focus();
}
else
{
// The textbox doesn't exist you have an error
}
</script>
If you are using the 2.0 framework you can do what Eliyahu mentioned or you
could do it this way:
Page.SetFocus(control);
Note: You must call this on or before the PreRender event.
Nick Wegner
"Eliyahu Goldin" wrote:

> If you are in 2.0, use method SetFocus.
> In 1.1 you need to do it in with javascript in the body's onload event.
> And it is always a good idea to post different questions in separate
> threads.
> --
> Eliyahu Goldin,
> Software Developer & Consultant
> Microsoft MVP [ASP.NET]
>
> "nil" <NileshThakker786@.gmail.com> wrote in message
> news:1165315092.234534.218860@.73g2000cwn.googlegroups.com...
>
>
Sorry Eliyahu, I meant to say that in 2.0 he could also use control.focus().
Didn't mean to repeat you...
Nick Wegner
"Nick Wegner" wrote:
> Nil,
> Eliyahu is right on. Here's what the javascript would look like if you ar
e
> using the 1.1 framework:
> <script type='text/javascript'>
> textbox = document. getElementById('[Replacewithnameofcontro
l]');
> if (textbox)
> {
> textbox.focus();
> }
> else
> {
> // The textbox doesn't exist you have an error
> }
> </script>
> If you are using the 2.0 framework you can do what Eliyahu mentioned or yo
u
> could do it this way:
> Page.SetFocus(control);
> Note: You must call this on or before the PreRender event.
> --
> Nick Wegner
>
> "Eliyahu Goldin" wrote:
>

Set Focus

How do you set the focus to a text box in ASP .NET? ASP Text boxes don't have a focus or setfocus method.Spot on.
Javascript has a "focus" function call :)

Something likedocument.getElementById('txtUsername').focus();

set focus

hi..suppose there is only one textbox in the form and one command
button...
can anyone tell me how can i setfocus of textbox when page is load?
should i do that by java script?please send me coding how to do that?

and can anyone tell me how can i send mail to the group of user?and how
can i add user in the vb.net?
i am developing one web application for one designing institute and
they want mailing facility so if i send one mail then all the member of
institute get that mail and for that i am supposed to create one group
for that...and any member can leave any time and one can be a member
of the institute so no of user are not fixed so tell me how can i do?i
did coding for sending one mail to the single user but i don't know how
to do for the group?should i take one array?please send me the code
snippet and it's better if it's in visual basic and not asp..thanks a
lot in advance

NilIf you are in 2.0, use method SetFocus.

In 1.1 you need to do it in with javascript in the body's onload event.

And it is always a good idea to post different questions in separate
threads.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

"nil" <NileshThakker786@.gmail.comwrote in message
news:1165315092.234534.218860@.73g2000cwn.googlegro ups.com...

Quote:

Originally Posted by

hi..suppose there is only one textbox in the form and one command
button...
can anyone tell me how can i setfocus of textbox when page is load?
should i do that by java script?please send me coding how to do that?
>
>
and can anyone tell me how can i send mail to the group of user?and how
can i add user in the vb.net?
i am developing one web application for one designing institute and
they want mailing facility so if i send one mail then all the member of
institute get that mail and for that i am supposed to create one group
for that...and any member can leave any time and one can be a member
of the institute so no of user are not fixed so tell me how can i do?i
did coding for sending one mail to the single user but i don't know how
to do for the group?should i take one array?please send me the code
snippet and it's better if it's in visual basic and not asp..thanks a
lot in advance
>
>
>
Nil
>


Sorry Eliyahu, I meant to say that in 2.0 he could also use control.focus().
Didn't mean to repeat you...

--
Nick Wegner

"Nick Wegner" wrote:

Quote:

Originally Posted by

Nil,
>
Eliyahu is right on. Here's what the javascript would look like if you are
using the 1.1 framework:
>
<script type='text/javascript'>
textbox = document.getElementById('[Replacewithnameofcontrol]');
if (textbox)
{
textbox.focus();
}
else
{
// The textbox doesn't exist you have an error
}
</script>
>
If you are using the 2.0 framework you can do what Eliyahu mentioned or you
could do it this way:
>
Page.SetFocus(control);
>
Note: You must call this on or before the PreRender event.
>
--
Nick Wegner
>
>
>
"Eliyahu Goldin" wrote:
>

Quote:

Originally Posted by

If you are in 2.0, use method SetFocus.

In 1.1 you need to do it in with javascript in the body's onload event.

And it is always a good idea to post different questions in separate
threads.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

"nil" <NileshThakker786@.gmail.comwrote in message
news:1165315092.234534.218860@.73g2000cwn.googlegro ups.com...

Quote:

Originally Posted by

hi..suppose there is only one textbox in the form and one command
button...
can anyone tell me how can i setfocus of textbox when page is load?
should i do that by java script?please send me coding how to do that?
>
>
and can anyone tell me how can i send mail to the group of user?and how
can i add user in the vb.net?
i am developing one web application for one designing institute and
they want mailing facility so if i send one mail then all the member of
institute get that mail and for that i am supposed to create one group
for that...and any member can leave any time and one can be a member
of the institute so no of user are not fixed so tell me how can i do?i
did coding for sending one mail to the single user but i don't know how
to do for the group?should i take one array?please send me the code
snippet and it's better if it's in visual basic and not asp..thanks a
lot in advance
>
>
>
Nil
>


Saturday, March 24, 2012

Set focus and cursor at end of text?

I use this code to set focus to a textbox when I load a page:

private void SetFocus(System.Web.UI.Control ctrl)
{
string s = "<SCRIPT language=\"javascript\">document.getElementById('" +
ctrl.ID + "').focus()</SCRIPT>";

RegisterStartupScript("focus", s);
}

I would also like the cursor to be positioned at the end of the text field.
Using only the above code, the cursor is positioned at the beginning of the
textbox even if there are some text present in the field.

How can I position the cusrsor at the end of the text?

OlavOlav,

Here we go:

Create a new function in your <head> tag in the HTML section:

function SetEnd (TB)
{
if (TB.createTextRange)
{
var FieldRange = TB.createTextRange();
FieldRange.moveStart('character', TB.value.length);
FieldRange.collapse();
FieldRange.select();
}
}

Create a new onfocus JavaScript event in your asp text box tag (asp:textBox)
that calls the SetEnd function above:

<asp:textbox id="TextBox1" runat="server" Width="65px"
onfocus="SetEnd(this)">Existing text</asp:textbox
Make sure you keep your existing code that calls the SetFocus function as it
is:

private void SetFocus(System.Web.UI.Control ctrl)
{
string s = "<SCRIPT language=\"javascript\">document.getElementById('" +
ctrl.ID + "').focus()</SCRIPT>";

RegisterStartupScript("focus", s);
}

Don't forget to call the above SetFocus() function in your Body tag on page
load ....( <body onload="SetFocus()"> )

Good luck!

Regards,

Mohammad Samara.

ICS (London) Ltd.

"Olav Tollefsen" <x@.y.com> wrote in message
news:uxrxLYt3DHA.3656@.TK2MSFTNGP11.phx.gbl...
> I use this code to set focus to a textbox when I load a page:
> private void SetFocus(System.Web.UI.Control ctrl)
> {
> string s = "<SCRIPT language=\"javascript\">document.getElementById('" +
> ctrl.ID + "').focus()</SCRIPT>";
> RegisterStartupScript("focus", s);
> }
> I would also like the cursor to be positioned at the end of the text
field.
> Using only the above code, the cursor is positioned at the beginning of
the
> textbox even if there are some text present in the field.
> How can I position the cusrsor at the end of the text?
> Olav

set focus in text box

Hi, id like to set focus for a text box in my web form but I dont know how. the text boxes do not have a setFocus or a Focus method

Thanks!!

myTextBox.select(); <<<< JavaScript
we use the following function which injects client side script

PublicSharedSub Set_Focus(ByVal aspPageAs System.Web.UI.Page,ByVal strControlNameAsString)

Try

Dim strScriptAsString

strScript ="<script language=javascript> document.all.item(""" & strControlName &""").focus() </script>"

aspPage.RegisterStartupScript("focus", strScript)

Catch exAs Exception
Throw ex
EndTry
EndSub

following then to call you would simply say:- Set_Focus(Me.Page,"txtMyTextbox")


In .NET 2.0, the Focus() method will set focus if you want to do it from code-beside.

HTH,
Ryan

set focus on postback/textchanged

I'm setting focus depenting upon which field has changed value. I'm doing
this with the following: Page.RegisterStartupScript("SetFocus", "<script
language=""Jscript"" > document.getElementById(""txtCity"").focus();
</Script>"). This is being called on the textChanged event for textboxes. fo
r
city it goes to state for state it goes to zip, ...
It works, but is this the correct way to do this or should this be a seties
of if then else's in he page load? if so, how can i isolate the textbox that
caused the event?
thanks
kesYou can change the javascript you have below to generate the name of the
control that caused the event:
Page.RegisterStartupScript("SetFocus", "<script language='Jscript'>
document.getElementById(" + controlName + ").focus(); </Script>").
in the "Changed" event of the control just set the "controlName" variable to
the required javascript id for the control:
i.e. for the txtCity changed event:
controlName = "txtCity";
I'm assuming that you are calling the Page.RegisterStartupScript() function
in the "Render" event of the page - you'll need to remember that because the
"Render" is called after the "Changed" event and thats what you want, if you
put the Page.RegisterStartupScript() in the Page_Load() by mistake, then the
"controlName" variable will not be assigned a value yet.
"Kurt Schroeder" wrote:

> I'm setting focus depenting upon which field has changed value. I'm doing
> this with the following: Page.RegisterStartupScript("SetFocus", "<script
> language=""Jscript"" > document.getElementById(""txtCity"").focus();
> </Script>"). This is being called on the textChanged event for textboxes.
for
> city it goes to state for state it goes to zip, ...
> It works, but is this the correct way to do this or should this be a setie
s
> of if then else's in he page load? if so, how can i isolate the textbox th
at
> caused the event?
> thanks
> kes
Thank you for replying!
i have the function call in each of the respective controls' changed event
:
Example:
Private Sub txtbAdr1_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles txtbAdr1.TextChanged
If chkShipSame.Checked Then
txtSadr1.Text = txtbAdr1.Text
Page.RegisterStartupScript("SetFocus", "<script
language=""Javascript"" > document.getElementById(""txtbadr2"").focus();
</Script>")
End If
End Sub
In vS.net i could not find the Render event under page, but i'm still
learning this. as well as JavaScript. I see PreRender, but not render.
1. My guess is the funtion calls are not in the right place, but should only
be one function call in the Render event?
2. where can i find Render?
3. the controlname variable is this a simple .net string variable or a
javascript variable?
Thanks
kes
"Jorge L Matos [MCSD.NET]" wrote:
> You can change the javascript you have below to generate the name of the
> control that caused the event:
> Page.RegisterStartupScript("SetFocus", "<script language='Jscript'>
> document.getElementById(" + controlName + ").focus(); </Script>").
> in the "Changed" event of the control just set the "controlName" variable
to
> the required javascript id for the control:
> i.e. for the txtCity changed event:
> controlName = "txtCity";
> I'm assuming that you are calling the Page.RegisterStartupScript() functio
n
> in the "Render" event of the page - you'll need to remember that because t
he
> "Render" is called after the "Changed" event and thats what you want, if y
ou
> put the Page.RegisterStartupScript() in the Page_Load() by mistake, then t
he
> "controlName" variable will not be assigned a value yet.
> "Kurt Schroeder" wrote:
>
Sorry, I meant the "PreRender" event, not the "Render".
Answers:
1. Yes, but use "PreRender" not "Render"
2. Don't worry about Render
3. The controlName variable is a field of the "Page" class that you create
and all the "Change" events can set it to the javascript ID of the control.
The page events are typically executed in the following order:
a) Init
b) Load
c) Change Events
d) Click Events
e) PreRender
f) Render
REF:
http://msdn.microsoft.com/library/d...onlifecycle.asp
ASP.NET 2.0 will have an enhanced page event life cycle with more events
that you can hook into.
"Kurt Schroeder" wrote:
> Thank you for replying!
> i have the function call in each of the respective controls' changed eve
nt:
> Example:
> Private Sub txtbAdr1_TextChanged(ByVal sender As System.Object, ByVal
e
> As System.EventArgs) Handles txtbAdr1.TextChanged
> If chkShipSame.Checked Then
> txtSadr1.Text = txtbAdr1.Text
> Page.RegisterStartupScript("SetFocus", "<script
> language=""Javascript"" > document.getElementById(""txtbadr2"").focus();
> </Script>")
> End If
> End Sub
> In vS.net i could not find the Render event under page, but i'm still
> learning this. as well as JavaScript. I see PreRender, but not render.
> 1. My guess is the funtion calls are not in the right place, but should on
ly
> be one function call in the Render event?
> 2. where can i find Render?
> 3. the controlname variable is this a simple .net string variable or a
> javascript variable?
> Thanks
> kes
> "Jorge L Matos [MCSD.NET]" wrote:
>

set focus on postback/textchanged

I'm setting focus depenting upon which field has changed value. I'm doing
this with the following: Page.RegisterStartupScript("SetFocus", "<script
language=""Jscript"" > document.getElementById(""txtCity"").focus();
</Script>"). This is being called on the textChanged event for textboxes. for
city it goes to state for state it goes to zip, ...
It works, but is this the correct way to do this or should this be a seties
of if then else's in he page load? if so, how can i isolate the textbox that
caused the event?

thanks
kesYou can change the javascript you have below to generate the name of the
control that caused the event:

Page.RegisterStartupScript("SetFocus", "<script language='Jscript'>
document.getElementById(" + controlName + ").focus(); </Script>").

in the "Changed" event of the control just set the "controlName" variable to
the required javascript id for the control:

i.e. for the txtCity changed event:

controlName = "txtCity";

I'm assuming that you are calling the Page.RegisterStartupScript() function
in the "Render" event of the page - you'll need to remember that because the
"Render" is called after the "Changed" event and thats what you want, if you
put the Page.RegisterStartupScript() in the Page_Load() by mistake, then the
"controlName" variable will not be assigned a value yet.

"Kurt Schroeder" wrote:

> I'm setting focus depenting upon which field has changed value. I'm doing
> this with the following: Page.RegisterStartupScript("SetFocus", "<script
> language=""Jscript"" > document.getElementById(""txtCity"").focus();
> </Script>"). This is being called on the textChanged event for textboxes. for
> city it goes to state for state it goes to zip, ...
> It works, but is this the correct way to do this or should this be a seties
> of if then else's in he page load? if so, how can i isolate the textbox that
> caused the event?
> thanks
> kes
Thank you for replying!

i have the function call in each of the respective controls' changed event:
Example:
Private Sub txtbAdr1_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles txtbAdr1.TextChanged
If chkShipSame.Checked Then
txtSadr1.Text = txtbAdr1.Text
Page.RegisterStartupScript("SetFocus", "<script
language=""Javascript"" > document.getElementById(""txtbadr2"").focus();
</Script>")
End If
End Sub

In vS.net i could not find the Render event under page, but i'm still
learning this. as well as JavaScript. I see PreRender, but not render.
1. My guess is the funtion calls are not in the right place, but should only
be one function call in the Render event?
2. where can i find Render?
3. the controlname variable is this a simple .net string variable or a
javascript variable?
Thanks
kes

"Jorge L Matos [MCSD.NET]" wrote:

> You can change the javascript you have below to generate the name of the
> control that caused the event:
> Page.RegisterStartupScript("SetFocus", "<script language='Jscript'>
> document.getElementById(" + controlName + ").focus(); </Script>").
> in the "Changed" event of the control just set the "controlName" variable to
> the required javascript id for the control:
> i.e. for the txtCity changed event:
> controlName = "txtCity";
> I'm assuming that you are calling the Page.RegisterStartupScript() function
> in the "Render" event of the page - you'll need to remember that because the
> "Render" is called after the "Changed" event and thats what you want, if you
> put the Page.RegisterStartupScript() in the Page_Load() by mistake, then the
> "controlName" variable will not be assigned a value yet.
> "Kurt Schroeder" wrote:
> > I'm setting focus depenting upon which field has changed value. I'm doing
> > this with the following: Page.RegisterStartupScript("SetFocus", "<script
> > language=""Jscript"" > document.getElementById(""txtCity"").focus();
> > </Script>"). This is being called on the textChanged event for textboxes. for
> > city it goes to state for state it goes to zip, ...
> > It works, but is this the correct way to do this or should this be a seties
> > of if then else's in he page load? if so, how can i isolate the textbox that
> > caused the event?
> > thanks
> > kes
Sorry, I meant the "PreRender" event, not the "Render".

Answers:
1. Yes, but use "PreRender" not "Render"
2. Don't worry about Render
3. The controlName variable is a field of the "Page" class that you create
and all the "Change" events can set it to the javascript ID of the control.

The page events are typically executed in the following order:
a) Init
b) Load
c) Change Events
d) Click Events
e) PreRender
f) Render

REF:
http://msdn.microsoft.com/library/d...onlifecycle.asp

ASP.NET 2.0 will have an enhanced page event life cycle with more events
that you can hook into.

"Kurt Schroeder" wrote:

> Thank you for replying!
> i have the function call in each of the respective controls' changed event:
> Example:
> Private Sub txtbAdr1_TextChanged(ByVal sender As System.Object, ByVal e
> As System.EventArgs) Handles txtbAdr1.TextChanged
> If chkShipSame.Checked Then
> txtSadr1.Text = txtbAdr1.Text
> Page.RegisterStartupScript("SetFocus", "<script
> language=""Javascript"" > document.getElementById(""txtbadr2"").focus();
> </Script>")
> End If
> End Sub
> In vS.net i could not find the Render event under page, but i'm still
> learning this. as well as JavaScript. I see PreRender, but not render.
> 1. My guess is the funtion calls are not in the right place, but should only
> be one function call in the Render event?
> 2. where can i find Render?
> 3. the controlname variable is this a simple .net string variable or a
> javascript variable?
> Thanks
> kes
> "Jorge L Matos [MCSD.NET]" wrote:
> > You can change the javascript you have below to generate the name of the
> > control that caused the event:
> > Page.RegisterStartupScript("SetFocus", "<script language='Jscript'>
> > document.getElementById(" + controlName + ").focus(); </Script>").
> > in the "Changed" event of the control just set the "controlName" variable to
> > the required javascript id for the control:
> > i.e. for the txtCity changed event:
> > controlName = "txtCity";
> > I'm assuming that you are calling the Page.RegisterStartupScript() function
> > in the "Render" event of the page - you'll need to remember that because the
> > "Render" is called after the "Changed" event and thats what you want, if you
> > put the Page.RegisterStartupScript() in the Page_Load() by mistake, then the
> > "controlName" variable will not be assigned a value yet.
> > "Kurt Schroeder" wrote:
> > > I'm setting focus depenting upon which field has changed value. I'm doing
> > > this with the following: Page.RegisterStartupScript("SetFocus", "<script
> > > language=""Jscript"" > document.getElementById(""txtCity"").focus();
> > > </Script>"). This is being called on the textChanged event for textboxes. for
> > > city it goes to state for state it goes to zip, ...
> > > It works, but is this the correct way to do this or should this be a seties
> > > of if then else's in he page load? if so, how can i isolate the textbox that
> > > caused the event?
> > > > thanks
> > > kes