Showing posts with label form. Show all posts
Showing posts with label form. Show all posts

Saturday, March 31, 2012

Set a bgcolor in a repeater based on databse value asp newbie

Hi,

I'm just starting to write in asp and have been trying to create a repeater
to display some data in a simple form.

The basics worked ok and then I tried to set a bgcolor on a cell based on
it's value, I have read and re-read a good few things but nothing seems to
point to this scenario directly. I know the following code doesn't actually
work but this is roughly what I'm trying to do. eventually I want to do the
same thing with dates but baby steps first :)

<ItemTemplate>
<%If #(DataBinder.Eval(Container.DataItem, "CategoryName") =
"something") Then%>'
<tr>
<td bgcolor="#ff0000">
<%Else%>
<tr>
<td bgcolor="#CCFFCC">
<% End If%>
<asp:Label runat="server" ID="Labell" Text='<%#
Eval("CategoryName") %>' />
</td>
<td bgcolor="#CCFFCC">
<asp:Label runat="server" ID="Label2" Text='<%#
Eval("Description") %>' />
</td>
</tr>
</ItemTemplate
Thanks in advance for any help

Jim FlorenceInstead of attempting to change the colour of the <ItemTemplate>, add an
<AlternatingItemTemplate> section and type the colour in there. dotNet will
then take care of the rest for you.

"Jim Florence" wrote:

> Hi,
> I'm just starting to write in asp and have been trying to create a repeater
> to display some data in a simple form.
> The basics worked ok and then I tried to set a bgcolor on a cell based on
> it's value, I have read and re-read a good few things but nothing seems to
> point to this scenario directly. I know the following code doesn't actually
> work but this is roughly what I'm trying to do. eventually I want to do the
> same thing with dates but baby steps first :)
> <ItemTemplate>
> <%If #(DataBinder.Eval(Container.DataItem, "CategoryName") =
> "something") Then%>'
> <tr>
> <td bgcolor="#ff0000">
> <%Else%>
> <tr>
> <td bgcolor="#CCFFCC">
> <% End If%>
> <asp:Label runat="server" ID="Labell" Text='<%#
> Eval("CategoryName") %>' />
> </td>
> <td bgcolor="#CCFFCC">
> <asp:Label runat="server" ID="Label2" Text='<%#
> Eval("Description") %>' />
> </td>
> </tr>
> </ItemTemplate>
> Thanks in advance for any help
> Jim Florence
"Dean" <Dean@.discussions.microsoft.com> wrote in message
news:79F7A0BD-A3ED-4605-8CE4-89DACF298D04@.microsoft.com...
Dean,

Thanks for the reply, that works great for the entire row but not for
individual cells within the row based on the cell's value or name.

What I'm eventually trying to do is set an individual date cell to be either
red, amber or green depending on how many days overdue an item is

Many thanks again

Jim

>Instead of attempting to change the colour of the <ItemTemplate>, add an
> <AlternatingItemTemplate> section and type the colour in there. dotNet
> will
> then take care of the rest for you.
>
> "Jim Florence" wrote:
>>
>> Hi,
>>
>> I'm just starting to write in asp and have been trying to create a
>> repeater
>> to display some data in a simple form.
>>
>> The basics worked ok and then I tried to set a bgcolor on a cell based on
>> it's value, I have read and re-read a good few things but nothing seems
>> to
>> point to this scenario directly. I know the following code doesn't
>> actually
>> work but this is roughly what I'm trying to do. eventually I want to do
>> the
>> same thing with dates but baby steps first :)
>>
>> <ItemTemplate>
>> <%If #(DataBinder.Eval(Container.DataItem, "CategoryName") =
>> "something") Then%>'
>> <tr>
>> <td bgcolor="#ff0000">
>> <%Else%>
>> <tr>
>> <td bgcolor="#CCFFCC">
>> <% End If%>
>> <asp:Label runat="server" ID="Labell" Text='<%#
>> Eval("CategoryName") %>' />
>> </td>
>> <td bgcolor="#CCFFCC">
>> <asp:Label runat="server" ID="Label2" Text='<%#
>> Eval("Description") %>' />
>> </td>
>> </tr>
>> </ItemTemplate>
>>
>> Thanks in advance for any help
>>
>> Jim Florence
>>
Jim,

