Monday, March 12, 2012

Why this code line doenst work?

Hello,

I have the following code in the Global.asax:

Sub Session_Start(Sender As Object, E As EventArgs)
Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
End Sub

The Error I get: "Name 'Thread' is not declared."

However when I have this in my aspx code it works:

Sub Page_Load(Sender As Object, E As EventArgs)
Thread.CurrentThread.CurrentCulture = New CultureInfo("pt-PT")
End Sub

Why?
Can't I set the culture in the Global.asax?

Thank You,
MiguelHi, Shapper.

Please review these links :

http://www.codingforums.com/archive/index.php/t-10203

http://www.tek-tips.com/faqs.cfm?fid=2707

http://www.eggheadcafe.com/ng/micro...ost20240872.asp

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Espaol
Ven, y hablemos de ASP.NET...
======================

"Shapper" <mdmoura*NOSPAM*@.gmail.*DELETE2SEND*com> wrote in message
news:u9OpMQLTFHA.3952@.TK2MSFTNGP15.phx.gbl...
> Hello,
> I have the following code in the Global.asax:
> Sub Session_Start(Sender As Object, E As EventArgs)
> Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
> End Sub
> The Error I get: "Name 'Thread' is not declared."
> However when I have this in my aspx code it works:
> Sub Page_Load(Sender As Object, E As EventArgs)
> Thread.CurrentThread.CurrentCulture = New CultureInfo("pt-PT")
> End Sub
> Why?
> Can't I set the culture in the Global.asax?
> Thank You,
> Miguel
"Shapper" <mdmoura*NOSPAM*@.gmail.*DELETE2SEND*com> wrote in message
news:u9OpMQLTFHA.3952@.TK2MSFTNGP15.phx.gbl...
> Hello,
> I have the following code in the Global.asax:
> Sub Session_Start(Sender As Object, E As EventArgs)
> Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
> End Sub
> The Error I get: "Name 'Thread' is not declared."
> However when I have this in my aspx code it works:
> Sub Page_Load(Sender As Object, E As EventArgs)
> Thread.CurrentThread.CurrentCulture = New CultureInfo("pt-PT")
> End Sub
> Why?
> Can't I set the culture in the Global.asax?
> Thank You,
> Miguel
Did you Import the System.Threading class? Or use the full name,
System.Threading.Thread.

--

Joe (MVP)

https://mvp.support.microsoft.com/p...E8-8741D22D17A5
My first guess would be that you are missing the namespace of this "Thread"
class or use the complete namespace reference while using "Thread"

Thread class is in System.Threading

"Shapper" wrote:

> Hello,
> I have the following code in the Global.asax:
> Sub Session_Start(Sender As Object, E As EventArgs)
> Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
> End Sub
> The Error I get: "Name 'Thread' is not declared."
> However when I have this in my aspx code it works:
> Sub Page_Load(Sender As Object, E As EventArgs)
> Thread.CurrentThread.CurrentCulture = New CultureInfo("pt-PT")
> End Sub
> Why?
> Can't I set the culture in the Global.asax?
> Thank You,
> Miguel
>
Ah,

I just found out. I forgot the dam line in Global.asax:
<%@. import Namespace="System.Threading" %
I had it on my ASPX page. I didn't even notice.

Sorry for the time.

Thanks,
Miguel

"Diffident" <Diffident@.discussions.microsoft.com> wrote in message
news:Diffident@.discussions.microsoft.com:

> My first guess would be that you are missing the namespace of this "Thread"
> class or use the complete namespace reference while using "Thread"
> Thread class is in System.Threading
> "Shapper" wrote:
>
> > Hello,
> > I have the following code in the Global.asax:
> > Sub Session_Start(Sender As Object, E As EventArgs)
> > Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
> > End Sub
> > The Error I get: "Name 'Thread' is not declared."
> > However when I have this in my aspx code it works:
> > Sub Page_Load(Sender As Object, E As EventArgs)
> > Thread.CurrentThread.CurrentCulture = New CultureInfo("pt-PT")
> > End Sub
> > Why?
> > Can't I set the culture in the Global.asax?
> > Thank You,
> > Miguel

Why this code line doenst work?

Hello,
I have the following code in the Global.asax:
Sub Session_Start(Sender As Object, E As EventArgs)
Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
End Sub
The Error I get: "Name 'Thread' is not declared."
However when I have this in my aspx code it works:
Sub Page_Load(Sender As Object, E As EventArgs)
Thread.CurrentThread.CurrentCulture = New CultureInfo("pt-PT")
End Sub
Why?
Can't I set the culture in the Global.asax?
Thank You,
Miguel

Have you add

