Save the value from Multiline Textbox into SQL Server with line brea - asp.net

I got one multiline textbox call txtDesc.
The user can key in multiline value such as :
Hai.
I'm robot.
Please feed me.
I want to save into database with the line break and will display it back later as user key in.
if i save the value as below code, the line break will not save.
dim strDesc as string = txtDesc.text
how to make this happen?
Thank you.

Love the sample text :)
How are you saving and loading this to/from SQL ? If I have a multiline textbox, the .Text property includes the line break character -
"Hai.\n\I'm robot.\n\Please feed me."
I save this into an NVARCHAR(MAX) field in a table in SQL, and when I load it back into the textbox, I get the line breaks exactly as it was typed in.
Can you post your your load/save code ?

i got the answer :
To save from multiline textbox to database :
Dim strDesc As String
strDesc = ReplaceNewLines(txtDesc.Text, True)
To show back from database to multiline textbox :
strDesc = productDetails.ProductDesc.Replace("<br/>", vbCrLf)
txtDesc.Text = strDesc

Related

Convert from string to textbox object

I am trying to convert a string to textbox, but I am getting an error that it cannot convert to integer?!
I have the following code:
Dim curr As String
curr = "Detail_0107"
Dim NEWTEXT As TextBox = TryCast(Me.Controls(curr), TextBox)
NEWTEXT.Text = "test"
On the TryCast, I get the following error:
Conversion from string "Detail_0107" to type 'Integer' is not valid
Detail_0107 is a textbox on my form. Can I do this?
Thanks
Your problem seems to be that you're setting Detail_0107 as a string. If you want to set the text of Detail_0107, all you need to do is the following:
Detail_0107.Text = "test"
As you said Detail_0107 is already a textbox on your form, there shoud already be an object for it.
Try using Me.Controls.Find(curr) instead. Additionally, every control has a .Text property. It's part of the base Control type, and therefore you have no need to cast to TextBox. If you're very sure the Detail_0107 control does exist in that collection, you can get the code down to just this:
Me.Controls.Find("Detail_0107").Text = "test"

How to set crystal report's textbox value at run time?

How to set crystal report's textbox value at run time. I have a textbox in section2 (page header) in crystal report, now I have to set Text property of this textbox at run time. Basically I have to pass user name in this textbox.
You can change textbox text in runtime. You can use this:
using CrystalDecisions.CrystalReports.Engine;
rptMyReport report = new rptMyReport();
TextObject to = (TextObject)report.ReportDefinition.Sections["Section2"].ReportObjects["textboxname"];
to.Text = newvalue;
The another way is to use parameters.
If you have the user name before the report opens you can add a parameter field (string) to the report and then put that field on the report where you want it to appear at runtime. You will just need to pass it into the report as a parameter just like you would any other parameter.
Dim UserName As String = "BukHix"
crDOC.SetParameterValue("UserName", UserName)
try this
((TextObject)rpt.Section2.ReportObjects["Textbox"]).Text = "yourvalue";

How to use findcontrol in createuserwizard1 complete step ...?

Is this the right declaration of findcontrol for complete step of createuserwizard1 ?
Dim UserName As TextBox = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Label11")
But when i use it its shows the error object expected !
What was the problem ?
You can't set the value of a Textbox to a generic control (especially one that is really a label). Plus you forgot the New keyword when initializing UserName. Depending on exactly what you're trying to do, you may want to try the following...
'This will set the textbox's Text to the label's text.
Dim UserName As New Textbox
UserName.Text = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Label11"), Label).Text
Or
'This will cast the label to a new label control you define in code.
Dim UserName as New Label
UserName = CType(CreateUserWizard2.CreateUserStep.ContentTemplateContainer.FindControl("Label11"), Label)

Dynamically Reference an Object Property Using a String

I'm trying to reference a public property from a string. How can this be done in vb.net?
I have the text value of "FirstName" stored in strucParam(i).TxtPropertyName.
This is what I'm currently doing:
Dim tmpValue As String
Dim ucAppName As UserControl_appName = CType(Parent.FindControl(strucParam(i).ParentFindControl), UserControl_appName)
tmpValue = ucAppName.FirstName.Text
How can I use the value in strucParam(i).TxtPropertyName so that I can remove ".FirstName" from my code? Thanks!
This is basically a duplicate of this question, but I'll answer it for you since you're a VB user and probably didn't consider C# in your searches.
Suppose you have an object of any type stored in a variable called objObject, and the name of the property stored in a variable called strPropertyName. You do the following:
tmpValue = objObject.GetType().GetProperty(strPropertyName).GetValue(objObject, Nothing)
As a final note: please, please consider dropping pseudo-Hungarian notation. It's of no value when working with a statically typed language like VB.NET.
Edit:
The FirstName property is in reality a text box. So don't I need to somehow reference .Text in the code?
tmpFirstName = ucAppName.GetType().GetProperty(strucParam(i).PropertyName).GetValue(objAppNav, Nothing)
Try this:
Dim textBox as TextBox
Dim tmpValue as String
textBox = CType(ucAppName.GetType().GetProperty(strucParam(1).PropertyName).GetValue(objAppNav, Nothing), TextBox)
tmpValue = textBox.Text
Basically, you have to cast the value of the property to a TextBox type, then grab the Text property from it.

Getting Text property in codebehind from ASP.NET TextBox with TextMode = Password

I have a <asp:TextBox with TextMode="Password". How can I read the value that the user entered, using the codebehind?
I want to create a new user with code like this, but PasswordTextBox.Text is always an empty string.
Membership.CreateUser(Username, PasswordTextBox.Text)
That's correct. You're probably setting PasswordTextBox.Text = '' in the Page_Load(). Don't do that if IsPostback() is true:
if not IsPostback() then
PasswordTextBox.Text = ''
end if
there has to be something else going on. I have no problems getting the value in TextBox.Text.
There's nothing special about reading a password text box. I'm guessing the problem is somewhere else in your code. Do you happen to overwrite the values in the Page_Load()?

Resources