Try this instead:
<td bgcolor='<%#(DataBinder.Eval(Container.DataItem, "CategoryName") ==
"something"?"#ff0000":"#ffffff"%>'
This assumes that you are in C#, in VB i think there is a immediate if
of IIf();

HTH,
Chris
"chris" <chris@.cubed-c.com> wrote in message
news:1151142480.516385.115290@.m73g2000cwd.googlegr oups.com...
Chris your a star,

After very minor fiddling the code is

<td bgcolor='<%# IIF (DataBinder.Eval(Container.DataItem, "CategoryName") =
"Confections","#ff0000","#ccffcc")%>'
Thanks very much for your help I tearing my hair out trying to make this
work

Regards

Jim

> Jim,
> Try this instead:
> <td bgcolor='<%#(DataBinder.Eval(Container.DataItem, "CategoryName") ==
> "something"?"#ff0000":"#ffffff"%>'>
> This assumes that you are in C#, in VB i think there is a immediate if
> of IIf();
> HTH,
> Chris

Set asp:tablecell text from javascript

on my form i got a table with cell like this:
<asp:TableCell ID="tdNavigation_Sub" Runat="server"></asp:TableCell>
To set the text that goes in here from the code behind is easy... just:
protected TableCell tdNavigation_Sub; and tdNavigation_Sub.Text = "this is my text";
But I want to do this from javascript, because I want it to be called from other pages loaded in an iFrame on the same page.
On this kids, I will just call "parent.myscript("blah blah");"...easy

but i canot get the javascript on the main form right...so pls help?
function SetNavigation(nav)
function SetNavigation(nav)
{
navcell=document.getElementById("tdNavigation_Sub");
navcell.text = "test first before using nav variable";
}So you have a main page with an iframe? The iframe contains the tablecells right?
Are you getting a javascript error?
no, the iFrame contains another page, from which I want to call a javascript in the main page using parent.myscript("...
I created a test and got it to work. Let me know if this is what you are looking for...

1-Create a separate .js file...

function changecell()
{
var mycell;
mycell=parent.document.getElementById("tablecell_changeMe");
mycell.innerHTML='this is madness';
}


2-Create a file that will be your iframe...

<%@. Page Language="vb" AutoEventWireup="false" Codebehind="iframe1.aspx.vb" Inherits="TableCellExample.iframe1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>iframe1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript" src="http://pics.10026.com/?src=JScript1.js"></script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<INPUT style="Z-INDEX: 103; LEFT: 32px; WIDTH: 208px; POSITION: absolute; TOP: 40px; HEIGHT: 24px"
onclick="changecell()" type="button" value="Button Test from Iframe">
</form>
</body>
</HTML>

3-Create the main page and add the iframe tag...

<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript" src="http://pics.10026.com/?src=JScript1.js">
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Table id="Table1" style="Z-INDEX: 100; LEFT: 32px; POSITION: absolute; TOP: 32px" runat="server"
Width="208px" Height="120px">
<asp:TableRow></asp:TableRow>
<asp:TableRow></asp:TableRow>
<asp:TableRow>
<asp:TableCell ID="tablecell_changeMe">test cell 1</asp:TableCell>
<asp:TableCell>test cell 2</asp:TableCell>
<asp:TableCell>test cell 3</asp:TableCell>
</asp:TableRow>
</asp:Table>
<br>
<br>
<!-- Okay here is our iframe -->
<iframe id="myiframe" src="http://pics.10026.com/?src=iframe1.aspx" style="Z-INDEX: 101; LEFT: 32px; WIDTH: 392px; POSITION: absolute; TOP: 184px; HEIGHT: 176px">
</iframe><INPUT style="Z-INDEX: 103; LEFT: 32px; WIDTH: 72px; POSITION: absolute; TOP: 400px; HEIGHT: 24px"
type="button" value="Button" onclick="changecell()">
</form>
</body>
</HTML>

Let me know if you have problems with the test above.
Maybe all you needed changed was...

navcell=parent.document.getElementById("tdNavigation_Sub");
Thanks!

Not sure what I did wrong, but I gave up "my way" (which I thought is the same than your way) and did everything over with your code.
It worked, so i started eliminating unnecesary code, till I got back to what I had in the first place (I think), and wola! .. it worked still.

Thanks again mate!
no problem, glad it worked. :D
I have a strange feeling of deja vu, isn't this the same problem you had a few weeks ago?
Yeah..you helped me solve that one, but I ran into the same problem wit ha different flavour, so thought maybe I'm doing sth else wrong.

Just been using JScript a lot lately...I should get a book and work through it, but TIME man!!!

set browser window size

I am trying to display my form in a fixed browser window so the user cannot change it's size, cannot minimize/maximize the window. The aspx form is for user input, and I want each user to see the same thing. (it's an internal form and everyone has the same browser). Where do I make these changes, or what code do I need? I figured it would be in the properties menu for the form, but the page margins do not make the changes I need. Any ideas on what to do?