Imports System.Threading statement in your code


Of Course. I forgot the dam line.
Thanks,
Miguel

Why this error when table has this column name

I know my table has this column but I keep getting the following error doesn't make sense: (my code for the for the button is below the error)

Column 'CompanyID' does not belong to table Categories.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:System.ArgumentException: Column 'CompanyID' does not belong to table Categories.
Source Error:
Line 883: Dim row As DataRowLine 884: row = DsPerformanceTabStrip1.Categories.NewCategoriesRowLine 885: row("CompanyID") = Session("companyID")Line 886: row("FacilityID") = Session("facilityID")Line 887: row("PeriodID") = Session("Period")

PrivateSub btnCatAdd_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles btnCatAdd.Click

DsPerformanceTabStrip1.Clear()

SqlDataAdapter1.SelectCommand.Parameters("@dotnet.itags.org.Period").Value = ddlEvalPeriod.SelectedValue

SqlDataAdapter1.Fill(DsPerformanceTabStrip1)

Dim rowAs DataRow

row = DsPerformanceTabStrip1.Categories.NewCategoriesRow

row("CompanyID") = Session("companyID")

row("FacilityID") = Session("facilityID")

row("PeriodID") = Session("Period")

row("SeqNbr") = txtSeq.Text

row("Description") = txtDescription.Text

DsPerformanceTabStrip1.Categories.AddCategoriesRow(row)

SqlDataAdapter1.Update(DsPerformanceTabStrip1)

DsPerformanceTabStrip1.Clear()

SqlDataAdapter1.Fill(DsPerformanceTabStrip1)

dgCategoryCurrent.DataBind()

EndSub

I found my answer -- I wasn't calling these columns in my stored procedure--I had the wrong stored procedure in my dataadapter

Why this error message?

VB.NET / ASP.NET

I have a simple test. One simple Formview connected to a datasource. I
have Button1 outside of the Formview. The Formview starts in ReadOnlyMode.
All I want to do is on the button click, change the formview to Insert mode
and then put the current date in the date textbox. The date textbox ID is
DateTextBox and I've double check that to make sure it's right. Here's my
simple code.

Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As
System.EventArgs)

FormView1.ChangeMode(FormViewMode.Insert)

Dim datetb As TextBox = FormView1.FindControl("DateTextBox")

datetb.Text = Now.Date.ToShortDateString()

End Sub

This is the error message I'm getting.

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 6: FormView1.ChangeMode(FormViewMode.Insert)
Line 7: Dim datetb As TextBox =
FormView1.FindControl("DateTextBox")
Line 8: datetb.Text = Now.Date.ToShortDateString()
Line 9: End Sub
Line 10: </script>

Thanks in advance!
PhilOn Aug 12, 4:49 pm, "pvong" <phillip*at*yahoo*dot*comwrote:

Quote:

Originally Posted by

VB.NET / ASP.NET
>
I have a simple test. One simple Formview connected to a datasource. I
have Button1 outside of the Formview. The Formview starts in ReadOnlyMode.
All I want to do is on the button click, change the formview to Insert mode
and then put the current date in the date textbox. The date textbox ID is
DateTextBox and I've double check that to make sure it's right. Here's my
simple code.
>
Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As
System.EventArgs)
>
FormView1.ChangeMode(FormViewMode.Insert)
>
Dim datetb As TextBox = FormView1.FindControl("DateTextBox")
>
datetb.Text = Now.Date.ToShortDateString()
>
End Sub
>
This is the error message I'm getting.
>
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
>
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
>
Source Error:
>
Line 6: FormView1.ChangeMode(FormViewMode.Insert)
Line 7: Dim datetb As TextBox =
FormView1.FindControl("DateTextBox")
Line 8: datetb.Text = Now.Date.ToShortDateString()
Line 9: End Sub
Line 10: </script>
>
Thanks in advance!
Phil


Hi Phil

Are there any entry in the datasource?
Yes, there are entries in the Datasource. If I manually put the date in, it
works perfectly. I just want when the user clicks this button for the
formview to auto switch to Insert mode and auto put in today's date for them
in the datetb.
Thanks!
Phil

"Alexey Smirnov" <alexey.smirnov@.gmail.comwrote in message
news:1186930820.570788.158710@.22g2000hsm.googlegro ups.com...

Quote:

Originally Posted by

On Aug 12, 4:49 pm, "pvong" <phillip*at*yahoo*dot*comwrote:

Quote:

Originally Posted by

