script for focus

  • Thread starter Thread starter selen
  • Start date Start date
S

selen

I am using above script for Focus to txtAdi which is textbox in c# web
application.But it doesnt work.

Have you any idea why it doesnt work

thanks.......



char c=(char)34;

string script =

"<script language=" + c + "javascript" + c

+ ">" +

" var control = document.getElementById(" + c +

txtAdi + c + ");" +

" if( control != null ){control.focus();}" +

"</script>";

Page.RegisterStartupScript("Focus", script);
 
selen,

If the script is before all of the document elements, then it will get
executed, and it will not know where the element is, because the element
doesn't exist yet (the document hasn't been rendered).

What you want to do is have the javascript registered with the onload
event for the body, having it call your code when the body is loaded. That
way, the document object model has been set up, and you can access the
elements in your script.

Hope this helps.
 
My code is in button's click event.I want When I click the button set focus
to textbox name is txtAdi.But It odesnt work...

iletide said:
selen,

If the script is before all of the document elements, then it will get
executed, and it will not know where the element is, because the element
doesn't exist yet (the document hasn't been rendered).

What you want to do is have the javascript registered with the onload
event for the body, having it call your code when the body is loaded. That
way, the document object model has been set up, and you can access the
elements in your script.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

selen said:
I am using above script for Focus to txtAdi which is textbox in c# web
application.But it doesnt work.

Have you any idea why it doesnt work

thanks.......



char c=(char)34;

string script =

"<script language=" + c + "javascript" + c

+ ">" +

" var control = document.getElementById(" + c +

txtAdi + c + ");" +

" if( control != null ){control.focus();}" +

"</script>";

Page.RegisterStartupScript("Focus", script);
 
selen,

I also notice that you don't have this script in a function. How are
you linking the button click event to the script?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

selen said:
My code is in button's click event.I want When I click the button set focus
to textbox name is txtAdi.But It odesnt work...

"Nicholas Paldino [.NET/C# MVP]" <[email protected]>, iletide
þunu yazdý news:[email protected]...
selen,

If the script is before all of the document elements, then it will get
executed, and it will not know where the element is, because the element
doesn't exist yet (the document hasn't been rendered).

What you want to do is have the javascript registered with the onload
event for the body, having it call your code when the body is loaded. That
way, the document object model has been set up, and you can access the
elements in your script.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

selen said:
I am using above script for Focus to txtAdi which is textbox in c# web
application.But it doesnt work.

Have you any idea why it doesnt work

thanks.......



char c=(char)34;

string script =

"<script language=" + c + "javascript" + c

+ ">" +

" var control = document.getElementById(" + c +

txtAdi + c + ");" +

" if( control != null ){control.focus();}" +

"</script>";

Page.RegisterStartupScript("Focus", script);
 
I am writind direct inside of button Click event.
Before I wrote above script.It worked.But this doesnt work.My button isnt
html button.I am using
c#.net
string strScript;

strScript = "<script>";

strScript = strScript + "alert('Rol Adýný Girmelisiniz.');";

strScript = strScript + "</script>";

Page.RegisterStartupScript("ClientScript", strScript);


iletide said:
selen,

I also notice that you don't have this script in a function. How are
you linking the button click event to the script?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

selen said:
My code is in button's click event.I want When I click the button set focus
to textbox name is txtAdi.But It odesnt work...

"Nicholas Paldino [.NET/C# MVP]" <[email protected]>, iletide
þunu yazdý news:[email protected]...
selen,

If the script is before all of the document elements, then it will get
executed, and it will not know where the element is, because the element
doesn't exist yet (the document hasn't been rendered).

What you want to do is have the javascript registered with the onload
event for the body, having it call your code when the body is loaded. That
way, the document object model has been set up, and you can access the
elements in your script.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I am using above script for Focus to txtAdi which is textbox in c# web
application.But it doesnt work.

Have you any idea why it doesnt work

thanks.......



char c=(char)34;

string script =

"<script language=" + c + "javascript" + c

+ ">" +

" var control = document.getElementById(" + c +

txtAdi + c + ");" +

" if( control != null ){control.focus();}" +

"</script>";

Page.RegisterStartupScript("Focus", script);
 
selen,

Yes, and your script doesn't have any function declaration around it.
How are you hooking up the event handler to the button? It doesn't make
sense.

How is the script being rendered on the client? How do you perform the
hookup between the button and the script itself.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

selen said:
I am writind direct inside of button Click event.
Before I wrote above script.It worked.But this doesnt work.My button isnt
html button.I am using
c#.net
string strScript;

strScript = "<script>";

strScript = strScript + "alert('Rol Adýný Girmelisiniz.');";

strScript = strScript + "</script>";

Page.RegisterStartupScript("ClientScript", strScript);


