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:
>
0 comments:
Post a Comment