Showing posts with label webform. Show all posts
Showing posts with label webform. Show all posts

Monday, March 26, 2012

Text in a textbox

On my webform I have a textbox. When the page loads I put some text in the textbox. The text is 2 sentences and all I want to do is to put the sentences on different lines.

It use to be so simple:

textbox1.text = "Sentence1." & vbCrLf & "Sentence2."

The above doesn't seem to work the sentences are on the same line.

Please help with this simple thing....

Thanks

************************************************** ********************
Sent via Fuzzy Software @dotnet.itags.org. http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...is the textbox.textmode set to "MultiLine" ?

"Paul P" <pphillips@.rattanconsulting.com> wrote in message
news:OF3GSQN8DHA.1672@.TK2MSFTNGP12.phx.gbl...
> On my webform I have a textbox. When the page loads I put some text in
the textbox. The text is 2 sentences and all I want to do is to put the
sentences on different lines.
> It use to be so simple:
> textbox1.text = "Sentence1." & vbCrLf & "Sentence2."
> The above doesn't seem to work the sentences are on the same line.
> Please help with this simple thing....
> Thanks
> ************************************************** ********************
> Sent via Fuzzy Software @. http://www.fuzzysoftware.com/
> Comprehensive, categorised, searchable collection of links to ASP &
ASP.NET resources...
I tried the multiline option but it has the scroll bar on it and I don't want to see the scroll bars. If you know of a way to get rid of the scroll bars, please let me know.

************************************************** ********************
Sent via Fuzzy Software @. http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
> I tried the multiline option but it has the scroll bar on it and I don't
want to see the scroll bars. If you know of a way to get rid

Sure. Use an editable Div instead. You can make it look any way you want it
to. If you need server-side functionality, use the Panel Control, which
renders a Div.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Paul P" <pphillips@.rattanconsulting.com> wrote in message
news:eS97SWN8DHA.2404@.TK2MSFTNGP12.phx.gbl...
> I tried the multiline option but it has the scroll bar on it and I don't
want to see the scroll bars. If you know of a way to get rid of the scroll
bars, please let me know.
> ************************************************** ********************
> Sent via Fuzzy Software @. http://www.fuzzysoftware.com/
> Comprehensive, categorised, searchable collection of links to ASP &
ASP.NET resources...
Paul,

You'll have to set the text box to multi-line to get your two lines of text.

One way to get rid of the scroll bar would be to use cascading style sheets:

..TextBox {
overflow: hidden
}

You could add this to your page's style sheet and then assign ".TextBox" to
the CssStyle of the text box.

The choices you may assign to overflow are:

auto - If the content is clipped, the browser should display a scroll-bar to
see the rest of the content

hidden - The content is clipped, but the browser does not display a
scroll-bar to see the rest of the content

scroll - The content is clipped, but the browser displays a scroll-bar to
see the rest of the content

visible - The content is not clipped. It renders outside the element.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche

"Paul P" <pphillips@.rattanconsulting.com> wrote in message
news:eS97SWN8DHA.2404@.TK2MSFTNGP12.phx.gbl...
> I tried the multiline option but it has the scroll bar on it and I don't
want to see the scroll bars. If you know of a way to get rid of the scroll
bars, please let me know.
> ************************************************** ********************
> Sent via Fuzzy Software @. http://www.fuzzysoftware.com/
> Comprehensive, categorised, searchable collection of links to ASP &
ASP.NET resources...
This is a better solution than the div solution I offered, if the content is
supposed to be editable, and if the content should be posted back to the
server.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"S. Justin Gengo" <sjgengo@.aboutfortunate.com> wrote in message
news:e77CboN8DHA.3288@.TK2MSFTNGP11.phx.gbl...
> Paul,
> You'll have to set the text box to multi-line to get your two lines of
text.
> One way to get rid of the scroll bar would be to use cascading style
sheets:
> .TextBox {
> overflow: hidden
> }
> You could add this to your page's style sheet and then assign ".TextBox"
to
> the CssStyle of the text box.
> The choices you may assign to overflow are:
> auto - If the content is clipped, the browser should display a scroll-bar
to
> see the rest of the content
> hidden - The content is clipped, but the browser does not display a
> scroll-bar to see the rest of the content
> scroll - The content is clipped, but the browser displays a scroll-bar to
> see the rest of the content
> visible - The content is not clipped. It renders outside the element.
> --
> Sincerely,
> S. Justin Gengo, MCP
> Web Developer / Programmer
> Free code library at:
> www.aboutfortunate.com
> "Out of chaos comes order."
> Nietzche
>
> "Paul P" <pphillips@.rattanconsulting.com> wrote in message
> news:eS97SWN8DHA.2404@.TK2MSFTNGP12.phx.gbl...
> > I tried the multiline option but it has the scroll bar on it and I don't
> want to see the scroll bars. If you know of a way to get rid of the
scroll
> bars, please let me know.
> > ************************************************** ********************
> > Sent via Fuzzy Software @. http://www.fuzzysoftware.com/
> > Comprehensive, categorised, searchable collection of links to ASP &
> ASP.NET resources...

