Showing posts with label box. Show all posts
Showing posts with label box. Show all posts

Thursday, March 29, 2012

Set css class on list box option

Hi,

I want to programatically set the css class on a single list item. I tried the following code but it does nothing...


<html>
<script language="VB" runat="server"
Sub Page_Load(Src As Object, E As EventArgs)
categories.Items(0).Attributes.Add("class", "option.primary")
End Sub

</script
<style>
.primary {background-color:green;color:red; }
</style
<body>
<form runat="server">
<asp:listbox id="categories" Runat="server" SelectionMode="Multiple" Rows="6" Width="400">
<asp:listItem>Item 1</asp:listItem>
</asp:listbox>
</form>
</body>
</html>

Does anyone know how to achieve this?

WT.use the "cssclass" property of the listbox, then you can set it without doing the attributes.add thing.
<option> elements do not have class attributes, but it *is* strange that it doesn't write it out anyway. If you look at the rendered HTML, it probably reads:

<select name="categories">
<option value="Item 1">Item 1</option
That is because, as said, option elements don't have class attributes. Additionally, you're specifying "option.primary" where really the css class you want to use is "primary". If you want to add the class to the whole categories listbox, you could. And an easier way is to use this syntax:


categories.CssClass = "primary"

Which will work just the same as:


categories.Attributes.Add("class","primary")

Thanks for the replies.

I presume that the listItems not rendering their attributes must be a bug.

Looking at the source for the ListBox control, it doesn't appear to be rendering the attributes of its list items. Thus, I'll override the 'RenderContents' method or something and get the attributes rendered.
I think it is a bug too,

but the class browser indicated that the attributes property of the ListItem is readonly which would explain the attributes not being added to the listitem... maybe it is by design.

Monday, March 26, 2012

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();

Saturday, March 24, 2012

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 in EditItemTemplate text box...

Hi,
Is there a way to set the focus onto a text box that I have set up in my
EditItemTemplate, so that the User can just start typing once they they have
selected to Edit?
Many thanks in advance
Colin BHi,
You could write a little script to set the focus and run it after you start
the edit (using Registerstartupscript, for instance).
Cosmin
"Colin Basterfield" <colinbasterfield@.hotmail.com> wrote in message
news:e2vcK5NTEHA.2580@.TK2MSFTNGP12.phx.gbl...
> Hi,
> Is there a way to set the focus onto a text box that I have set up in my
> EditItemTemplate, so that the User can just start typing once they they
have
> selected to Edit?
> Many thanks in advance
> Colin B
>

Set Focus in EditItemTemplate text box...

Hi,

Is there a way to set the focus onto a text box that I have set up in my
EditItemTemplate, so that the User can just start typing once they they have
selected to Edit?

Many thanks in advance
Colin BHi,

You could write a little script to set the focus and run it after you start
the edit (using Registerstartupscript, for instance).

Cosmin

"Colin Basterfield" <colinbasterfield@.hotmail.com> wrote in message
news:e2vcK5NTEHA.2580@.TK2MSFTNGP12.phx.gbl...
> Hi,
> Is there a way to set the focus onto a text box that I have set up in my
> EditItemTemplate, so that the User can just start typing once they they
have
> selected to Edit?
> Many thanks in advance
> Colin B

Set Focus on a control

Hello,

On a click event, I need to test certain text boxes and then based on their
values go to another text box. How do you set the focus using vb?

--
Thanks in advance,

StevenLook at the "Focus in WebForms" thread earlier today...

Set focus on a text box