"Nicholas Paldino [.NET/C# MVP]" <[email protected]>, iletide
þunu yazdý news:%[email protected]...
selen,

I also notice that you don't have this script in a function. How are
you linking the button click event to the script?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

selen said:
My code is in button's click event.I want When I click the button set focus
to textbox name is txtAdi.But It odesnt work...

"Nicholas Paldino [.NET/C# MVP]" <[email protected]>, iletide
þunu yazdý selen,

If the script is before all of the document elements, then it
will
get
executed, and it will not know where the element is, because the element
doesn't exist yet (the document hasn't been rendered).

What you want to do is have the javascript registered with the onload
event for the body, having it call your code when the body is loaded.
That
way, the document object model has been set up, and you can access the
elements in your script.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I am using above script for Focus to txtAdi which is textbox in c# web
application.But it doesnt work.

Have you any idea why it doesnt work

thanks.......



char c=(char)34;

string script =

"<script language=" + c + "javascript" + c

+ ">" +

" var control = document.getElementById(" + c +

txtAdi + c + ");" +

" if( control != null ){control.focus();}" +

"</script>";

Page.RegisterStartupScript("Focus", script);
 
I think I coundnt do it.I dont understand anything:(((.can you give me
example.

Thanks


iletide said:
selen,

Yes, and your script doesn't have any function declaration around it.
How are you hooking up the event handler to the button? It doesn't make
sense.

How is the script being rendered on the client? How do you perform the
hookup between the button and the script itself.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

selen said:
I am writind direct inside of button Click event.
Before I wrote above script.It worked.But this doesnt work.My button isnt
html button.I am using
c#.net
string strScript;

strScript = "<script>";

strScript = strScript + "alert('Rol Adýný Girmelisiniz.');";

strScript = strScript + "</script>";

Page.RegisterStartupScript("ClientScript", strScript);


"Nicholas Paldino [.NET/C# MVP]" <[email protected]>, iletide
þunu yazdý news:%[email protected]...
selen,

I also notice that you don't have this script in a function. How are
you linking the button click event to the script?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

My code is in button's click event.I want When I click the button set
focus
to textbox name is txtAdi.But It odesnt work...

"Nicholas Paldino [.NET/C# MVP]" <[email protected]>,
iletide
þunu yazdý selen,

If the script is before all of the document elements, then it will
get
executed, and it will not know where the element is, because the element
doesn't exist yet (the document hasn't been rendered).

What you want to do is have the javascript registered with the
onload
event for the body, having it call your code when the body is loaded.
That
way, the document object model has been set up, and you can access the
elements in your script.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I am using above script for Focus to txtAdi which is textbox in
c#
web
application.But it doesnt work.

Have you any idea why it doesnt work

thanks.......



char c=(char)34;

string script =

"<script language=" + c + "javascript" + c

+ ">" +

" var control = document.getElementById(" + c +

txtAdi + c + ");" +

" if( control != null ){control.focus();}" +

"</script>";

Page.RegisterStartupScript("Focus", script);
 
selen,

Basically, you have to place a piece of script in your code:

<script language="JavaScript">
function DoSomething()
{
// Do something here
}
</script>

Then, your button declaration needs to be:

<input type="button" onclick="DoSomething">

This links the button's click event to the DoSomething function.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

selen said:
I think I coundnt do it.I dont understand anything:(((.can you give me
example.

Thanks


"Nicholas Paldino [.NET/C# MVP]" <[email protected]>, iletide
þunu yazdý news:[email protected]...
selen,

Yes, and your script doesn't have any function declaration around it.
How are you hooking up the event handler to the button? It doesn't make
sense.

How is the script being rendered on the client? How do you perform the
hookup between the button and the script itself.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

selen said:
I am writind direct inside of button Click event.
Before I wrote above script.It worked.But this doesnt work.My button isnt
html button.I am using
c#.net
string strScript;

strScript = "<script>";

strScript = strScript + "alert('Rol Adýný Girmelisiniz.');";

strScript = strScript + "</script>";

Page.RegisterStartupScript("ClientScript", strScript);


"Nicholas Paldino [.NET/C# MVP]" <[email protected]>, iletide
þunu yazdý selen,

I also notice that you don't have this script in a function.
How
are
you linking the button click event to the script?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

My code is in button's click event.I want When I click the button set
focus
to textbox name is txtAdi.But It odesnt work...

"Nicholas Paldino [.NET/C# MVP]"
iletide
þunu yazdý selen,

If the script is before all of the document elements, then
it
will
get
executed, and it will not know where the element is, because the
element
doesn't exist yet (the document hasn't been rendered).

What you want to do is have the javascript registered with the
onload
event for the body, having it call your code when the body is loaded.
That
way, the document object model has been set up, and you can
access
the
elements in your script.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I am using above script for Focus to txtAdi which is textbox
in
 
Back
Top