Tuesday, March 13, 2012

TextBox - MaxLength property

I have a MultiLine TextBox (WebForm - C#) with the MaxLength property = 1000
but am able to type in an unlimited number of characters. Is there a way to
limit the number of characters that can be typed into this TextBox?only the TextBox.TextMode = "singleLine" or "password" , the
TextBox.MaxLength property is valid
so when you set TextBox.TextMode=MutilLine, the MaxLength property not valid
"mg" <mg@.theworld.com> д?
news:46B9FAB4-A15C-4014-AC26-2A99413A67C6@.microsoft.com...
> I have a MultiLine TextBox (WebForm - C#) with the MaxLength property =
1000 but am able to type in an unlimited number of characters. Is there a
way to limit the number of characters that can be typed into this TextBox?

TextBox - MaxLength property

I have a MultiLine TextBox (WebForm - C#) with the MaxLength property = 1000 but am able to type in an unlimited number of characters. Is there a way to limit the number of characters that can be typed into this TextBox?only the TextBox.TextMode = "singleLine" or "password" , the
TextBox.MaxLength property is valid
so when you set TextBox.TextMode=MutilLine, the MaxLength property not valid

"mg" <mg@.theworld.com> д?
news:46B9FAB4-A15C-4014-AC26-2A99413A67C6@.microsoft.com...
> I have a MultiLine TextBox (WebForm - C#) with the MaxLength property =
1000 but am able to type in an unlimited number of characters. Is there a
way to limit the number of characters that can be typed into this TextBox?

TextBox - MaxLength property

I have a MultiLine TextBox (WebForm - C#) with the MaxLength property = 1000 but am able to type in an unlimited number of characters. Is there a way to limit the number of characters that can be typed into this TextBox?only the TextBox.TextMode = "singleLine" or "password" , the
TextBox.MaxLength property is valid
so when you set TextBox.TextMode=MutilLine, the MaxLength property not valid

"mg" <mg@.theworld.com> д?
news:46B9FAB4-A15C-4014-AC26-2A99413A67C6@.microsoft.com...
> I have a MultiLine TextBox (WebForm - C#) with the MaxLength property =
1000 but am able to type in an unlimited number of characters. Is there a
way to limit the number of characters that can be typed into this TextBox?
only the TextBox.TextMode = "singleLine" or "password" , the
TextBox.MaxLength property is valid
so when you set TextBox.TextMode=MutilLine, the MaxLength property not valid

"mg" <mg@.theworld.com> д?
news:46B9FAB4-A15C-4014-AC26-2A99413A67C6@.microsoft.com...
> I have a MultiLine TextBox (WebForm - C#) with the MaxLength property =
1000 but am able to type in an unlimited number of characters. Is there a
way to limit the number of characters that can be typed into this TextBox?

Textbox and mouse focus

Hi,

I have webform that uses 1 customized user controls(contain textbox1 and textbox2). When the form loads, I want to put the mouse focus on the user controls textbox1. Is this possible?

Thanks in advance!Again in my case I'm trying to position on a textbox1 inside a user control(name.ascx) that is called by home.aspx page.

When I add the below code to the page_load event of home.aspx, it gave the error.

Dim strbuilder As StringBuilder = New StringBuilder

strbuilder.Append("<script language='javascript'>")

strbuilder.Append(" window.document.getElementById('txtkeywords').focus()")

strbuilder.Append("</script>")

RegisterStartupScript("Focus", strbuilder.ToString)

Error:
Microsoft JScript runtime error: 'window.document.getElementById(...)' is null or not an object

Any help is grealty appreciated
Say that your user control has the ID of "myUserControl".

You would then change your code from:

 strbuilder.Append(" window.document.getElementById('txtkeywords').focus()")
to
 strbuilder.Append(" window.document.getElementById('" & myUserContro.FindControl('txtkeywords').ClientID & "').focus()")

Admittedly, I haven't tested this ... but it should work.
I replaced the code you gave me, but it gave me a Expression Expected error, indicated in between getElementbyID and (. Since I don't know Javascript well, I remove the two "s from your code and it gave me runtime error: Expected ')' on this line of code. How do I make this work?

Thanks for you help.
My apologies, I should have tested the code before I posted it.

Here is the user control:

 <%@. Control Language="VB" %>
<script runat="server"
Function GetTextboxID() As String
Return txtkeywords.ClientID
End Function

</script>
<p>I am the UserControl</p>
<p>Keywords: <asp:Textbox id="txtkeywords" runat="server" /></p>


The only interesting thing is that I've given the User Control a method called GetTextboxID. This simply returns the ClientID property of its Textbox control. You see, when the page finally renders, the ID of this textbox will no longer be "txtkeywords". It will be the ID of the user controlplus the ID of the textbox, separated by an underscore: myUserControl_txtkeywords.

This is why your code was never working ... the Javascript was looking for a control with the ID txtkeywords, when what it should be looking for was the ID myUserControl_txtkeywords.

And we've now given our User Control a method that returns this extended ID (known as the ClientID).

So, we can now update our ASPX Page so that it calls this function when creating the focus Javascript function:

 <%@. Page Language="VB" %>
<%@. Register TagPrefix="my" TagName="UserControl" src="http://pics.10026.com/?src=mycontrol15.ascx" %>
<script runat="server"
Sub Page_Load( sender As Object, eArgs As EventArgs )
Dim focusScript As Text.StringBuilder = New Text.StringBuilder
focusScript.Append("<scr" & "ipt language=""javascript"" type=""text/javascript"">")
focusScript.Append("window.document.getElementById('" &myUserControl.GetTextboxID() & "').focus()")
focusScript.Append("</scr" & "ipt>")
RegisterStartupScript("FocusScript", focusScript.ToString)
End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<h3>Page Header</h3>
<hr />
<my:UserControl id="myUserControl" runat="server" />
<hr />
<h4>Page Footer</h4>
</form>
</body>
</html>

Does that work for you?
Thanks for your help! But, I created a usercontrol and a form and copied your code. When I run it, it doesn't place the focus on textbox. what went wrong?

here are my code:
myControl.ascx


<%@. Control Language="vb" AutoEventWireup="false" Codebehind="myControl.ascx.vb" Inherits="SettingFocus.myControl" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<script runat="server"
Function GetTextboxID() As String

Return txtkeywords.ClientID

End Function

</script>
<p>I am the UserControl</p>
<p>Keywords:
<asp:Textbox id="txtkeywords" runat="server" /></p

And the form file DefaultFocus.aspx


<%@. Register TagPrefix="my" TagName="UserControl" src="http://pics.10026.com/?src=myControl.ascx" %>
<%@. Page Language="vb" AutoEventWireup="false" Codebehind="DefaultFocus.aspx.vb" Inherits="SettingFocus.DefaultFocus"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<script runat="server"
Sub Page_Load( sender As Object, eArgs As EventArgs )

Dim focusScript As Text.StringBuilder = New Text.StringBuilder

focusScript.Append("<scr" & "ipt language=""javascript"" type=""text/javascript"">")

focusScript.Append("window.document.getElementById('" & myUserControl.GetTextboxID() & "').focus()")

focusScript.Append("</scr" & "ipt>")

RegisterStartupScript("FocusScript", focusScript.ToString)

End Sub

</script
<html
<head
</head
<body
<form runat="server" ID="Form1"
<h3>Page Header</h3
<hr /
<my:UserControl id="myUserControl" runat="server" /
<hr /
<h4>Page Footer</h4
</form
</body
</html>


We'll need to update our code slightly as you're using the codebehind method.

Here is our Control.ascx user control. I've now removed the inline code:

 <%@. Control AutoEventWireup="False" Inherits="Test.ControlCodebehind" %>
<p>I am the UserControl</p>
<p>Keywords: <asp:Textbox id="txtkeywords" runat="server" /></p>

The code has now moved into the codebehind:

 Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace Test

Public Class ControlCodebehind
Inherits System.Web.UI.UserControl

Protected txtkeywords As Textbox

Function GetTextboxID() As String
Return txtkeywords.ClientID
End Function

End Class

End Namespace

Our page.aspx also has its inline code removed:

 <%@. Page AutoEventWireup="False" Inherits="Test.PageCodebehind" %>
<%@. Register TagPrefix="my" TagName="UserControl" src="http://pics.10026.com/?src=control.ascx" %>
<html>
<head>
</head>
<body>
<form runat="server">
<h3>Page Header</h3>
<hr />
<my:UserControl id="myUserControl" runat="server" />
<hr />
<h4>Page Footer</h4>
</form>
</body>
</html>

And the code is moved into its codebehind. I've highlighted the only real change:

 Imports System
Imports System.Text
Imports System.Web.UI

Namespace Test

Public Class PageCodebehind
Inherits System.Web.UI.Page

Protected myUserControl As Test.ControlCodebehind

Protected Sub Page_Load( ByVal sender As Object, ByVal eArgs As System.EventArgs ) Handles MyBase.Load

Dim focusScript As StringBuilder = New StringBuilder
focusScript.Append("<scr" & "ipt language=""javascript"" type=""text/javascript"">")
focusScript.Append("window.document.getElementById('" & myUserControl.GetTextboxID() & "').focus()")
focusScript.Append("</scr" & "ipt>")
RegisterStartupScript("FocusScript", focusScript.ToString)

End Sub

End Class

End Namespace


As you can see, the only real change is that we've declared our myUserControl not as a UserControl, but as the class name for our user control's codebehind.

Does that help?
NO Luck. I'm getting the same result. I'm wondering if the code works on your pc. If it does then there must be something else other than the source code that is causing the problem. I'm running Visual Studio .NET 2003, with framework 1.1 and IIS 5.
> I'm wondering if the code works on your pc.

It sure does, because I made a test app called DotNetBeginner in IIS, with the code shown. (I too use .NET 1.1 on IIS 5.)

You can download this test app:
www.edition3.com/developers/DotNetBeginner/code.zip

Create a new folder within \wwwroot and unzip the files. Use IIS to configure this new folder as an app. And then request page.aspx.

Let me know if that works.
Not to step on SomeNewKid's efforts, I'm sure his code will work, I haven't tested it, but when I want to simply set focus on a textbox, this is what I do...

Let's say my textbox name is txtEntry.
In the page_load event, I place this code.


Me.SetFocus(Me.txtEntry)

Then, elsewhere, I create this...

Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
Dim s As String = "<SCRIPT language='javascript'>document.getElementById('" & ctrl.ID & "').focus() </SCRIPT>"
RegisterStartupScript("focus", s)
End Sub

And that's it. You can put the Me.SetFocus(Me.txtEntry) anywhere on your page as well.

Hope this helps as well,

Zath
Hi.. how about if i want to put the coding in a .cs file? i found that it have an error on this line

RegisterStartupScript("focus", s)?

The name 'RegisterStartupScript' does not exist in the class or namespace 'Utilities.HandleUtil.HandlerUtil'

What wrong actually?

Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)

Dim s As String = "<SCRIPT language='javascript'>document.getElementById('" & ctrl.ID & "').focus() </SCRIPT>"

RegisterStartupScript("focus", s)

End Sub
RegisterStartupScript is a method of System.Web.UI.Page.

So RegisterStartupScript really needs to be used within your codebehind ... not within a Utility class.

Although, if you like, the Utility class can generate the script, but the codebehind actually places it on the Page with RegisterStartupScript.
Hi SomeNewKid,

This maybe a dumb question, but since I'm a beginner, please don't mind me asking. How do configure the new folder as an application in IIS?

Thanks
Gwen
Open the Internet Services Manager (under Administrative tools) expand
your website and right-click on webserver, select all tasks->New virtual directory,
give it a name, browse to the direcotry that contains the files, and voila
you have configured your application!

Regards
Fredr!k
I do it aslightly different way to Fredrick2000.

To make it easy, I've created a little tutorial with screenshots, starting here:
www.edition3.com/developers/DotNetBeginner/step1.htm

I hope this helps.