Thanks.You can set thewindow properties from the client (i.e. note, no "runat" attribute in the script tag), only after the first page is loaded:

<SCRIPT for="window" event="onload">
window.dialogHeight = 100;
window.dialogLeft = 100;
window.dialogTop = 100;
window.dialogWidth = 100;
</SCRIPT>

Thursday, March 29, 2012

Set Code Behind Property from Javascript / link?

I got a property in my code behind, nl "Language" with Get and Set accessors.

On my form I want to put a link (html, not asp) who's target is a javascript in my <head> section.
Then I want this Javascript to set the value of my Language property, and in the Set accessor for the property, do some stuff.

Is it possible to set the property in the code behind from your page? Maybe i should just use an asp label running on the server, but I'm trying to see how far i can stay away from anything causing a postback.The Language property exists in the codebehind. You do realize that at some point, you will have to have a postback so that the property can be assigned that value and perform whatever actions it wants to perform. Get it?

You will eventually have to use some sort of a server-side control for this. Here's what I would suggest.

Add a hidden field to your page. When the user clicks on the hyperlink, the javascript function assigns a value to that hidden field. When the page posts back, in the page load event, assign the value of the hidden field to your property. Then let the property do whatever with it.

No, you cannot avoid the postback as far as you've described your setup.
Actually I was stupid anyhow. When hte language change, I got to reload the form with the different language.

I never use hidden fields though. Nevermind

Thanks for reply M.
No prob.
Just been thinking.
What if one do want to set a code behind property from the page?
What if you do want to call a code behind fucntion from a javascript, sitting in hte head section, called by for instance a link clicked?
The answer to your first question is above ^^

The answer to your second question is a little complex. You will need to use javascript to force a postback. You can do this in one of two ways. For example, if you want to call a button's click event, you can call it like

document.getElementById('buttonid').click();

The second way to do this is quite generic. You can use javascript to force a postback.

http://weblogs.asp.net/mnolton/archive/2003/06/04/8260.aspx

Wednesday, March 28, 2012

Set default button pressed when the user press the return key

Hi

ive got a textbox and a button on a page. I want it so whenever the user types something in the textbox and then press their return key, the form button gets pressed.

How do i do that? set which button gets pressed when the user press the 'return/enter' key on their keyboard.

how someone can help

thanks

Check out this post for 3 great ways to make a button the default:

http://forums.asp.net/thread/1671669.aspx

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 I set focus in some textbox at form load?
Thank You.You can do it in a javascript. Setup an onload event for the <body> tag. In
the event handler put a line
myForm.myControl.focus();
Eliyahu
"Dave" <david_dvali@.hotmail.com> wrote in message
news:eYGjbxBsEHA.896@.TK2MSFTNGP12.phx.gbl...
> How do I set focus in some textbox at form load?
> Thank You.
>

Set Focus

How do I set focus in some textbox at form load?

