Showing posts with label textbox. Show all posts
Showing posts with label textbox. Show all posts

Saturday, March 31, 2012

Trim Each textbox control - Repost

HI

I'm trying to iterate through all the textboxes on a webpage and trim
them for spaces.

i.e. If a user enters " hello world " we correct it to "hello
world"

So far I've come up with this:

------------------------

'Trim all textboxes
Dim ThisControl As System.Web.UI.Control
For Each ThisControl In Me.Controls

If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then

ThisControl.text = Trim(ThisControl.text)
'Above line is wrong syntax, I want to trim the textbox here, but I'm
stuck! Please help...

End If

Next ThisControl

------------------------

The problem I have is not really with the trim function. It's the fact
that I cannot update the control text value. It won't allow the .text
property at all in this example because "thiscontrol" is not actually
aware that the control assigned to it is actually a textbox. Is there a
way to tell it it's a textbox so I can access this property, or is there
another way around this?

Can you help?

Many Thanks!

AlexHi,

here is an example how to loop through controls on the Page:
http://www.aspnet101.com/aspnet101/tips.aspx?id=97

If you want to access Text property, you need to have typed reference (cast
it to TextBox with CType and set the value to the property).

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"Alex Shirley" <postings@.alexshirley.com> wrote in message
news:e9704b08.0406280400.238ba501@.posting.google.c om...
> HI
> I'm trying to iterate through all the textboxes on a webpage and trim
> them for spaces.
> i.e. If a user enters " hello world " we correct it to "hello
> world"
> So far I've come up with this:
> -----------------------
--
> 'Trim all textboxes
> Dim ThisControl As System.Web.UI.Control
> For Each ThisControl In Me.Controls
> If ThisControl.GetType().ToString() =
> "system.Web.UI.WebControls.TextBox" Then
> ThisControl.text = Trim(ThisControl.text)
> 'Above line is wrong syntax, I want to trim the textbox here, but I'm
> stuck! Please help...
> End If
> Next ThisControl
> -----------------------
--
> The problem I have is not really with the trim function. It's the fact
> that I cannot update the control text value. It won't allow the .text
> property at all in this example because "thiscontrol" is not actually
> aware that the control assigned to it is actually a textbox. Is there a
> way to tell it it's a textbox so I can access this property, or is there
> another way around this?
>
> Can you help?
> Many Thanks!
> Alex
Thanks Teemu

However I'm still stuck with the casting the object I've discovered in
a for next loop to a textbox so I can access its properties in
VB/ASP.Net... dumb I know, but I've looked everywhere for an answer,
but obviously not in the right places!

So far I've got this code:

-----------

Dim ThisControl As System.Web.UI.Control
Dim txtControl As TextBox

For Each ThisControl In Me.Controls
If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then
txtControl = CType(ThisControl, TextBox) ' am I casting this
correctly?
txtControl.Text = "I'vechanged" 'Doesn't work
End If
Next ThisControl

-----------

I tried ThisControl = CType(ThisControl, TextBox), but the properties
won't appear for thiscontrol.

Sorry but can you or somebody help in this casting so I can update or
get the text property?

Thanks

Alex

"Teemu Keiski" <joteke@.aspalliance.com> wrote in message news:<elLAShQXEHA.4064@.TK2MSFTNGP11.phx.gbl>...
> Hi,
> here is an example how to loop through controls on the Page:
> http://www.aspnet101.com/aspnet101/tips.aspx?id=97
> If you want to access Text property, you need to have typed reference (cast
> it to TextBox with CType and set the value to the property).
> --
> Teemu Keiski
> MCP, Microsoft MVP (ASP.NET), AspInsiders member
> ASP.NET Forum Moderator, AspAlliance Columnist
> http://blogs.aspadvice.com/joteke
> "Alex Shirley" <postings@.alexshirley.com> wrote in message
> news:e9704b08.0406280400.238ba501@.posting.google.c om...
> > HI
> > I'm trying to iterate through all the textboxes on a webpage and trim
> > them for spaces.
> > i.e. If a user enters " hello world " we correct it to "hello
> > world"
> > So far I've come up with this:
> > -----------------------
> --
> > 'Trim all textboxes
> > Dim ThisControl As System.Web.UI.Control
> > For Each ThisControl In Me.Controls
> > If ThisControl.GetType().ToString() =
> > "system.Web.UI.WebControls.TextBox" Then
> > ThisControl.text = Trim(ThisControl.text)
> > 'Above line is wrong syntax, I want to trim the textbox here, but I'm
> > stuck! Please help...
> > End If
> > Next ThisControl
> > -----------------------
> --
> > The problem I have is not really with the trim function. It's the fact
> > that I cannot update the control text value. It won't allow the .text
> > property at all in this example because "thiscontrol" is not actually
> > aware that the control assigned to it is actually a textbox. Is there a
> > way to tell it it's a textbox so I can access this property, or is there
> > another way around this?
> > Can you help?
> > Many Thanks!
> > Alex

Trim Each textbox control

