.NET Forum / ASP.NET / General / August 2007
VB vs C# question (trying to switch languages)
|
|
Thread rating:  |
WebBuilder451 - 22 Aug 2007 15:26 GMT 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.
 Signature thanks (as always) some day i''m gona pay this forum back for all the help i''m getting kes
Patrice - 22 Aug 2007 15:37 GMT 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.
--- Patrice
> I'm trying to make the jump from VB to C#. Aside from the syntax issues > i'm [quoted text clipped - 22 lines] > not > selectable. WebBuilder451 - 22 Aug 2007 16:22 GMT 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.
 Signature thanks (as always) some day i''m gona pay this forum back for all the help i''m getting kes
> 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 [quoted text clipped - 36 lines] > > not > > selectable. Patrice - 22 Aug 2007 18:18 GMT 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
> 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 [quoted text clipped - 52 lines] >> > not >> > selectable. WebBuilder451 - 22 Aug 2007 18:44 GMT very appreciated!! thank you
 Signature thanks (as always) some day i''m gona pay this forum back for all the help i''m getting kes
> Historical reasons maybe. They 'll probably catch up in the future ? > [quoted text clipped - 66 lines] > >> > not > >> > selectable. Patrice - 23 Aug 2007 08:59 GMT 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...
--- Patrice
> very appreciated!! thank you > [quoted text clipped - 74 lines] >> >> > not >> >> > selectable. WebBuilder451 - 23 Aug 2007 14:44 GMT thanks
 Signature thanks (as always) some day i''m gona pay this forum back for all the help i''m getting kes
> A lightning striked me while going back to work. The event you are using is > just not handled automatically by the autoeventwireup attribute. [quoted text clipped - 83 lines] > >> >> > not > >> >> > selectable. Juan T. Llibre - 22 Aug 2007 17:38 GMT 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.
Juan T. Llibre, asp.net MVP asp.net faq : http://asp.net.do/faq/ foros de asp.net, en español : http://asp.net.do/foros/ ======================================
> 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). [quoted text clipped - 31 lines] >> 2. I noticed that Intelesense does not work, i see items grayed out, but not >> selectable. WebBuilder451 - 22 Aug 2007 18:44 GMT 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?
 Signature thanks (as always) some day i''m gona pay this forum back for all the help i''m getting kes
> re: > !> AFAIK using both languages in the same web application is not supported [quoted text clipped - 68 lines] > >> 2. I noticed that Intelesense does not work, i see items grayed out, but not > >> selectable. Mark Rae [MVP] - 22 Aug 2007 19:22 GMT > 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
 Signature Mark Rae ASP.NET MVP http://www.markrae.net
WebBuilder451 - 22 Aug 2007 19:44 GMT 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!
 Signature thanks (as always) some day i''m gona pay this forum back for all the help i''m getting kes
> > Do most CS developers use inline as opposed to code sepration? > [quoted text clipped - 14 lines] > > 4) Double-click the event which you want to create Juan T. Llibre - 22 Aug 2007 20:10 GMT 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.
:-) Juan T. Llibre, asp.net MVP asp.net faq : http://asp.net.do/faq/ foros de asp.net, en español : http://asp.net.do/foros/ ======================================
> My Friend, > Truely you are a "Fine American!!!" (or a fine "what ever country you care [quoted text clipped - 22 lines] >> >> 4) Double-click the event which you want to create Mark Rae [MVP] - 22 Aug 2007 21:13 GMT > 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...
 Signature Mark Rae ASP.NET MVP http://www.markrae.net
Damien - 23 Aug 2007 10:37 GMT > > I haven't come across anything which can be done > > in codebehind which can't be done in inline code. > > 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
Evan M. - 23 Aug 2007 14:16 GMT > On Aug 22, 9:13 pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.net> wrote:> "Juan T. Llibre" <nomailrepl...@nowhere.com> wrote in messagenews:OsPjQAP5HHA.1204@TK2MSFTNGP03.phx.gbl... > [quoted text clipped - 8 lines] > > 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.
WebBuilder451 - 23 Aug 2007 14:38 GMT ! This is now, but i see a lot of room for other opinions here and they all work
 Signature thanks (as always) some day i''m gona pay this forum back for all the help i''m getting kes
> > On Aug 22, 9:13 pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.net> wrote:> "Juan T. Llibre" <nomailrepl...@nowhere.com> wrote in messagenews:OsPjQAP5HHA.1204@TK2MSFTNGP03.phx.gbl... > > [quoted text clipped - 18 lines] > scripting. Plus, I find it much easier to work with two, shorter, > files than one larger file. WebBuilder451 - 23 Aug 2007 14:36 GMT 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).
 Signature thanks (as always) some day i''m gona pay this forum back for all the help i''m getting kes
> > I haven't come across anything which can be done > > in codebehind which can't be done in inline code. [quoted text clipped - 12 lines] > That's the thing - there's really no difference once the web app is compiled > and deployed... WebBuilder451 - 23 Aug 2007 14:34 GMT 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.
 Signature thanks (as always) some day i''m gona pay this forum back for all the help i''m getting kes
> For the alternative point of view : I *never* use codebehind. > [quoted text clipped - 40 lines] > >> > >> 4) Double-click the event which you want to create Evan M. - 22 Aug 2007 19:49 GMT > > Do most CS developers use inline as opposed to code sepration? > [quoted text clipped - 18 lines] > Mark Rae > ASP.NET MVPhttp://www.markrae.net 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.
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|