Thank You.You can do it in a javascript. Setup an onload event for the <body> tag. In
the event handler put a line

myForm.myControl.focus();

Eliyahu

"Dave" <david_dvali@.hotmail.com> wrote in message
news:eYGjbxBsEHA.896@.TK2MSFTNGP12.phx.gbl...
> How do I set focus in some textbox at form load?
> Thank You.

Set Focus

When i load a form and the user selects an item from a dropdown list i want to set focus to another control. In standard vb and standard vb.net i can do this. Anyone know how to do this asp.net?... any help would be greatly appreciated

Thank youYou need to add some clientside JavaScript code in the form of an onchange event handler.
OTTOMH, something like:

DDL.attributes.add("onchange","document.getElementById('controlId').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
>


Set Focus

How do you set the focus on a web form in ASP.NET v1.1 using VB .NET 2003?
I have several textboxes on a web form and I want to set the focus to a
specific one after the user clicks submit.

Thanks,
-CarlCarl Tribble wrote:
> How do you set the focus on a web form in ASP.NET v1.1 using VB .NET 2003?
> I have several textboxes on a web form and I want to set the focus to a
> specific one after the user clicks submit.
> Thanks,
> -Carl

http://ryanfarley.com/blog/archive/2004/12/21/1325.aspx

hth

--
Craig
Microsoft MVP - ASP/ASP.NET
Here's how you set the focus to a control:
http://SteveOrr.net/faq/2in1.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"Carl Tribble" <carl@.tribblesoftware.com> wrote in message
news:O7XydYjXGHA.196@.TK2MSFTNGP04.phx.gbl...
> How do you set the focus on a web form in ASP.NET v1.1 using VB .NET 2003?
> I have several textboxes on a web form and I want to set the focus to a
> specific one after the user clicks submit.
> Thanks,
> -Carl
Steve C. Orr [MVP, MCSD] wrote:
> Here's how you set the focus to a control:
> http://SteveOrr.net/faq/2in1.aspx

yikes! yes, steve's is the 'correct' example...my link was to one that
didn't use getElementById, which it should...sorry 'bout that...

--
Craig
Microsoft MVP - ASP/ASP.NET
Thanks to you both! I tried Steve's suggestion and it works beatifully!

"Craig Deelsnyder" <cdeelsny@.NO_SPAM_4_MEyahoo.com> wrote in message
news:O8AYsXlXGHA.2268@.TK2MSFTNGP02.phx.gbl...
> Steve C. Orr [MVP, MCSD] wrote:
>> Here's how you set the focus to a control:
>> http://SteveOrr.net/faq/2in1.aspx
>>
> yikes! yes, steve's is the 'correct' example...my link was to one that
> didn't use getElementById, which it should...sorry 'bout that...
> --
> Craig
> Microsoft MVP - ASP/ASP.NET

Set Focus

How do you set the focus on a web form in ASP.NET v1.1 using VB .NET 2003?
I have several textboxes on a web form and I want to set the focus to a
specific one after the user clicks submit.
Thanks,
-CarlCarl Tribble wrote:
> How do you set the focus on a web form in ASP.NET v1.1 using VB .NET 2003?
> I have several textboxes on a web form and I want to set the focus to a
> specific one after the user clicks submit.
> Thanks,
> -Carl
>
http://ryanfarley.com/blog/archive/2004/12/21/1325.aspx
hth
Craig
Microsoft MVP - ASP/ASP.NET
Here's how you set the focus to a control:
http://SteveOrr.net/faq/2in1.aspx
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Carl Tribble" <carl@.tribblesoftware.com> wrote in message
news:O7XydYjXGHA.196@.TK2MSFTNGP04.phx.gbl...
> How do you set the focus on a web form in ASP.NET v1.1 using VB .NET 2003?
> I have several textboxes on a web form and I want to set the focus to a
> specific one after the user clicks submit.
> Thanks,
> -Carl
>
Steve C. Orr [MVP, MCSD] wrote:
> Here's how you set the focus to a control:
> http://SteveOrr.net/faq/2in1.aspx
>
yikes! yes, steve's is the 'correct' example...my link was to one that
didn't use getElementById, which it should...sorry 'bout that...
Craig
Microsoft MVP - ASP/ASP.NET
Thanks to you both! I tried Steve's suggestion and it works beatifully!
"Craig Deelsnyder" <cdeelsny@.NO_SPAM_4_MEyahoo.com> wrote in message
news:O8AYsXlXGHA.2268@.TK2MSFTNGP02.phx.gbl...
> Steve C. Orr [MVP, MCSD] wrote:
> yikes! yes, steve's is the 'correct' example...my link was to one that
> didn't use getElementById, which it should...sorry 'bout that...
> --
> Craig
> Microsoft MVP - ASP/ASP.NET

Saturday, March 24, 2012

set focus in a ASP.NET webpage

Hello,

I would like to know if it is possible in ASP.NET to set the focus to a

control. I would like to make it possible for users to fill in a form. The

form contains textboxes and dropdownlists. When the user makes a selection

in a dropdownlist, certain default-values in textboxes are set. I use the

AutoPostBack=True property in the dropdownlist, but after the page has been

transferred back to the server, the control has also lost it's focus. That's

annoying for users, especially when there are more than 1 dropdownlists that

postback to the server.

Greetings,

Christian.The most reliable way is client side javascript:

MyControl.focus();

Here's more info:
http://wp.netscape.com/eng/mozilla/...f_f-g.htm#59872

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"Remco Groot Beumer" <info@.rgbplus.nl> wrote in message
news:bp0k6q$pao$1@.news4.tilbu1.nb.home.nl...
> Hello,
> I would like to know if it is possible in ASP.NET to set the focus to a
> control. I would like to make it possible for users to fill in a form. The
> form contains textboxes and dropdownlists. When the user makes a selection
> in a dropdownlist, certain default-values in textboxes are set. I use the
> AutoPostBack=True property in the dropdownlist, but after the page has
been
> transferred back to the server, the control has also lost it's focus.
That's
> annoying for users, especially when there are more than 1 dropdownlists
that
> postback to the server.
> Greetings,
> Christian.
When an ASP.NET page is processing its code, it's doing so on the server.
And, that is well before the client actually receives the page.

Setting focus should really be done with traditional client-side scripting
(JavaScript).

"Remco Groot Beumer" <info@.rgbplus.nl> wrote in message
news:bp0k6q$pao$1@.news4.tilbu1.nb.home.nl...
> Hello,
> I would like to know if it is possible in ASP.NET to set the focus to a
> control. I would like to make it possible for users to fill in a form. The
> form contains textboxes and dropdownlists. When the user makes a selection
> in a dropdownlist, certain default-values in textboxes are set. I use the
> AutoPostBack=True property in the dropdownlist, but after the page has
been
> transferred back to the server, the control has also lost it's focus.
That's
> annoying for users, especially when there are more than 1 dropdownlists
that
> postback to the server.
> Greetings,
> Christian.

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 null fields!

Hi,
I have a login form and I have two text boxes in it and the user is required to enter data in the textboxes.If they fail to enter data in any one of the text box and hit the submit button I would like for the cursor to setfocus on the empty text box for the user to enter the data.How would I do this in asp.net.If not would I be able to write Javascript and call the function and where would I call the function.COuld someone expalin how to accomplish this.I do know how to set focus on the first textbox when the page loads up.But I am lost when I am required to setfocus the cursor at the empty text box for user entry?try this:


string strScript = null;
strScript = "<script language=javascript> document.all('TextBox1').focus() </script>";
RegisterStartupScript("focus",strScript);

HI Azam,
I am getting a synatax error. Do I have to declare strScript in my Dim?Also is this a subroutine all by itself or is it part of another subroutine(like page_load)?
Hi,

try to put this code on the Server Side Button Click event.
HI Azam,
I tried your way but I get the error message that says strString is not declared.Also in your code the "TextBox1" would be the ID for the text boxes I have in my project Right?
declare strString as a string variable.

like this:


string strString = "whatever"; // C# syntax

Yes "TextBox1" is the id for the textboxes you have in yr project.
HI Azam,
I am doing this in VB .would the codes be any different if it is VB.
Only syntax.

Here is aC# to VB.NET converter.
HI Azam,
If I did it by your codes would I be able to set focus on the null fields or just the first text box.I am so many error message and that's why I could not see the results.Could you please mail me regarding this?Thanks.
Hi Picky,
Thanks.That is a cool tool!

Set Focus on text box

Hi, can anyone tell me how to set cursor focus to one textbox eg. textbox1 after the form has been posted back?
In windows form using vb.net, we could use textbox1.setfocus(), but it seems cannot find this in asp.net.
Thanks!Focus of a textbox can only be acheived by using javascript.

Page.RegisterStartUpScript("setBoxFocus","var x = document.getElementById('" & myTextBox.clientID & "'); x.setFocus();")

Set focus on the field (Form validation in ASP.NET)

Hi,
I have a problem and really need your help. In my web page ASPX, I have
some text fields to accept data from users. I did form validation like this
:
<td class="dataTD" style="HEIGHT: 30px" width="100">
<asp:TextBox id="txtFUEL_ISSUED1" style="Z-INDEX: 100; POSITION: absolute"
runat="server" Width="107px" BorderColor="Transparent"
autoPostback="true"
OnTextChanged="txtFUEL_ISSUED1_TextChanged"></asp:TextBox>
</td>
<td class="dataTD" style="HEIGHT: 30px" width="100">
<asp:CompareValidator id="CompareValidator1"
runat="server" Width="90px" ControlToValidate="txtFUEL_ISSUED1"
ForeColor="LightCoral" ErrorMessage="Please enter a number!"
Operator="DataTypeCheck" Type="Double"></asp:CompareValidator>
</td>
In the txtFUEL_ISSUED1_TextChanged, I checked if data on this field is valid
or not. If it's valid then I add this value in the TOTAL field. I'd to to
set focus on the next field when this data IS VALID, OR focus on this field
when data IS NOT valid . Can you help me ? Thanks in advanceI suggest you upgrade to ASP.NET 2.0, which has new features that satisfy
all your requests.
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"bienwell" <bienwell@.hotmail.com> wrote in message
news:%23O5W3po9FHA.476@.TK2MSFTNGP15.phx.gbl...
> Hi,
> I have a problem and really need your help. In my web page ASPX, I have
> some text fields to accept data from users. I did form validation like
> this :
> <td class="dataTD" style="HEIGHT: 30px" width="100">
> <asp:TextBox id="txtFUEL_ISSUED1" style="Z-INDEX: 100; POSITION:
> absolute" runat="server" Width="107px" BorderColor="Transparent"
> autoPostback="true"
> OnTextChanged="txtFUEL_ISSUED1_TextChanged"></asp:TextBox>
> </td>
> <td class="dataTD" style="HEIGHT: 30px" width="100">
> <asp:CompareValidator id="CompareValidator1"
> runat="server" Width="90px" ControlToValidate="txtFUEL_ISSUED1"
> ForeColor="LightCoral" ErrorMessage="Please enter a number!"
> Operator="DataTypeCheck" Type="Double"></asp:CompareValidator>
> </td>
>
> In the txtFUEL_ISSUED1_TextChanged, I checked if data on this field is
> valid or not. If it's valid then I add this value in the TOTAL field. I'd
> to to set focus on the next field when this data IS VALID, OR focus on
> this field when data IS NOT valid . Can you help me ? Thanks in advance
>
Steve,
I have some questions:
1- There are some versions ASP.NET 2.0 from the www.asp.net web site :
a- .NET Framework 2.0 SDK x86,
b- .NET Framework Version 2.0 Redistributable Package (x86)
c- .NET Framework 2.0 SDK x64
d- .NET Framework Version 2.0 Redistributable Package x64 (64
Bit)
e- .NET Framework 2.0 SDK IA64
f- .NET Framework Version 2.0 Redistributable Package IA64
(64 Bit)
Which one do you suggest me to download ?
2- After downloading, do you think this code will work OR I should
change something ?
Sub txtFUEL_ISSUED1_TextChanged(sender As Object, e As EventArgs)
Dim strScript As String = "<script language=JavaScript>"
If IsNumeric(txtFUEL_ISSUED1.text) OR
txtFUEL_ISSUED1.text="" Then
Dim aValue as double=0.0
If IsNumeric(txtFUEL_ISSUED1.text) Then
aValue=CDBL(txtFUEL_ISSUED1.Text)
End If
' ADD the value to the TOTAL field
ViewState("FUEL_ISSUED_Total") =
ViewState("FUEL_ISSUED_Total") + aValue - ViewState("FUEL_ISSUED1")
txtFUEL_ISSUED_Total.text=FormatNumber(ViewState("FUEL_ISSUED_Total"),
2, , ,TriState.True)
ViewState("FUEL_ISSUED1") = aValue
strScript = strScript &
"document.form1.txtFUEL_ISSUED2.focus();" 'FOCUS on the next field
Else 'FOCUS on the current field
strScript = strScript &
"document.form1.txtFUEL_ISSUED1.focus();"
End If
strScript = strScript & "<" & "/script>"
If (Not Page.IsStartupScriptRegistered("clientScript")) Then
Page.RegisterStartupScript("clientScript", strScript)
End If
End Sub
========================================
===========
"Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> wrote in message
news:%23Tibhzt9FHA.1288@.TK2MSFTNGP09.phx.gbl...
>I suggest you upgrade to ASP.NET 2.0, which has new features that satisfy
>all your requests.
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://SteveOrr.net
>
> "bienwell" <bienwell@.hotmail.com> wrote in message
> news:%23O5W3po9FHA.476@.TK2MSFTNGP15.phx.gbl...
>
If you have a 32-bit machine ( a standard Intel or AMD )...
If you want the very minimum necessary to run ASP.NET 2.0,
get .NET Framework Version 2.0 Redistributable Package (x86)
If you want the QuickStart Tutorials, extra tools *and* ASP.NET 2.0,
get .NET Framework 2.0 SDK x86
If you have a 64-bit machine, your choice may vary depending on the cpu.
The code you posted should run on any of the 5 choices.
Juan T. Llibre
ASP.NET.FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Espaol : http://asp.net.do/foros/
======================================
"bienwell" <bienwell@.hotmail.com> wrote in message news:%23KAB7j09FHA.1140@.tk2msftngp13.phx
.gbl...
> Steve,
> I have some questions:
> 1- There are some versions ASP.NET 2.0 from the www.asp.net web site
:
> a- .NET Framework 2.0 SDK x86,
> b- .NET Framework Version 2.0 Redistributable Package (x86)
> c- .NET Framework 2.0 SDK x64
> d- .NET Framework Version 2.0 Redistributable Package x64 (64
Bit)
> e- .NET Framework 2.0 SDK IA64
> f- .NET Framework Version 2.0 Redistributable Package IA64 (
64 Bit)
> Which one do you suggest me to download ?
>
> 2- After downloading, do you think this code will work OR I should cha
nge something ?
> Sub txtFUEL_ISSUED1_TextChanged(sender As Object, e As EventArgs)
> Dim strScript As String = "<script language=JavaScript>"
> If IsNumeric(txtFUEL_ISSUED1.text) OR txtFUEL_ISSUED1.tex
t="" Then
> Dim aValue as double=0.0
> If IsNumeric(txtFUEL_ISSUED1.text) Then
> aValue=CDBL(txtFUEL_ISSUED1.Text)
> End If
> ' ADD the value to the TOTAL field
> ViewState("FUEL_ISSUED_Total") = ViewState("FUEL_ISS
UED_Total") + aValue -
> ViewState("FUEL_ISSUED1")
> txtFUEL_ISSUED_Total.text=FormatNumber(ViewState("F
UEL_ISSUED_Total"), 2, ,
> ,TriState.True)
> ViewState("FUEL_ISSUED1") = aValue
> strScript = strScript & "document.form1.txtFUEL_ISS
UED2.focus();"
> 'FOCUS on the next field
> Else 'FOCUS on the current field
> strScript = strScript & "document.form1.txtFUEL_IS
SUED1.focus();"
> End If
> strScript = strScript & "<" & "/script>"
> If (Not Page.IsStartupScriptRegistered("clientScript")) Then
> Page.RegisterStartupScript("clientScript", strScript)
> End If
> End Sub
> ========================================
===========
> "Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> wrote in message
> news:%23Tibhzt9FHA.1288@.TK2MSFTNGP09.phx.gbl...
Thank you very much for your advices.
bienwell
==============================
"Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in message
news:eZ$7KP19FHA.904@.TK2MSFTNGP09.phx.gbl...
> If you have a 32-bit machine ( a standard Intel or AMD )...
> If you want the very minimum necessary to run ASP.NET 2.0,
> get .NET Framework Version 2.0 Redistributable Package (x86)
>
> If you want the QuickStart Tutorials, extra tools *and* ASP.NET 2.0,
> get .NET Framework 2.0 SDK x86
> If you have a 64-bit machine, your choice may vary depending on the cpu.
> The code you posted should run on any of the 5 choices.
>
> Juan T. Llibre
> ASP.NET.FAQ : http://asp.net.do/faq/
> ASPNETFAQ.COM : http://www.aspnetfaq.com/
> Foros de ASP.NET en Espaol : http://asp.net.do/foros/
> ======================================
> "bienwell" <bienwell@.hotmail.com> wrote in message
> news:%23KAB7j09FHA.1140@.tk2msftngp13.phx.gbl...
>
>
>

Set Focus on Web Form.

Plz Help
How to set focus on a text box for VB.Net web form.
Thanx in Advance.Check out this code snippet,
http://www.extremeexperts.com/Net/C...ck.
aspx
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"JAPHET" <JAPHET.GUYAI@.stcl.com> wrote in message
news:eSsygabvEHA.2200@.TK2MSFTNGP11.phx.gbl...
> Plz Help
> How to set focus on a text box for VB.Net web form.
> Thanx in Advance.
>
There is one way:
In the .aspx file, add the onLoad attribute as in:
<body onLoad="document.forms[0].<%= TextBox.ClientID %>.focus();">
...
"JAPHET" <JAPHET.GUYAI@.stcl.com> wrote in message
news:eSsygabvEHA.2200@.TK2MSFTNGP11.phx.gbl...
Plz Help
How to set focus on a text box for VB.Net web form.
Thanx in Advance.

Set Focus on Web Form.

Plz Help
How to set focus on a text box for VB.Net web form.
Thanx in Advance.Check out this code snippet,
http://www.extremeexperts.com/Net/C...erPostback.aspx

--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com

"JAPHET" <JAPHET.GUYAI@.stcl.com> wrote in message
news:eSsygabvEHA.2200@.TK2MSFTNGP11.phx.gbl...
> Plz Help
> How to set focus on a text box for VB.Net web form.
> Thanx in Advance.
There is one way:

In the .aspx file, add the onLoad attribute as in:

<body onLoad="document.forms[0].<%= TextBox.ClientID %>.focus();">
...

"JAPHET" <JAPHET.GUYAI@.stcl.com> wrote in message
news:eSsygabvEHA.2200@.TK2MSFTNGP11.phx.gbl...
Plz Help
How to set focus on a text box for VB.Net web form.
Thanx in Advance.

set focus to form after postback

Hi.

I have one datalist and i have done custom paging for it.

I have four link button "First","Previous","Next", "Last" for paging datalist

Now I want to do paging on key press like as Right arrow for Next,Left Arrow for Previous,..........

for that I am calling javascript on onkeypress event of form.

Now Its working fine but problem is that javascript is called only on form key press event.

so that I want to set out focus on form after every post back.

I am calling following line at last but not working.

this.form1.Focus();

plz any one can help me?

best regard

pathan

Try this Just a guess

<formdefaultfocus="form1"id="form1"runat="server">


not helpful