473,394 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

script for focus

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);
Nov 15 '05 #1
7 1767
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]
- mv*@spam.guard.caspershouse.com

"selen" <sk*****@yahoo.com> wrote in message
news:uH**************@TK2MSFTNGP11.phx.gbl...
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);

Nov 15 '05 #2
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]" <mv*@spam.guard.caspershouse.com>, iletide
şunu yazdı news:u1**************@TK2MSFTNGP11.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"selen" <sk*****@yahoo.com> wrote in message
news:uH**************@TK2MSFTNGP11.phx.gbl...
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);


Nov 15 '05 #3
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]
- mv*@spam.guard.caspershouse.com

"selen" <sk*****@yahoo.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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]" <mv*@spam.guard.caspershouse.com>, iletide şunu yazdı news:u1**************@TK2MSFTNGP11.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"selen" <sk*****@yahoo.com> wrote in message
news:uH**************@TK2MSFTNGP11.phx.gbl...
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);



Nov 15 '05 #4
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]" <mv*@spam.guard.caspershouse.com>, iletide
şunu yazdı news:%2****************@tk2msftngp13.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"selen" <sk*****@yahoo.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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]" <mv*@spam.guard.caspershouse.com>,

iletide
şunu yazdı news:u1**************@TK2MSFTNGP11.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"selen" <sk*****@yahoo.com> wrote in message
news:uH**************@TK2MSFTNGP11.phx.gbl...
> 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);
>
>



Nov 15 '05 #5
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]
- mv*@spam.guard.caspershouse.com

"selen" <sk*****@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
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]" <mv*@spam.guard.caspershouse.com>, iletide şunu yazdı news:%2****************@tk2msftngp13.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"selen" <sk*****@yahoo.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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]" <mv*@spam.guard.caspershouse.com>,

iletide
şunu yazdı news:u1**************@TK2MSFTNGP11.phx.gbl...
> 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]
> - mv*@spam.guard.caspershouse.com
>
> "selen" <sk*****@yahoo.com> wrote in message
> news:uH**************@TK2MSFTNGP11.phx.gbl...
> > 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);
> >
> >
>
>



Nov 15 '05 #6
I think I coundnt do it.I dont understand anything:(((.can you give me
example.

Thanks
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>, iletide
şunu yazdı news:et**************@tk2msftngp13.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"selen" <sk*****@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
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]" <mv*@spam.guard.caspershouse.com>,

iletide
şunu yazdı news:%2****************@tk2msftngp13.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"selen" <sk*****@yahoo.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> 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]" <mv*@spam.guard.caspershouse.com>,
iletide
> şunu yazdı news:u1**************@TK2MSFTNGP11.phx.gbl...
> > 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]
> > - mv*@spam.guard.caspershouse.com
> >
> > "selen" <sk*****@yahoo.com> wrote in message
> > news:uH**************@TK2MSFTNGP11.phx.gbl...
> > > 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);
> > >
> > >
> >
> >
>
>



Nov 15 '05 #7
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]
- mv*@spam.guard.caspershouse.com

"selen" <sk*****@yahoo.com> wrote in message
news:OY**************@TK2MSFTNGP12.phx.gbl...
I think I coundnt do it.I dont understand anything:(((.can you give me
example.

Thanks
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>, iletide şunu yazdı news:et**************@tk2msftngp13.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"selen" <sk*****@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
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]" <mv*@spam.guard.caspershouse.com>,

iletide
şunu yazdı news:%2****************@tk2msftngp13.phx.gbl...
> 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]
> - mv*@spam.guard.caspershouse.com
>
> "selen" <sk*****@yahoo.com> wrote in message
> news:%2****************@tk2msftngp13.phx.gbl...
> > 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]"
<mv*@spam.guard.caspershouse.com>, > iletide
> > şunu yazdı news:u1**************@TK2MSFTNGP11.phx.gbl...
> > > 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]
> > > - mv*@spam.guard.caspershouse.com
> > >
> > > "selen" <sk*****@yahoo.com> wrote in message
> > > news:uH**************@TK2MSFTNGP11.phx.gbl...
> > > > 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);
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Kenneth | last post by:
Hello, I'm having some serious problems debugging a script that I'm trying to make work. I'm working on a form where a user can type in a time (in the format of HH:MM), and another script...
1
by: Luis | last post by:
When I run the following script it displays a form with a dropdown list and four text boxes. If I select "No" from the dropdown list all the text boxes are disabled. If I select "Yes" from the...
4
by: Semi Head | last post by:
Hello folks, I'm looking for a script to validate a specific number value in a standard form input field. An example would be, if someone enters a number into a form input, I want the script to...
2
by: selen | last post by:
I am using script for Focus to txtAdi which is textbox in c# web application.But it doesnt work. Have you any idea why it doesnt work.What must I do ? can you give me example. Because I am...
2
by: kpg | last post by:
Hi all, This should be simple... I have a TextBox1 and a customvalidation control linked to it. I use a client side script to validate the textbox. If the data is not valid I want to return...
2
by: Paul | last post by:
Hi I have some code and java script, when the page initially loads I want it to have focus on dr_tx_names. This works. The page loads a second time with a dropdown selection and in the code...
1
by: RSH | last post by:
I have a situation where I am Registering a Startup script with the following code: If Not IsPostBack Then Dim sScript As StringBuilder = New StringBuilder sScript.Append("<SCRIPT...
0
by: Razcer | last post by:
I am getting 'Object Expected' script errors from the scripts rendered by aspnet 2.0 webcontrols. This happens if I set OnTextChange="methodnamehere" on the .aspx page or use the Control.Focus()...
3
by: happyse27 | last post by:
Hi All, I am creating the perl script using html form(with embedded javascript inside). When using this html form with javascript alone, it works where the form validation will pop up...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.