VB vs C# question (trying to switch languages)

G

Guest

I'm trying to make the jump from VB to C#. Aside from the syntax issues i'm
running into some execution differences i think
1. I created a C# page in an existing VB.net website
2. I added a gridview with a footer row
3. i attempted to change the value of a label in the footer row on row
databound using:
protected void gv_catalog_RowDataBound(object sender,
System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if ((e.Row.RowType == DataControlRowType.Footer))
{
Label lbl =
(Label)this.gv_catalog.FooterRow.FindControl("lbl_OrderTotal");
lbl.Text = "total go here";
lbl.Font.Bold = true;
}
}
Note: I can get it to change in the page_load, but my point is it does not
appear that the gv_catalog_RowDataBound event is firing.

Questions:
1. Is there something else i need to do to get this even to fire?
2. I noticed that Intelesense does not work, i see items grayed out, but not
selectable.
 
P

Patrice

AFAIK using both languages in the same web application is not supported (IMO
may work, may not work depending on the deployment option etc you are
using).

In your case it's likely a problme with the AutoEventWriteUp attribute that
is false for VB.NET and true in C# projects. You may want to set this valeu
to true...

See http://odetocode.com/Blogs/scott/archive/2006/02/16/2914.aspx for
details.
 
G

Guest

it was set to true. so this is odd, unless it's a mixed code issue.
i did notice from the article you referencd that "Note: C# doesn’t make the
dropdown list of events available when editing a code-beside file, but the
dropdown is available when writing in-line code. "

Why is that?, i'd think it would code seperation would be encourged es in
C#! I'd hate to think i'll need to use in-line code sections to get the tools
available in VS.


--
thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes


Patrice said:
AFAIK using both languages in the same web application is not supported (IMO
may work, may not work depending on the deployment option etc you are
using).

In your case it's likely a problme with the AutoEventWriteUp attribute that
is false for VB.NET and true in C# projects. You may want to set this valeu
to true...

See http://odetocode.com/Blogs/scott/archive/2006/02/16/2914.aspx for
details.
 
J

Juan T. Llibre

re:
!> AFAIK using both languages in the same web application is not supported

Yes, it is supported.

You have to create a couple of subdirectories of the App_Code directory,
one for each language, and declare those directories in your web.config.

<configuration>
<system.web>
<compilation debug="false">
<codeSubDirectories>
<add directoryName="VB"/>
<add directoryName="CS"/>
</codeSubDirectories>
</compilation>
</system.web>
</configuration>

Then, creating the App_Code\VB and App_Code\CS directories,
and placing your VB and CS files in each, will allow you to use both languages in your app.

This only works in ASP.NET 2.0! ( and is quite easy to implement )

Caveat: this works only for "helper classes".
You cannot place code-behind pages in the individual language directories.

However, it *does* allow you to mix different-language source files in the same app,
and it does allow you to call classes/methods/properties in different languages.

An alternative would be to compile your different-language source files
from the command-line, and placing the compiled assemblies in /bin.







Patrice said:
AFAIK using both languages in the same web application is not supported (IMO may work, may not work depending on the
deployment option etc you are using).

In your case it's likely a problme with the AutoEventWriteUp attribute that is false for VB.NET and true in C#
projects. You may want to set this valeu to true...

See http://odetocode.com/Blogs/scott/archive/2006/02/16/2914.aspx for details.
 
P

Patrice

Historical reasons maybe. They 'll probably catch up in the future ?

So for now you could perhaps try to programmaticaly check if the event
handler is wired ? Try also perhaps to start a new project just to see if
you have the same behavior... Is this a page in the same dir than other
VB.NET pages etc...

Note also Juan response. This is actually supported despite a caveat....

Good luck and please let us know...

---
Patrice



WebBuilder451 said:
it was set to true. so this is odd, unless it's a mixed code issue.
i did notice from the article you referencd that "Note: C# doesn't make
the
dropdown list of events available when editing a code-beside file, but the
dropdown is available when writing in-line code. "

Why is that?, i'd think it would code seperation would be encourged es in
C#! I'd hate to think i'll need to use in-line code sections to get the
tools
available in VS.
 
G

Guest

very appreciated!!!!!!!
Thanks to both of you. My question other question is the same as above:

Do mos CS developers use inline as opposed to code sepration?
I'd perfer to use code separation but do not know how to get the events to
come up
with the exception of adding a gridview and then double clicking on it to
get the index_changed event.

How do you do it?
--
thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes


Juan T. Llibre said:
re:
!> AFAIK using both languages in the same web application is not supported

Yes, it is supported.