HI
I'm trying to iterate through all the textboxes on a webpage and trim
them for spaces.
i.e. If a user enters " hello world " we correct it to "hello
world"
So far I've come up with this:
----
--
'Trim all textboxes
Dim ThisControl As System.Web.UI.Control
For Each ThisControl In Me.Controls
If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then
ThisControl.text = Trim(ThisControl.text)
'Above line is wrong syntax, I want to trim the textbox here, but I'm
stuck! Please help...
End If
Next ThisControl
----
--
Can you help?
Many Thanks!
Alexuse RTrim() and LTrim().
R for right and L for the left side to remove spaces.
"Alex Shirley" <postings@.alexshirley.com> schreef in bericht
news:e9704b08.0406240318.6e352a45@.posting.google.com...
> HI
> I'm trying to iterate through all the textboxes on a webpage and trim
> them for spaces.
> i.e. If a user enters " hello world " we correct it to "hello
> world"
> So far I've come up with this:
> ----
--
> 'Trim all textboxes
> Dim ThisControl As System.Web.UI.Control
> For Each ThisControl In Me.Controls
> If ThisControl.GetType().ToString() =
> "system.Web.UI.WebControls.TextBox" Then
> ThisControl.text = Trim(ThisControl.text)
> 'Above line is wrong syntax, I want to trim the textbox here, but I'm
> stuck! Please help...
> End If
> Next ThisControl
> ----
--
> Can you help?
> Many Thanks!
> Alex
Hi Richard
The problem I have is not really with the trim function. It's the fact
that I cannot update the control text value. It won't allow the .text
property at all in this example because "thiscontrol" is not actually
aware that the control assigned to it is actually a textbox. Is there a
way to tell it it's a textbox so I can access this property, or is there
another way around this?
Any answers folks?
Cheers
Alex
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Trim Each textbox control

HI

I'm trying to iterate through all the textboxes on a webpage and trim
them for spaces.

i.e. If a user enters " hello world " we correct it to "hello
world"

So far I've come up with this:

------------------------

'Trim all textboxes
Dim ThisControl As System.Web.UI.Control
For Each ThisControl In Me.Controls

If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then

ThisControl.text = Trim(ThisControl.text)
'Above line is wrong syntax, I want to trim the textbox here, but I'm
stuck! Please help...

End If

Next ThisControl

------------------------

Can you help?

Many Thanks!

Alexuse RTrim() and LTrim().
R for right and L for the left side to remove spaces.

"Alex Shirley" <postings@.alexshirley.com> schreef in bericht
news:e9704b08.0406240318.6e352a45@.posting.google.c om...
> HI
> I'm trying to iterate through all the textboxes on a webpage and trim
> them for spaces.
> i.e. If a user enters " hello world " we correct it to "hello
> world"
> So far I've come up with this:
> -----------------------
--
> 'Trim all textboxes
> Dim ThisControl As System.Web.UI.Control
> For Each ThisControl In Me.Controls
> If ThisControl.GetType().ToString() =
> "system.Web.UI.WebControls.TextBox" Then
> ThisControl.text = Trim(ThisControl.text)
> 'Above line is wrong syntax, I want to trim the textbox here, but I'm
> stuck! Please help...
> End If
> Next ThisControl
> -----------------------
--
> Can you help?
> Many Thanks!
> Alex
Hi Richard

The problem I have is not really with the trim function. It's the fact
that I cannot update the control text value. It won't allow the .text
property at all in this example because "thiscontrol" is not actually
aware that the control assigned to it is actually a textbox. Is there a
way to tell it it's a textbox so I can access this property, or is there
another way around this?

Any answers folks?

Cheers

Alex

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Trim Each textbox control - Repost

HI
I'm trying to iterate through all the textboxes on a webpage and trim
them for spaces.
i.e. If a user enters " hello world " we correct it to "hello
world"
So far I've come up with this:
----
--
'Trim all textboxes
Dim ThisControl As System.Web.UI.Control
For Each ThisControl In Me.Controls
If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then
ThisControl.text = Trim(ThisControl.text)
'Above line is wrong syntax, I want to trim the textbox here, but I'm
stuck! Please help...
End If
Next ThisControl
----
--
The problem I have is not really with the trim function. It's the fact
that I cannot update the control text value. It won't allow the .text
property at all in this example because "thiscontrol" is not actually
aware that the control assigned to it is actually a textbox. Is there a
way to tell it it's a textbox so I can access this property, or is there
another way around this?
Can you help?
Many Thanks!
AlexHi,
here is an example how to loop through controls on the Page:
http://www.aspnet101.com/aspnet101/tips.aspx?id=97
If you want to access Text property, you need to have typed reference (cast
it to TextBox with CType and set the value to the property).
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke
"Alex Shirley" <postings@.alexshirley.com> wrote in message
news:e9704b08.0406280400.238ba501@.posting.google.com...
> HI
> I'm trying to iterate through all the textboxes on a webpage and trim
> them for spaces.
> i.e. If a user enters " hello world " we correct it to "hello
> world"
> So far I've come up with this:
> ----
--
> 'Trim all textboxes
> Dim ThisControl As System.Web.UI.Control
> For Each ThisControl In Me.Controls
> If ThisControl.GetType().ToString() =
> "system.Web.UI.WebControls.TextBox" Then
> ThisControl.text = Trim(ThisControl.text)
> 'Above line is wrong syntax, I want to trim the textbox here, but I'm
> stuck! Please help...
> End If
> Next ThisControl
> ----
--
> The problem I have is not really with the trim function. It's the fact
> that I cannot update the control text value. It won't allow the .text
> property at all in this example because "thiscontrol" is not actually
> aware that the control assigned to it is actually a textbox. Is there a
> way to tell it it's a textbox so I can access this property, or is there
> another way around this?
>
> Can you help?
> Many Thanks!
> Alex
Thanks Teemu
However I'm still stuck with the casting the object I've discovered in
a for next loop to a textbox so I can access its properties in
VB/ASP.Net... dumb I know, but I've looked everywhere for an answer,
but obviously not in the right places!
So far I've got this code:
Dim ThisControl As System.Web.UI.Control
Dim txtControl As TextBox
For Each ThisControl In Me.Controls
If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then
txtControl = CType(ThisControl, TextBox) ' am I casting this
correctly?
txtControl.Text = "I'vechanged" 'Doesn't work
End If
Next ThisControl
I tried ThisControl = CType(ThisControl, TextBox), but the properties
won't appear for thiscontrol.
Sorry but can you or somebody help in this casting so I can update or
get the text property?
Thanks
Alex
"Teemu Keiski" <joteke@.aspalliance.com> wrote in message news:<elLAShQXEHA.4064@.TK2MSFTNGP1
1.phx.gbl>...
> Hi,
> here is an example how to loop through controls on the Page:
> http://www.aspnet101.com/aspnet101/tips.aspx?id=97
> If you want to access Text property, you need to have typed reference (cas
t
> it to TextBox with CType and set the value to the property).
> --
> Teemu Keiski
> MCP, Microsoft MVP (ASP.NET), AspInsiders member
> ASP.NET Forum Moderator, AspAlliance Columnist
> http://blogs.aspadvice.com/joteke
> "Alex Shirley" <postings@.alexshirley.com> wrote in message
> news:e9704b08.0406280400.238ba501@.posting.google.com...
> --
> --