>VB.NET / ASP.NET
>>
>I have a simple test. One simple Formview connected to a datasource. I
>have Button1 outside of the Formview. The Formview starts in
>ReadOnlyMode.
>All I want to do is on the button click, change the formview to Insert
>mode
>and then put the current date in the date textbox. The date textbox ID
>is
>DateTextBox and I've double check that to make sure it's right. Here's
>my
>simple code.
>>
>Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As
>System.EventArgs)
>>
>FormView1.ChangeMode(FormViewMode.Insert)
>>
>Dim datetb As TextBox = FormView1.FindControl("DateTextBox")
>>
>datetb.Text = Now.Date.ToShortDateString()
>>
>End Sub
>>
>This is the error message I'm getting.
>>
>Object reference not set to an instance of an object.
>Description: An unhandled exception occurred during the execution of the
>current web request. Please review the stack trace for more information
>about the error and where it originated in the code.
>>
>Exception Details: System.NullReferenceException: Object reference not
>set
>to an instance of an object.
>>
>Source Error:
>>
>Line 6: FormView1.ChangeMode(FormViewMode.Insert)
>Line 7: Dim datetb As TextBox =
>FormView1.FindControl("DateTextBox")
>Line 8: datetb.Text = Now.Date.ToShortDateString()
>Line 9: End Sub
>Line 10: </script>
>>
>Thanks in advance!
>Phil


>
Hi Phil
>
Are there any entry in the datasource?
>

Why this error message?

VB.NET / ASP.NET
I have a simple test. One simple Formview connected to a datasource. I
have Button1 outside of the Formview. The Formview starts in ReadOnlyMode.
All I want to do is on the button click, change the formview to Insert mode
and then put the current date in the date textbox. The date textbox ID is
DateTextBox and I've double check that to make sure it's right. Here's my
simple code.
Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As
System.EventArgs)
FormView1.ChangeMode(FormViewMode.Insert)
Dim datetb As TextBox = FormView1.FindControl("DateTextBox")
datetb.Text = Now.Date.ToShortDateString()
End Sub
This is the error message I'm getting.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
Source Error:
Line 6: FormView1.ChangeMode(FormViewMode.Insert)
Line 7: Dim datetb As TextBox =
FormView1.FindControl("DateTextBox")
Line 8: datetb.Text = Now.Date.ToShortDateString()
Line 9: End Sub
Line 10: </script>
Thanks in advance!
PhilOn Aug 12, 4:49 pm, "pvong" <phillip*at*yahoo*dot*com> wrote:
> VB.NET / ASP.NET
> I have a simple test. One simple Formview connected to a datasource. I
> have Button1 outside of the Formview. The Formview starts in ReadOnlyMode
.
> All I want to do is on the button click, change the formview to Insert mod
e
> and then put the current date in the date textbox. The date textbox ID is
> DateTextBox and I've double check that to make sure it's right. Here's my
> simple code.
> Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As
> System.EventArgs)
> FormView1.ChangeMode(FormViewMode.Insert)
> Dim datetb As TextBox = FormView1.FindControl("DateTextBox")
> datetb.Text = Now.Date.ToShortDateString()
> End Sub
> This is the error message I'm getting.
> Object reference not set to an instance of an object.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about the error and where it originated in the code.
> Exception Details: System.NullReferenceException: Object reference not set
> to an instance of an object.
> Source Error:
> Line 6: FormView1.ChangeMode(FormViewMode.Insert)
> Line 7: Dim datetb As TextBox =
> FormView1.FindControl("DateTextBox")
> Line 8: datetb.Text = Now.Date.ToShortDateString()
> Line 9: End Sub
> Line 10: </script>
> Thanks in advance!
> Phil
Hi Phil
Are there any entry in the datasource?
Yes, there are entries in the Datasource. If I manually put the date in, it
works perfectly. I just want when the user clicks this button for the
formview to auto switch to Insert mode and auto put in today's date for them
in the datetb.
Thanks!
Phil
"Alexey Smirnov" <alexey.smirnov@.gmail.com> wrote in message
news:1186930820.570788.158710@.22g2000hsm.googlegroups.com...
> On Aug 12, 4:49 pm, "pvong" <phillip*at*yahoo*dot*com> wrote:
> Hi Phil
> Are there any entry in the datasource?
>

why this doesnt work

i new to asp.net, i have use the following code to bind the database to datagrid control.

<%@dotnet.itags.org. Page Language="VB" %>
<%@dotnet.itags.org. import Namespace="System.Data" %>
<%@dotnet.itags.org. import Namespace="System.Data.SqlClient" %>
<script runat="server"
' Insert page code here
'
Sub Page_Load(Sender As Object, E As EventArgs)
Dim DS As DataSet
Dim MyConnection As SqlConnection = New SqlConnection("server='(local)'; trusted_connection=true; database='model'")
Dim MyCommand As SqlCommand = New SqlCommand("SELECT * FROM jobs", myConnection)