Dear All,
I have developed a aspx web page with c# as page language. I have place two
text boxes and two requiredfield validator control for each text box. Now
whenever i a text box is null, i want to set the focus on the text box apart
from displaying the error message. Please help.
Regards,
SwamiOne way is to handle the onBlur event of the text box:
<asp:TextBox runat="server" id="txt" onblur="if (this.value.replace(/\s/g,
'').length == 0) this.focus();">
"Swami" <Swami@.discussions.microsoft.com> wrote in message
news:CEB6C427-6924-4D9F-B731-7E560DB05FEC@.microsoft.com...
Dear All,
I have developed a aspx web page with c# as page language. I have place two
text boxes and two requiredfield validator control for each text box. Now
whenever i a text box is null, i want to set the focus on the text box apart
from displaying the error message. Please help.
Regards,
Swami
The easiest, most reliable way is client side java script:
MyControl.focus();
Here's more info:
http://wp.netscape.com/eng/mozilla/...f_f-g.htm#59872
You might also consider using this free control:
http://www.metabuilders.com/Tools/FirstFocus.aspx
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com
"Swami" <Swami@.discussions.microsoft.com> wrote in message
news:CEB6C427-6924-4D9F-B731-7E560DB05FEC@.microsoft.com...
> Dear All,
> I have developed a aspx web page with c# as page language. I have place
> two
> text boxes and two requiredfield validator control for each text box. Now
> whenever i a text box is null, i want to set the focus on the text box
> apart
> from displaying the error message. Please help.
> Regards,
> Swami
Check out this code snippet,
http://www.extremeexperts.com/Net/C...ck.
aspx
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"Swami" <Swami@.discussions.microsoft.com> wrote in message
news:CEB6C427-6924-4D9F-B731-7E560DB05FEC@.microsoft.com...
> Dear All,
> I have developed a aspx web page with c# as page language. I have place
two
> text boxes and two requiredfield validator control for each text box. Now
> whenever i a text box is null, i want to set the focus on the text box
apart
> from displaying the error message. Please help.
> Regards,
> Swami

Set focus on a text box

Dear All,
I have developed a aspx web page with c# as page language. I have place two
text boxes and two requiredfield validator control for each text box. Now
whenever i a text box is null, i want to set the focus on the text box apart
from displaying the error message. Please help.

Regards,
SwamiOne way is to handle the onBlur event of the text box:

<asp:TextBox runat="server" id="txt" onblur="if (this.value.replace(/\s/g,
'').length == 0) this.focus();"
"Swami" <Swami@.discussions.microsoft.com> wrote in message
news:CEB6C427-6924-4D9F-B731-7E560DB05FEC@.microsoft.com...
Dear All,
I have developed a aspx web page with c# as page language. I have place two
text boxes and two requiredfield validator control for each text box. Now
whenever i a text box is null, i want to set the focus on the text box apart
from displaying the error message. Please help.

Regards,
Swami
The easiest, most reliable way is client side javascript:

MyControl.focus();

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

You might also consider using this free control:
http://www.metabuilders.com/Tools/FirstFocus.aspx

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

"Swami" <Swami@.discussions.microsoft.com> wrote in message
news:CEB6C427-6924-4D9F-B731-7E560DB05FEC@.microsoft.com...
> Dear All,
> I have developed a aspx web page with c# as page language. I have place
> two
> text boxes and two requiredfield validator control for each text box. Now
> whenever i a text box is null, i want to set the focus on the text box
> apart
> from displaying the error message. Please help.
> Regards,
> Swami
Check out this code snippet,
http://www.extremeexperts.com/Net/C...erPostback.aspx

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

"Swami" <Swami@.discussions.microsoft.com> wrote in message
news:CEB6C427-6924-4D9F-B731-7E560DB05FEC@.microsoft.com...
> Dear All,
> I have developed a aspx web page with c# as page language. I have place
two
> text boxes and two requiredfield validator control for each text box. Now
> whenever i a text box is null, i want to set the focus on the text box
apart
> from displaying the error message. Please help.
> Regards,
> Swami

Set focus on page load

Hello,

This is probably super simple but I can't figure out how to set the initial focus on an aspx page. I have a text box control that I would like to be the default focus on page load, how do I do this?

Thanks for any help

-SI think this might be the simple way but only good for IE:


<asp:TextBox id=TextBox1 runat="server"></asp:TextBox>
<SCRIPT>window.document.all["TextBox1"].focus()</SCRIPT>

Please see below thread, it has related info on it

http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=314815

Set focus on textbox

Hello,
How do i set focus on text box or any web control in my
aspx.vb page..pls help</form>
<script>
document.all.Button1.focus();
</script>
</body>
</html
"Saifee" <saifthe@.yahoo.com> ??
news:ee5b01c3bd4a$768875f0$a601280a@.phx.gbl...
> Hello,
> How do i set focus on text box or any web control in my
> aspx.vb page..pls help
thanx for the script worked fine, but then how do i set
the focus on a control in run time
say if the user do not enter a value in a textbox,
i dsiplay a message n then have to set the focus to the
textbox

>--Original Message--
></form>
><script>
>document.all.Button1.focus();
></script>
></body>
></html>
>"Saifee" <saifthe@.yahoo.com> ??
>news:ee5b01c3bd4a$768875f0$a601280a@.phx.gbl...
>> Hello,
>> How do i set focus on text box or any web control in my
>> aspx.vb page..pls help
>
>.
Here is an example...