Trim TextBox spaces

I am facing difficulity of having to Trim Spaces in Textbox.I am given a task of needing to trim spaces in the textbox and not to allow space at the front and at the back of the textbox as when u enter a space in front of the textbox it will be a totally different data from the one which has no space. So can anyone help me about the trim in Asp.net 2.0 c# languague.

<trclass="i4">

<tdclass="i5">

<span><span><spanclass="i6">C</span>USTCODE</span><spanclass="i6">

</span>

</span>

</td>

<tdclass="i7">

<asp:RequiredFieldValidatorID="RequiredFieldValidator2"runat="server"ControlToValidate="CUSTCODETextBox"

ErrorMessage="*"Font-Bold="False"></asp:RequiredFieldValidator></td>

<tdcolspan="2"class="i8">

<asp:TextBoxID="CUSTCODETextBox"runat="server"Text='<%# Bind("CUSTCODE") %>'MaxLength="20"></asp:TextBox></td>

<tdrowspan="10"class="i9"></td>

When you are saving the data in your code behind, you can trim the text using this code:

string customerCode = CUSTOMCODETextBox.Text.Trim();

That will get you the value entered by the user, without any leading or trailing spaces.

Wednesday, March 28, 2012

Trouble Declaring and Setting Variable

I have a page that sends the value of a textbox in a form through GET.

My next page is supposed to grab that value, and put it in a variable. This is what I have for my next page:

1<%@dotnet.itags.org. Import namespace="System.IO"%>2<html>
3<head>
4<title>Uploading a File</title>
5678<script language="VB" runat="server">
9Dim strPath
10 strPath = Request.QueryString("path")
11
12 Dim savePath As String = StrPath
13Sub Upload_Click(source As Object, e As EventArgs)
1415 If Not (uploadedFile.PostedFile Is Nothing) Then
16 Try
17 Dim postedFile = uploadedFile.PostedFile
18 Dim filename As String = Path.GetFileName(postedFile.FileName)
19 Dim contentType As String = postedFile.ContentType
20 Dim contentLength As Integer = postedFile.ContentLength
2122 postedFile.SaveAs(savePath & filename)
23 message.Text = postedFile.Filename & " uploaded" & _
24 "<br>content type: " & contentType & _
25 "<br>content length: " & contentLength.ToString()
26 Catch exc As Exception
27 message.Text = "Failed uploading file"
28 End Try
29 End If
30End Sub
31</script>
32
33</head>
34<body>
35
36<form id="Form1" enctype="multipart/form-data" runat="server">
37 Select File to Upload:
3839 <input id="uploadedFile" type="file" runat="server">
40 <p>
41 <input type=button id="upload"
42 value="Upload"
43 OnServerClick="Upload_Click"
44 runat="server">
45 <p>
46 <asp:Label id="message" runat="server"/>
47</form>
48
49</body>
50</html>

I get a "declaration expected" on line 10. Any Ideas why?

A simle fix is to move both lines

Dim strPath as String = Request.QueryString("path")
Dim savePath As String = StrPath

to the top of Sub Upload_Click.


The actual error is that line 9 is not complete with a type declaration.

Dim strPathAs String

Also, you don't seem to need both strPath and savePath.

Dim savePath As String = Request.QueryString("path")
should be enough 


Gunteman, I must respectfully disagree. If you put

Dim savePath As String = Request.QueryString("path")

outside of Sub Upload_Click, you get the following exception:

"Request is not available in this context."

However, removing strPath does make sense.


Thanks to both of you. I still got a problem even after doing that, but adding "Context." before "Request" cleared things up.


louis210:

Gunteman, I must respectfully disagree. If you put

Dim savePath As String = Request.QueryString("path")

outside of Sub Upload_Click, you get the following exception:

"Request is not available in this context."

Quite right!

Monday, March 26, 2012

Trouble displaying Japanese text with aspx