You have to create a couple of subdirectories of the App_Code directory,
one for each language, and declare those directories in your web.config.

<configuration>
<system.web>
<compilation debug="false">
<codeSubDirectories>
<add directoryName="VB"/>
<add directoryName="CS"/>
</codeSubDirectories>
</compilation>
</system.web>
</configuration>

Then, creating the App_Code\VB and App_Code\CS directories,
and placing your VB and CS files in each, will allow you to use both languages in your app.

This only works in ASP.NET 2.0! ( and is quite easy to implement )

Caveat: this works only for "helper classes".
You cannot place code-behind pages in the individual language directories.

However, it *does* allow you to mix different-language source files in the same app,
and it does allow you to call classes/methods/properties in different languages.

An alternative would be to compile your different-language source files
from the command-line, and placing the compiled assemblies in /bin.
 
M

Mark Rae [MVP]

Do most CS developers use inline as opposed to code sepration?

I never use in-line server-side code...
I'd perfer to use code separation but do not know how to get the events to
come up
with the exception of adding a gridview and then double clicking on it to
get the index_changed event.

How do you do it?

1) Switch into Design view

2) Select the relevant control

3) Click the lightning bolt icon in the Properties pane

4) Double-click the event which you want to create
 
G

Guest

My Friend,
Truely you are a "Fine American!!!" (or a fine "what ever country you care
to confess affiliation") can't thank you enough for this simple and obvious
item in VS. You have saved me from my greatest fear: having to write inline
code!!!! (i mean it)

IOU1 big time!
--
thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes
 
E

Evan M.

I never use in-line server-side code...



1) Switch into Design view

2) Select the relevant control

3) Click the lightning bolt icon in the Properties pane

4) Double-click the event which you want to create

Or to do it purely with manual code, which is all that these helper
double-clicks do:

On your ASPX page, pull up the source code, and find your gridview
item, and add the EventHandler method name to the event type, like so:
<asp:GridView id="GridView1" runat="server"
OnRowDataBound="MyEventNameHere" />

Then, add your event handler method to the code-behind page, as you
did above.
 
J

Juan T. Llibre

For the alternative point of view : I *never* use codebehind.

I haven't come across anything which can be done
in codebehind which can't be done in inline code.

As far as I'm concerned, codebehind is a duplication of effort which
involves doing in multiple files what can be done in a single file.

I hope this doesn't confuse the h*ll out of you, but only provides insight into that
the choice of inline vs. codebehind is up to the developer and what he/she feels
most comfortable with, depending on his/her programming style.

:)
 
M

Mark Rae [MVP]

I haven't come across anything which can be done
in codebehind which can't be done in inline code.

That is indeed true.
As far as I'm concerned, codebehind is a duplication of effort which
involves doing in multiple files what can be done in a single file.

The reason that I prefer codebehind is because I have a whole slew of base
classes which (obviously) all live in .cs files, so it just feels more
consistent to have *all* my server-side code in .cs files...
depending on his/her programming style.

That's the thing - there's really no difference once the web app is compiled
and deployed...
 
P

Patrice

A lightning striked me while going back to work. The event you are using is
just not handled automatically by the autoeventwireup attribute.

So you'll have to explicitely add this handler as shown in the article I
mentionned earlier...
 
D

Damien

That is indeed true.
But you can do something with inline code which you can't do with
codebehind - you can postpone a compilation error until the page is
hit :)

Damien
 
E

Evan M.

But you can do something with inline code which you can't do with
codebehind - you can postpone a compilation error until the page is
hit :)

Damien

Only if you're pre-compiling the web-app. If you're doing it on the
fly, you'll be fine (VS will inform you of the error whne you start to
debug it, but you can continue forward).

The reason I like code-behind rather than inline is the same reason
that I like separate CSS files rather than doing inline stylesheets:
It's the physical separation between content, formatting, and
scripting. Plus, I find it much easier to work with two, shorter,
files than one larger file.
 
G

Guest

Opinion appreciated!

I'm creating classes in vb now and have used code behind exclusively in all
my projects. It makes my life safer because when errors pop in as a result of
designers i can at least know they did not alter the code by accident. It
makes their life easier because they can create and complain (rightly so)
only about the junk html introduced by VS, but not about the stuff at the top.
--
thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes
 
G

Guest

same here but in vb.net however, i'm already starting to perfer cs. I, thanks
to your help and others, can create dual directories for code and add cs
classes for new items i create without having to rewrite the old (for now).
--
thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes
 
G

Guest

!
This is now, but i see a lot of room for other opinions here and they all work
--
thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,104
Latest member
LesliVqm09
Top