<html>
<body>
<form runat="server">
<asp:TextBox ID="TextBox1" RunAt="server" /><br>
<asp:TextBox ID="TextBox2" RunAt="server" /><br>
</form>
</body>
</html
<script language="javascript">
document.forms[0].TextBox1.focus ();
</script
<asp:placeholder id=script1 runat=server Visible=False
EnableViewState=False>
<script>
alert('please input something');
document.all.TextBox1.focus();
</script>
</asp:placeholder>
</form
to enable the script once , using C#:

placeholder.Visible=true;

"Saifee" <saifthe@.yahoo.com> ??
news:041301c3bd55$9ed5fe00$a401280a@.phx.gbl...
> thanx for the script worked fine, but then how do i set
> the focus on a control in run time
> say if the user do not enter a value in a textbox,
> i dsiplay a message n then have to set the focus to the
> textbox
> >--Original Message--
> ></form>
> ><script>
> >document.all.Button1.focus();
> ></script>
> ></body>
> ></html>
> >"Saifee" <saifthe@.yahoo.com> ??
> >news:ee5b01c3bd4a$768875f0$a601280a@.phx.gbl...
> >> Hello,
> >> How do i set focus on text box or any web control in my
> >> aspx.vb page..pls help
> >.

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 txt box within an user control

I am try to find a way to set focus on the txt box that is in an user control I create, any ideas about this?

ThanksYou can do this using Javascript.

Thanks,
Sridhar!!
Thanks, How? this text box is in the user control, I know how to use JavaScript to set Focus if the control is a server control but not this one.
You just need to make sure that you use the full client ID of the textbox. You could do this by hard-coding the ID of the user control appended to the ID of the textbox, or you could just get the ClientID of the textbox and pass that to your client script.
Hi Penghao98,

How about usingthis control from Meta builders which will essentially write javascript for you :)

HTH
Thanks, do you think you can give me a little example of it?
Hmm. I am not really for using a third party control, for as simple as this. You should identify your textbox inside the user control (in javascript) and set the focus after the page has loaded.

Lets say your user control id is "uc1"
and id of the textbox inside the "uc1" user control is "txt1"

You should be able to set the focus as

document.getElementById("uc1:txt1").focus();

Remember to place this code after the controls on the form has been loaded. May be after the closing form tag "</form>" in the html
Actually, I believe that would be

document.getElementById("uc1_txt1").focus();

(note the underscore instead of colon)
Yeah Peter is correct it should be

document.getElementById("uc1_txt1").focus();
oops. Sorry for the mistake. It should be underscore. Thanks for correcting me guys
Check out this :view post 821121

regards

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 a Text Box Field on a User Web Control

I would like to set focus to a text box field on a user web control. Does
anyone have suggestions on how I should approach this?Something basic like this should work:
Response.Write "<script language = javascript>"& MyTextBox.ClientID &
".focus()</script>"
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Mike Moore" <MikeMoore@.discussions.microsoft.com> wrote in message
news:8EEBC0E1-E38B-4B43-9D8A-889C3E85DF1B@.microsoft.com...
>I would like to set focus to a text box field on a user web control. Does
> anyone have suggestions on how I should approach this?

Set Focus to a Text Box Field on a User Web Control

I would like to set focus to a text box field on a user web control. Does
anyone have suggestions on how I should approach this?Something basic like this should work:

Response.Write "<script language = javascript>"& MyTextBox.ClientID &
".focus()</script>"

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

"Mike Moore" <MikeMoore@.discussions.microsoft.com> wrote in message
news:8EEBC0E1-E38B-4B43-9D8A-889C3E85DF1B@.microsoft.com...
>I would like to set focus to a text box field on a user web control. Does
> anyone have suggestions on how I should approach this?

Tuesday, March 13, 2012

set ReadOnly to radio button and check box

How can I set ReadOnly to radio button and check box ??

Million thanks.Enabled Property.

Av.
"Grey" <ericyum@.i-cable.com> wrote in message news:eMC79JuREHA.2704@.TK2MSFTNGP10.phx.gbl...
How can I set ReadOnly to radio button and check box ??

Million thanks.

set ReadOnly to radio button and check box

How can I set ReadOnly to radio button and check box '
Million thanks.Enabled Property.
Av.
"Grey" <ericyum@.i-cable.com> wrote in message news:eMC79JuREHA.2704@.TK2MSFTN
GP10.phx.gbl...
How can I set ReadOnly to radio button and check box '
Million thanks.