Friends,
I am having trouble displaying Japanese text within a textbox (or
anywhere else) in an aspx page with .net 2.0 framework. Initial
default text in Japanese displays perfectly but when I attempt to
change the text following a button-click event, it displays as junk.
I have tried setting the globalization tag in the web.config file but
that does not help eiter.
<globalization requestEncoding="UTF-8" responseEncoding="UTF-8"
fileEncoding="UTF-8"/>
I should mention that the problem does not happen in my development pc
where I am using the Visual Web Developer 2005 IDE. It happens only
when I deploy the files to the actual IIS webserver on Windows 2000.
Would greatly appreciate any help.
Here's what I have:
1. TestJP.aspx contains:
<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true"
CodeFile="TestJP.aspx.cs" Inherits="TestJP" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Test JP</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtJP" runat="server" Height="101px"
Width="374px">Default Japanese Text</asp:TextBox>
<br />
<asp:Button ID="cmdJP" runat="server" Text="Change Text"
OnClick="cmdJP_Click" />
</div>
</form>
</body>
</html>
2. TestJP.aspx.cs contains:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class TestJP : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void cmdJP_Click(object sender, EventArgs e)
{
txtJP.Text = "New Japanese text";
}
}On May 8, 9:16 am, pardesiya <zenst...@.gmail.com> wrote:
> Friends,
> I am having trouble displaying Japanese text within a textbox (or
> anywhere else) in an aspx page with .net 2.0 framework. Initial
> default text in Japanese displays perfectly but when I attempt to
> change the text following a button-click event, it displays as junk.
> I have tried setting the globalization tag in the web.config file but
> that does not help eiter.
> <globalization requestEncoding="UTF-8" responseEncoding="UTF-8"
> fileEncoding="UTF-8"/>
> I should mention that the problem does not happen in my development pc
> where I am using the Visual Web Developer 2005 IDE. It happens only
> when I deploy the files to the actual IIS webserver on Windows 2000.
> Would greatly appreciate any help.
> Here's what I have:
> 1. TestJP.aspx contains:
> <%@. Page Language="C#" AutoEventWireup="true"
> CodeFile="TestJP.aspx.cs" Inherits="TestJP" %>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www
.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml" >
> <head runat="server">
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
> <title>Test JP</title>
> </head>
> <body>
> <form id="form1" runat="server">
> <div>
> <asp:TextBox ID="txtJP" runat="server" Height="101px"
> Width="374px">Default Japanese Text</asp:TextBox>
> <br />
> <asp:Button ID="cmdJP" runat="server" Text="Change Text"
> OnClick="cmdJP_Click" />
> </div>
> </form>
> </body>
> </html>
> 2. TestJP.aspx.cs contains:
> using System;
> using System.Data;
> using System.Configuration;
> using System.Collections;
> using System.Web;
> using System.Web.Security;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.Web.UI.WebControls.WebParts;
> using System.Web.UI.HtmlControls;
> public partial class TestJP : System.Web.UI.Page
> {
> protected void Page_Load(object sender, EventArgs e)
> {
> }
> protected void cmdJP_Click(object sender, EventArgs e)
> {
> txtJP.Text = "New Japanese text";
> }
>
> }- Hide quoted text -
> - Show quoted text -
Go to File - Save .aspx As - point to Save and select Save with
Encoding... What encoding do you use to save the file?
On May 8, 9:30 am, Alexey Smirnov <alexey.smir...@.gmail.com> wrote:
> Go to File - Save .aspx As - point to Save and select Save with
> Encoding... What encoding do you use to save the file... Hide quoted text -
>
Wait... you have to check the encoding for your TestJP.aspx.cs file.
It seems that it saved in a different encoding...
Alexey thanks a lot for your prompt suggestion. That worked!
TestJP.aspx.cs and TestJP.aspx were saved with Shift_JIS. Changed
that to UTF-8 and it works fine!
I have a second question which is related. I query data into a dataset
and display the result in the same text box but it appears junk. Is
there any way I should set the charset of the DataSet? The database is
probably encoded with Unicode.
DataSet dsTables = new DataSet();
dsTables = <code to get data from database>
txtJP.Text = dsTables.Tables[0].Rows[0]["japanese_name"].ToString();
using System.Data.OleDb;
On May 8, 10:32 am, pardesiya <zenst...@.gmail.com> wrote:
> Alexey thanks a lot for your prompt suggestion. That worked!
> TestJP.aspx.cs and TestJP.aspx were saved with Shift_JIS. Changed
> that to UTF-8 and it works fine!
> I have a second question which is related. I query data into a dataset
> and display the result in the same text box but it appears junk. Is
> there any way I should set the charset of the DataSet? The database is
> probably encoded with Unicode.
> DataSet dsTables = new DataSet();
> dsTables = <code to get data from database>
> txtJP.Text = dsTables.Tables[0].Rows[0]["japanese_name"].ToString();
Where data came from? Did you do that from your asp.net application?
It seems that the data encoded in other format...
Try to change encoding of your result page, in IE right click,
Encoding - Shift_JIS (or any other)
Thanks Alexey. Yes, I'm getting the data from asp.net application.
But changing the encoding in IE doesnt seem to help. As you mention
maybe the data is encoded differently. Probably I should post this as
a separate thread.
using System.Data.OleDb;
OleDbConnection OledbConn = new OleDbConnection();
OleDbDataAdapter OledbDataAdap = new OleDbDataAdapter();
DataSet OleDbDS = new DataSet();
OledbConn.ConnectionString = <connection string to Sybase
database>;
OledbConn.Open();
OledbDataAdap.SelectCommand = new OleDbCommand("select
japanese_name from ... ", OledbConn);
OledbDataAdap.Fill(OleDbDS);
OledbConn.Close();
return OleDbDS;
On May 8, 11:06 am, pardesiya <zenst...@.gmail.com> wrote:
> Thanks Alexey. Yes, I'm getting the data from asp.net application.
> But changing the encoding in IE doesnt seem to help. As you mention
> maybe the data is encoded differently. Probably I should post this as
> a separate thread.
> using System.Data.OleDb;
> OleDbConnection OledbConn = new OleDbConnection();
> OleDbDataAdapter OledbDataAdap = new OleDbDataAdapter();
> DataSet OleDbDS = new DataSet();
> OledbConn.ConnectionString = <connection string to Sybase
> database>;
> OledbConn.Open();
> OledbDataAdap.SelectCommand = new OleDbCommand("select
> japanese_name from ... ", OledbConn);
> OledbDataAdap.Fill(OleDbDS);
> OledbConn.Close();
> return OleDbDS;
Sorry, I think I was not clear. I'm interesting in the code which
stored the data in the database. I guess, you have a kind of web form
with fields and submit button which fires the code-behind action. This
form has to be in UTF encoded
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
not sure about a code (want to see it first)
and your database should support that encoding.
Actually, if you browse the database using a shell, do you see the
correct characters? Are you able to insert any data in Japanese (using
a shell) and see that text on the website?
Ok I understand what you mean. Actually I am not sure about how the
data is stored in the database. The people who maintain the database
have some kind of tool or database application to insert the data. I
only try to retrieve some data using an oledb connection in my asp.net
form.
But I am able to browse the database using Microsoft Query and see the
Japanese data correctly. I can even download the correct data into
Excel. I dont have permission to insert data so cannot check that
part.
On May 8, 11:50 am, pardesiya <zenst...@.gmail.com> wrote:
> Ok I understand what you mean. Actually I am not sure about how the
> data is stored in the database. The people who maintain the database
> have some kind of tool or database application to insert the data. I
> only try to retrieve some data using an oledb connection in my asp.net
> form.
> But I am able to browse the database using Microsoft Query and see the
> Japanese data correctly. I can even download the correct data into
> Excel. I dont have permission to insert data so cannot check that
> part.
1. Check the existing output. Maybe it will give you idea about
encoding.
2. Try to encode
System.Text.Encoding en1 = System.Text.Encoding.Unicode;
System.Text.Encoding en2 = System.Text.Encoding.UTF8;
txtJP.Text = en2.GetString(en1.GetBytes(dsTables.Tables[0].Rows[0]
["japanese_name"].ToString()));
or
System.Text.Encoding en1 =
System.Text.Encoding.Encoding.GetEncoding("Shift_JIS"); // or any
other standard JP-encoding
System.Text.Encoding en2 = System.Text.Encoding.UTF8;
txtJP.Text = en2.GetString(en1.GetBytes(dsTables.Tables[0].Rows[0]
["japanese_name"].ToString()));
3. Check code page of your database
4. Contact db-developers :-)

Trouble editing HTML Elements version 0.6

Hi
I just encountered something very weird. I opened an existing aspx fileto make some changes. When I click on an HTML element, such as a textbox, I get the open squares that say it is selected. The Propertieswindow opens up on the right but when I try to make any changes in thatwindow, the open squares become gray squares around the HTML element.Certain properties (e.g. Type) can be changed. Others such as ID cannot be changed. However I can go into the HTML code and make thechanges there. I am using version 0.6 of ASP.NET.
Any ideas on what happened? If it helps, I am working on the Guest Book example in Chapter 10 of Mike Pope's starter book.
Danny Low

version 0.6 of ASP.NET


As far as I know there has never been a ver. 0.6 of Asp.Net. You are either using ver. 1.0, 1.1 or 2.0. Are you perhaps talking about some kind of development tool here, like Visual Studio?

As far as I know there has never been a ver. 0.6 of Asp.Net.
When you ask for version number with Help->About the window thatpops up says version 0.6 build(812). This is what I downloaded from theasp.net download section.
Danny Low

What window is this? Asp.Net is part of the .NET Framework and does not come with an Interface. There are three versions of .NET; 1.0, 1.1 and 2.0. Is it Web Matrix your are referring to??
Yes, it is Web Matrix that I am referring to. All I did was save myaspx file at a convenient stop point and shut down my system for thenight. The next day when I resumed working on the sample program, I noticed the weird behavior of not being able to edit some propertiesof the page elements when in the Design mode. And it is not just theexisting elements but any new elements that I add to the page.
Danny

Trouble getting an "Update Quantities" Button Working

Hello,

I am trying to create a click handler on an update quantities button which updates the quantities with the textbox. I am using a datalist and have addressed the "ProductID" as the DataKeyField. Can someone please help me code this?

This is the code
--------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim productID As String = Request.Params("AddToCart" )
If Not productID Is Nothing Then
Dim cart As New ShoppingCart()
cart.AddProduct(productID)
End If
BindShoppingCart()
checkoutCodeLabel.Text = "Checkout Code: "
End If
End Sub

Private Sub BindShoppingCart()
Dim cart As New ShoppingCart()
list.DataSource = cart.GetProducts
list.DataKeyField = "ProductID"
list.DataBind()

If cart.GetTotalAmount = 0 Then
placeOrderButton.Enabled = False
Else
placeOrderButton.Enabled = True
End If

TotalAmount.Text = "Total amount:"

totalAmountLabel.Text = String.Format("{0:c}", cart.GetTotalAmount())
End Sub

Private Sub btnUpdateQuantity_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdateQuantity.Click
(WHAT DO I PUT HERE??????????)
End Sub

Thanks in advance!Where you can get the total after you click the update button and page post back? looks like all the code in page_load will not run for they are in "If Not Page.IsPostBack ".

Trouble referencing controls within list controls

I have a DataGrid containing a TextBox control and a CustomValidator
in each row. The CustomValidator fires a function that compares all
TextBoxes for equality. The algorithm for comparison is
straightforward:

*PSEUDOCODE*

for i=1 thru ( Container.Length-1 )
for j=i+1 thru ( Container.Length-1 )
if ( TextBox[i]==TextBox[j] )
TRUE

It would be even faster if instead of starting with 1 everytime, I set
i to get the index of the current Container row.

Problem is I'm having trouble referencing the TextBoxes within the
DataGrid. I've studied msdn
(http://msdn.microsoft.com/library/d...bformspages.asp)
but the concept still baffles me.

Specifically, what I try to do is store the TextBoxes for comparison
in an array:

Dim ControlName As String' temporary

ControlName = OurDataGrid.Controls(i).UniqueID
aObjFirst(0) = CType( Me.FindControl(ControlName & "First"), TextBox
)
ControlName = OurDataGrid.Controls(j).UniqueID
aObjFirst(1) = CType( Me.FindControl(ControlName & "First"), TextBox
)

' If first names match...
If ( aObjFirst(0).Text=aObjFirst(1).Text ) Then
...

(Yes, I'm comparing first names.) However, this always warns me that
j is out of range. And getting back to the msdn, it seems to be
discouraging the technique of name concatenation I used to get at the
controls I want.

Can anyone follow where I'm going with this and provide some
insightful direction?--or a totally different approach would be welcome. Anything that
could help, really.

I just thought of a less repetitive algorithm.

Provided I can dynamically obtain the index of the current row:

*PSEUDOCODE*

for i=currentIndex thru ( DataGrid.Controls.Count-1 )
if ( TextBox[currentIndex].Text==TextBox[i].Text )
TRUE

Problem is I still need help referencing the individual TextBox
controls that my DataGrid generates. I have a feeling the solution
lies with the UniqueID property, but I still can't solve it on my own.

> I have a DataGrid containing a TextBox control and a CustomValidator
> in each row. The CustomValidator fires a function that compares all
> TextBoxes for equality. The algorithm for comparison is
> straightforward:
> *PSEUDOCODE*
> for i=1 thru ( Container.Length-1 )
> for j=i+1 thru ( Container.Length-1 )
> if ( TextBox[i]==TextBox[j] )
> TRUE

...

> Specifically, what I try to do is store the TextBoxes for comparison
> in an array:
>Dim aObjFirst(2) As TextBox
> Dim ControlName As String' temporary
> ControlName = OurDataGrid.Controls(i).UniqueID
> aObjFirst(0) = CType(Me.FindControl(ControlName & "First"), TextBox)
> ControlName = OurDataGrid.Controls(j).UniqueID
> aObjFirst(1) = CType(Me.FindControl(ControlName & "First"), TextBox)
> ' If first names match...
> If ( aObjFirst(0).Text=aObjFirst(1).Text ) Then
> ...
> (Yes, I'm comparing first names.) However, this always warns me that
> j is out of range. And getting back to the msdn, it seems to be
> discouraging the technique of name concatenation I used to get at the
> controls I want.
> Can anyone follow where I'm going with this and provide some
> insightful direction?
Same question, different day, (hopefully) worded more clearly.

I have a DataGrid containing a TextBox control and a CustomValidator in
each row.

The CustomValidator fires a subroutine that compares all TextBoxes the
DataGrid generates for equality.

The algorithm is pretty straightforward:

*PSEUDOCODE*

senderIndex = the row in the DataGrid of the sender

FOR ( i=senderIndex+1 ) THRU ( last Row of the DataGrid )
IF ( TextBox[i].Text==TextBox[senderIndex].Text )
TRUE

However, I'm stuck in my attempts to formally code this algorithm:

*CODE*

Sub HasDupe(sender as Object, e as EventArgs)
Dim objFirst As Textbox
value.IsValid = False

For ( i = SENDER_INDEX+1 ) To ( DataGrid.Controls.Count-1 )
' get the control in row i with the same ID as the
sender
objFirst =
OurDataGrid.Items(i).FindControl(sender.ControlToV alidate)

If ( objFirst.Text=sender.Text )
value.IsValid = True
End If
Next
End Sub

I /think/ my only problem is the "SENDER_INDEX"--I can't figure out how
to reveal the row number of the sender. This is my question.

(But if any other part of my code looks screwy, I'd appreciate input on
that as well.)
(Here's an answer I received from another post, that _works._

--E.)

Use can use the parent control to find the index. All Controls have
parents and children, you can move up and down the node list to find
the one you are looking for. You can shorten the code, I just wanted to
make sure you saw the levels. Also a while back I was trying to deal
with CustomValidators in datagrids, I seem to recall some issues with
that just FYI. Hope this helps AuSable Troutbum

'Find the The control that is firing event
Dim valCustomControl As New CustomValidator
valCustomControl = sender

'Find the Parent Cell of Validation Control
Dim cell As TableCell = valCustomControl.Parent

'Find the Datagrid Item
Dim dgItem As DataGridItem = cell.Parent

'Set the Row
Dim myRow As DataRow =
DataSet.Tables("YourTableName").Rows(dgItem.ItemIndex)

Trouble referencing controls within list controls

I have a DataGrid containing a TextBox control and a CustomValidator
in each row. The CustomValidator fires a function that compares all
TextBoxes for equality. The algorithm for comparison is
straightforward:
*PSEUDOCODE*
for i=1 thru ( Container.Length-1 )
for j=i+1 thru ( Container.Length-1 )
if ( TextBox[i]==TextBox[j] )
TRUE
It would be even faster if instead of starting with 1 everytime, I set
i to get the index of the current Container row.
Problem is I'm having trouble referencing the TextBoxes within the
DataGrid. I've studied msdn
(http://msdn.microsoft.com/library/d...bformspages.asp)
but the concept still baffles me.
Specifically, what I try to do is store the TextBoxes for comparison
in an array:
Dim ControlName As String ' temporary
ControlName = OurDataGrid.Controls(i).UniqueID
aObjFirst(0) = CType( Me.FindControl(ControlName & "First"), TextBox
)
ControlName = OurDataGrid.Controls(j).UniqueID
aObjFirst(1) = CType( Me.FindControl(ControlName & "First"), TextBox
)
' If first names match...
If ( aObjFirst(0).Text=aObjFirst(1).Text ) Then
..
(Yes, I'm comparing first names.) However, this always warns me that
j is out of range. And getting back to the msdn, it seems to be
discouraging the technique of name concatenation I used to get at the
controls I want.
Can anyone follow where I'm going with this and provide some
insightful direction?--or a totally different approach would be welcome. Anything that
could help, really.
I just thought of a less repetitive algorithm.
Provided I can dynamically obtain the index of the current row:
*PSEUDOCODE*
for i=currentIndex thru ( DataGrid.Controls.Count-1 )
if ( TextBox[currentIndex].Text==TextBox[i].Text )
TRUE
Problem is I still need help referencing the individual TextBox
controls that my DataGrid generates. I have a feeling the solution
lies with the UniqueID property, but I still can't solve it on my own.

> I have a DataGrid containing a TextBox control and a CustomValidator
> in each row. The CustomValidator fires a function that compares all
> TextBoxes for equality. The algorithm for comparison is
> straightforward:
> *PSEUDOCODE*
> for i=1 thru ( Container.Length-1 )
> for j=i+1 thru ( Container.Length-1 )
> if ( TextBox[i]==TextBox[j] )
> TRUE
>
...

> Specifically, what I try to do is store the TextBoxes for comparison
> in an array:
> Dim aObjFirst(2) As TextBox
> Dim ControlName As String ' temporary
> ControlName = OurDataGrid.Controls(i).UniqueID
> aObjFirst(0) = CType(Me.FindControl(ControlName & "First"), TextBox)
> ControlName = OurDataGrid.Controls(j).UniqueID
> aObjFirst(1) = CType(Me.FindControl(ControlName & "First"), TextBox)
> ' If first names match...
> If ( aObjFirst(0).Text=aObjFirst(1).Text ) Then
> ...
> (Yes, I'm comparing first names.) However, this always warns me that
> j is out of range. And getting back to the msdn, it seems to be
> discouraging the technique of name concatenation I used to get at the
> controls I want.
> Can anyone follow where I'm going with this and provide some
> insightful direction?
Same question, different day, (hopefully) worded more clearly.
I have a DataGrid containing a TextBox control and a CustomValidator in
each row.
The CustomValidator fires a subroutine that compares all TextBoxes the
DataGrid generates for equality.
The algorithm is pretty straightforward:
*PSEUDOCODE*
senderIndex = the row in the DataGrid of the sender
FOR ( i=senderIndex+1 ) THRU ( last Row of the DataGrid )
IF ( TextBox[i].Text==TextBox[senderIndex].Text )
TRUE
However, I'm stuck in my attempts to formally code this algorithm:
*CODE*
Sub HasDupe(sender as Object, e as EventArgs)
Dim objFirst As Textbox
value.IsValid = False
For ( i = SENDER_INDEX+1 ) To ( DataGrid.Controls.Count-1 )
' get the control in row i with the same ID as the
sender
objFirst =
OurDataGrid.Items(i).FindControl(sender.ControlToValidate)
If ( objFirst.Text=sender.Text )
value.IsValid = True
End If
Next
End Sub
I /think/ my only problem is the "SENDER_INDEX"--I can't figure out how
to reveal the row number of the sender. This is my question.
(But if any other part of my code looks screwy, I'd appreciate input on
that as well.)
(Here's an answer I received from another post, that _works._
--E.)
Use can use the parent control to find the index. All Controls have
parents and children, you can move up and down the node list to find
the one you are looking for. You can shorten the code, I just wanted to
make sure you saw the levels. Also a while back I was trying to deal
with CustomValidators in datagrids, I seem to recall some issues with
that just FYI. Hope this helps AuSable Troutbum
'Find the The control that is firing event
Dim valCustomControl As New CustomValidator
valCustomControl = sender
'Find the Parent Cell of Validation Control
Dim cell As TableCell = valCustomControl.Parent
'Find the Datagrid Item
Dim dgItem As DataGridItem = cell.Parent
'Set the Row
Dim myRow As DataRow =
DataSet.Tables("YourTableName").Rows(dgItem.ItemIndex)

Saturday, March 24, 2012

Trouble saving html in a string variable

I'm trying to allow a user to enter html text into a textBox (FreeTextBox) but am getting an error upon submitting:

A potentially dangerous Request.Form value was detected from the client (noteTextBox="<H2><FONT size=6>asd...").
Description:Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. You can disable request validation by setting validateRequest=false in the Page directive or in the configuration section. However, it is strongly recommended that your application explicitly check all inputs in this case.

Exception Details:System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (noteTextBox="<H2><FONT size=6>asd...").

Anybody know how to deal with this while still allowing me to save the html?

<%@. Page...... ValidateRequest="false".....%>


I think the reason for this error was that someone could enter a <script> tag in your textbox with javascript code, and then if you grab that value from the form and display directly it on another page, the code in the <script> tag would be executed on your user's computer... this could be potentially bad. i usually turn the error off though, like the previous poster. If you HtmlEncode() anything that you display that ultimately came from the user, it should be ok to turn it off.


How do I HtmlEncode() this text?


dim myText as String = Server.HtmlEncode(yourTextbox.Text)

Trouble updating

I have a Access database with 2 text fields. I'm reading one field into a text box, changing the value in the textbox and attempting to update the database with the new value. The page loads fine with the correct value in the textbox, but I'm getting a error on the Update statement. Below is the code. Any suggestions?

Sub LoadInventory()
Connect()
Dim strQuery As String = "SELECT Type, Number FROM Inventory WHERE type = 'squares'"

Dim dbComm As New OLEDBCommand(strQuery, objConnection)
Dim reader As OLEDBDataReader = dbComm.ExecuteReader()

reader.Read()
txtAmount.Text = reader.GetString(1)

reader.Close()
Disconnect()
End Sub

Sub btnChange_Click(ByVal Sender As Object, ByVal E As EventArgs)
UpdateInventory()
LoadInventory()
End Sub

Private Sub UpdateInventory()
Dim strSQL As String = "UPDATE Inventory SET Number = " & txtAmount.Text & " WHERE Type = 'squares'"
Connect()
Dim dbComm As New OLEDBCommand(strSQL, objConnection)
dbComm.ExecuteNonQuery()
Disconnect()
End Subinstead of

Dim strSQL As String = "UPDATE Inventory SET Number = " & txtAmount.Text & " WHERE Type = 'squares'"

try this
Dim strSQL As String = "UPDATE Inventory SET Number = " & Convert.ToInt32(txtAmount.Text) & " WHERE Type = 'squares'"

Jeff
Jeff,

Thanks for your reply. That however didn't work. Could it be the way I have my access database setup?

Jeremy
Jeff,

Does it work when you try putting in a static value for txtAmount.Text such as this:

"UPDATE Inventory SET Number =1 WHERE Type='squares'"

If it does work like that, then try doing this:


Try
Dim dbComm As New OLEDBCommand(strSQL, objConnection)
dbComm.ExecuteNonQuery()
Catch dbException As Exception
Response.Write(dbException.ToString())
End Try

Tell us what the exception is. Besides, it is always good practice anyway to put database queries inside a try statement - there are just way too many things that could go wrong to not catch those errors.

Aaron

Tuesday, March 13, 2012

Troubles displaying a changing read-only value

I am writing a form with one value being a total of a couple other values from my page. I put this in a read-only textbox so it can't be changed, and when I change the other boxes values, the JavaScript automatically changes this value. However, when I generate the e-mail I use textboxTotalSpace.text to make it appear in my email, but this will only display the original value, and not the new one.

Does anyone know how I fix this?

Thanks.

TextBox server control will not pick up the changed values (during LoadPostData()) if the textbox is set to read only. Check this link for a fix:

http://aspadvice.com/blogs/joteke/archive/2006/04/12/16409.aspx

Hope this helps,

Vivek


Thanks Vivek, but I am unsure where I am supposed to add theTextBox1.Attributes.Add("readonly","readonly")


That should go in the Page_Load event.

protected void Page_Load(object sender, EventArgs e)
{
// add the javascript attributes
TextBox1.Attributes.Add("readonly", "readonly");
}

Thanks


Because you are changing data at client side using java script....


You can put this in the Page Load method.


suresh modiya:

Because you are changing data at client side using java script....

Changed text box value client side WILL show up in the server code behind because textbox implements IPostBackDataHandler interface and it loads its value from the forms POST data in the LoadPostBackData() method.

Its only when it is set to readonly that this data load will not work on postback, hence the alternative.

Vivek

Troubles with INSERT INTO Statement...

hey all, im currently trying to do an insert statement, using textbox's and a variable. the only thing is its inserting txtTextBox.Text into the db instead of the value of that textbox...and i get this error when trying to insert my variable...

Exception Details: System.Data.SqlClient.SqlException: The name 'RndmNum' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.

Source Error:

Line 42: dbQuery = "INSERT INTO table (name, fault_type, fault_location, fault_description, fault_number) VALUES ('txtName.Text', 'txtType.Text', 'txtLocation.Text', 'txtDesc.Text', RndmNum)"
Line 43: dbCommand = New SqlCommand(dbQuery,dbConnection)
Line 44: dbCommand.ExecuteNonQuery()
Line 45: dbConnection.Close
Line 46:

this is my insert statement:

dbQuery = "INSERT INTO table (name, fault_type, fault_location, fault_description, fault_number) VALUES ('txtName.Text', 'txtType.Text', 'txtLocation.Text', 'txtDesc.Text', RndmNum)"

thanks everyone,
JustinYou are sending txtName.Text as a string. Your dbQuery needs to look like this:

dbQuery = "INSERT INTO table (name, fault_type, fault_location, fault_description, fault_number) VALUES ('" & txtName.Text & "', '" & txtType.Text & "', '" & txtLocation.Text & "', '" & txtDesc.Text & "', " & RndmNum & ")"