DS = new DataSet()
MyCommand.Fill(ds, "jobs")

DataGrid1.DataSource=ds.Tables("jobs").DefaultView
DataGrid1.DataBind()
End Sub
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid>
</p>
</form>
</body>
</html
AND i always get this error page which doesn't help a lots
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: The compiler failed with error code 1.

Show Detailed Compiler Output:(nothing apear in here)

Show Complete Compilation Source:(same as here)Make sure that your web.config file is well formed. If you are using Visual Studio run the solution without debugging and you should see a detailed error message.

hope this helps,
sivilian

why this doesnt work?

<%@dotnet.itags.org. Page Language="C#" %
<span id="span1" runat="server">Test_String</span>
<br><br
<%
Response.Write (span1.ID); // works: span1
Response.Write ("<br>");
Response.Write (span1.InnerHtml); // works: Test_String
Response.Write ("<br>");

Response.Write (FindControl("span1").ID); // works: span1
Response.Write ("<br>");
Response.Write (FindControl("span1").InnerHtml); // doesn't work, why??
Response.Write ("<br>");
%Hi,

FindControl returns back something of type control so you have to cast it first to the correct type.

Grz, Kris.
thx XIII
but how? any hint?
Change:

 Response.Write (FindControl("span1").InnerHtml);
to:
 Response.Write (((HtmlGenericControl)FindControl("span1")).InnerHtml);
To make this a bit less cryptic, here's how it works.

First, we use FindControl to actually grab the control:

FindControl("span")
However, this will give us a Control. As your error states, Control does not have an InnerHtml property. So, we first cast from a Control to a HtmlGenericControl (which is what the <span> is):
(HtmlGenericControl)FindControl("span")
Now, we put brackets around this combination, to give us our resulting HtmlGenericControl object:
((HtmlGenericControl)FindControl("span"))
Now that we have an HtmlGenericControl object, we can specify its InnerHtml property:
((HtmlGenericControl)FindControl("span1")).InnerHtml

I hope this helps.
hi, SomeNewKid,

thanks for yr help.
I tried yr way, but still not work :(
can you run this program ok in your machine?
> can you run this program ok in your machine?

Yes. With that single line change, your sample runs fine. Remember that C# is case-sensitive ... so you must type it exactly as shown.

When you say it still doesn't work, what exactly do you mean?

Do you get an error? If so, what does the error say?

Do you get an output that you did not expect? If so, what output were you expecting?
thanks to SomeNewKid, I got it! it runs ok now.

here is another probem, I added two 'Reponse' lines, first & second run ok, but the third line got a error. Is this 'HtmlGenericControl' not for a 'TD' tag?


<%@. Page Language="C#" %
<span id="id_span" runat="server">span_string</span>
<div id="id_div" runat="server">div_string</div
<form id="form1" runat="server">
<table id="table1" border="1" runat="server">
<tr id="id_tr" runat="server">
<td id="id_td" runat="server">td_string</td>
</tr>
</table>
</form
<%
Response.Write (((HtmlGenericControl)FindControl("id_span")).InnerHtml); // ok
Response.Write (((HtmlGenericControl)FindControl("id_div")).InnerHtml); //ok
Response.Write (((HtmlGenericControl)FindControl("id_td")).InnerHtml); // got error!
%>

> Is this 'HtmlGenericControl' not for a 'TD' tag?

Correct.

Here's a loose description of why:

The HtmlGenericControl is used for any control that is not "special" to ASP.NET.

A <span> tag is nothing special. It is just a tag sitting by itself, with no required parent or child tags. So, it's just a HtmlGenericControl.

A <td> tag, on the other hand, is not a tag sitting by itself. It must have a parent <tr> tag, and a grandparent <table> tag. This required structure makes tables "special" to ASP.NET. So, a <table> is an HtmlTable control, a <tr> is an HtmlTableRow control, and a <td> is a HtmlTableCell control.

Hence, you can get your code working by changing:

 Response.Write (((HtmlGenericControl)FindControl("id_td")).InnerHtml);
to:
 Response.Write (((HtmlTableCell)FindControl("id_td")).InnerHtml);
So, how on earth can you know which tags are generic, and which are special?

As always, the answer is in the documentation:
System.Web.UI.HtmlControls Namespace
oh, SomeNewKid! You are a good teacher! I love you so mucn~~~~
I think now I understood a lot about it, thank you very much!

p.s.
and I found 'HtmlContainerControl' can get work too :)
You're welcome.