|
Quick ASP question: I want to include an ASP file only if certain conditions are met. Since the include statements are in HTML comments, can I do something like this: code:
Old hand at PHP, but the workplace is a Windows-only shop that uses ASP for everything, so if I made a complete n00b mistake, please let me know.
|
# ? Jul 9, 2008 19:29 |
|
|
# ? Jun 10, 2024 08:48 |
|
This is a horribly embarrassing question for someone who has been programming for a decade now, but I just can't find the right Google keywords to solve my query, so here we go: In C# .NET, how do I call a method that exists in another file? I have a using <Namespace> at the top of the file I want to call from, and the method that I want to call is public. Do I need a constructor in that file, and create an instance of that class?
|
# ? Jul 9, 2008 19:51 |
|
Strict 9 posted:In C# .NET, how do I call a method that exists in another file? I have a using <Namespace> at the top of the file I want to call from, and the method that I want to call is public. Do I need a constructor in that file, and create an instance of that class? First, it's "C#" - .NET is the platform. Second, methods only exist in classes, and classes != files. Unless the method is static, create an instance of the class and call the method. edit: Better post your code. The questions you're asking seem to indicate there's something strange about your design, because this is how every method is called in C#, and I think you may be trying to shove C# into another language's idiom
|
# ? Jul 9, 2008 20:02 |
|
dwazegek posted:Casting is not the same as an explicit conversion, even though the syntax is identical. Cool, thanks. Having to do stuff like that makes me feel that there is probably something wrong with the design, but whatever. Thanks :-)
|
# ? Jul 9, 2008 20:28 |
|
csammis posted:edit: Better post your code. The questions you're asking seem to indicate there's something strange about your design, because this is how every method is called in C#, and I think you may be trying to shove C# into another language's idiom
|
# ? Jul 9, 2008 22:26 |
|
Did Framework 3.5 change how try-catch-finally blocks work? I had a piece of code that worked fine in Framework 2.0 when I had a try-finally block, but then we recently upgraded to 3.5 and I spent the last hour trying to figure out how and why my exceptions were not being caught by the "finally" block unless I put "catch" there instead .
|
# ? Jul 9, 2008 23:40 |
|
pliable posted:Did Framework 3.5 change how try-catch-finally blocks work? I had a piece of code that worked fine in Framework 2.0 when I had a try-finally block, but then we recently upgraded to 3.5 and I spent the last hour trying to figure out how and why my exceptions were not being caught by the "finally" block unless I put "catch" there instead .
|
# ? Jul 10, 2008 01:29 |
|
csammis posted:First, it's "C#" - .NET is the platform. Second, methods only exist in classes, and classes != files. Unless the method is static, create an instance of the class and call the method. Considering all the languages that were crammed down my throat during college, I wouldn't be surprised if I was mixing up the terms. I don't have the code here at home, but basically I have a file, Template.aspx.cs, with a few public functions (I'm guessing functions would be a more accurate term here) that I'd like to call from other files. I've tried calling the function via MyProject.Template.Function(), but that doesn't work. So it sounds like your suggestion is to write a constructor for Template.aspx.cs, create an instance of it, and call the function using that instance?
|
# ? Jul 10, 2008 03:19 |
|
Strict 9 posted:Considering all the languages that were crammed down my throat during college, I wouldn't be surprised if I was mixing up the terms. Template.aspx.cs would be the "code behind" file for an ASP.NET page named (presumably) Template.aspx. In an ASP.NET scenario, you should think of the .aspx file and the .aspx.cs file as one class - they essentially get combined at runtime to build and output Template.aspx. If what you're looking to do is to have a class with a bunch of public static methods that you can call from any page anywhere in your project, what you'd probably want to do is add a class (not a web form) to your project and add those methods to it. EDIT: This is just a wild guess based solely on the file name you provided, but if you're looking for a way to have templates or base classes that other pages in your web site derive from, look into master pages. A master page is essentially a template that you fill with placeholders that other pages (content pages) derive from, much like a base class. You can design a master page with with all the design elements that other pages in your site will inherit and give it all the methods you want. Then, in any content pages you create that derive from that master page, all you have to do is cast that page's Master property to the specific type of your master page. Horse Cock Johnson fucked around with this message at 03:55 on Jul 10, 2008 |
# ? Jul 10, 2008 03:48 |
|
I'm currently creating a Windows Forms application and I keep running into pesky UI issues. I'm just not happy with the way the program looks and is used. I like some of the early stuff I saw that WPF could do but I'm afraid that going that route may require too much of my user base. I don't want them to have to download the .NET 3.0 framework for this application since I'm trying to appeal to the lowest common denominator. (Unless something has changed and WPF doesn't require additional framework downloads to work. Are there any stats on how many users have 3.0 already on their machine?) So I'm either wondering if market penetration is deep enough to justify the move to WPF. (I'm targeting users that may not be very technical, including teachers and schools.) And if that's not an option and I stick with 2.0 WinForms, how can I make my program not look like crap? I'm specifically looking for some sort of smooth animating filmstrip control on my user selection screen that would look like this. (I have an idea or two on how to code it but not sure if it's feasible.)
|
# ? Jul 10, 2008 04:08 |
|
Gary the Llama posted:I like some of the early stuff I saw that WPF could do but I'm afraid that going that route may require too much of my user base. I don't want them to have to download the .NET 3.0 framework for this application since I'm trying to appeal to the lowest common denominator. (Unless something has changed and WPF doesn't require additional framework downloads to work. Are there any stats on how many users have 3.0 already on their machine?) Someone can feel free to correct me if I'm wrong, but I'm pretty sure that WPF is integrated into .NET 3.5. As long as your users have the latest version of the .NET Framework (which can be bundled into an MSI or whatever method you're using to distribute your application), you could use WPF no problem.
|
# ? Jul 10, 2008 04:28 |
|
Mr. Herlihy posted:Someone can feel free to correct me if I'm wrong, but I'm pretty sure that WPF is integrated into .NET 3.5. As long as your users have the latest version of the .NET Framework (which can be bundled into an MSI or whatever method you're using to distribute your application), you could use WPF no problem. I understand that, but like I said, I'm trying to hit the lowest common denominator. I don't want to hassle the user with installing something extra. Of course, if the process of bundling and installing it is totally seamless for the user, that's nice. I guess I should run some tests and find out. And of course, if I switch to WPF, it's going to extend my development time quite a bit. Edit: Anyone have an idea how big the 3.5 framework is when bundled? Isn't it something like 200-300MB? That would be completely unacceptable since my program is tiny (should end up > 5MB) and I can't guarantee that my users will have access to broadband. Gary the Llama fucked around with this message at 04:34 on Jul 10, 2008 |
# ? Jul 10, 2008 04:32 |
|
Gary the Llama posted:Edit: Anyone have an idea how big the 3.5 framework is when bundled? Isn't it something like 200-300MB? That would be completely unacceptable since my program is tiny (should end up > 5MB) and I can't guarantee that my users will have access to broadband. Yeah, it's pretty big and I may have spoken too soon about bundling the framework install with an MSI anyway. I could have sworn I've seen ways to package the installer with an MSI before, but I can't seem to find anything specific on how to do it. I guess it really depends on who your users are as to whether or not you stick with Windows Forms or move to WPF. You say you're appealing to the "lowest common denominator", so until things like Vista and .NET 3.5 are a foregone conclusion or you can feel safe in asking your users to download something extra to make your app work, you might be better off sticking with Windows Forms.
|
# ? Jul 10, 2008 04:46 |
|
I have an interesting problem: I'm pulling data from three databases to be loaded on a page. Due to the nature of the databases there is a time difference between the data pulled from each one. One will be quicker than the others and one will be much slower. However the information pulled from each database is valid in its own right - so if the page only loaded information from one database they'd still be able to act on it - but it's the information from all three is the same "set". What I'm wondering is how it would be possible to perform the search, then when the information is returned from the first database I'd like to display the page, rather than waiting on the other two to return. But when the information becomes available from the other two databases then I'd like to update the page using some sort of AJAXY stuff, rather than a full page refresh. If anyone knows how to go about doing this then that'd be a great help.
|
# ? Jul 10, 2008 12:30 |
|
pliable posted:Did Framework 3.5 change how try-catch-finally blocks work? I had a piece of code that worked fine in Framework 2.0 when I had a try-finally block, but then we recently upgraded to 3.5 and I spent the last hour trying to figure out how and why my exceptions were not being caught by the "finally" block unless I put "catch" there instead . A finally block has never "caught" exceptions. Like melonhead said, its only purpose is to contain code that will be executed no matter how the try block is exited (either normally or when an exception is caught). The finally block doesn't have access to the thrown exception or anything like that. Melonhead posted:the code in your finally block is guaranteed to be executed (before the throw?) Exception thrown -> finally block executed -> exception passed back up the stack
|
# ? Jul 10, 2008 14:52 |
|
Mr. Herlihy posted:Template.aspx.cs would be the "code behind" file for an ASP.NET page named (presumably) Template.aspx. In an ASP.NET scenario, you should think of the .aspx file and the .aspx.cs file as one class - they essentially get combined at runtime to build and output Template.aspx. Ah, that was it! I was trying to do everything in web forms. I kind of, well, forgot about classes. Thanks!
|
# ? Jul 10, 2008 15:22 |
|
csammis posted:A finally block has never "caught" exceptions. Like melonhead said, its only purpose is to contain code that will be executed no matter how the try block is exited (either normally or when an exception is caught). The finally block doesn't have access to the thrown exception or anything like that. Ah, well then I'm retarded and obviously need to go back to school! Thank you both for the info.
|
# ? Jul 10, 2008 16:19 |
|
Mr. Herlihy posted:Yeah, it's pretty big
|
# ? Jul 10, 2008 16:46 |
|
Gary the Llama posted:I'm currently creating a Windows Forms application and I keep running into pesky UI issues. I'm just not happy with the way the program looks and is used. edit: oh, and the WPF issues are as outlined. I don't think .net 3.5 penetration is high enough to consider it a lowest common denominator solution.
|
# ? Jul 10, 2008 17:54 |
|
Anyone know exactly the effect of the .NET Runtime Optimization Service? I just got my own VPS instead of a shared hosting thing running and I see this in the service list. Now I don't have it running on my home or work computer, and by default its set to manual on my VPS so its not running either. Its obviously not essential, but whats the deal with it? What effect will I find by turning it on or off?
|
# ? Jul 10, 2008 22:24 |
|
Fastbreak posted:Anyone know exactly the effect of the .NET Runtime Optimization Service? I just got my own VPS instead of a shared hosting thing running and I see this in the service list. Now I don't have it running on my home or work computer, and by default its set to manual on my VPS so its not running either. Its obviously not essential, but whats the deal with it? What effect will I find by turning it on or off? That's the service that handles background NGen requests (compiling of assemblies into native code ahead of time so they don't need to be JITted at runtime). You'll generally only notice it running after installing a new .NET application or installing an update to the framework itself. Starting it directly yourself won't provide any performance benefit. In fact it may just stop itself right away if you try since it wouldn't have any work to do. NGen starts it when its needed. Disabling it entirely will have no immediate performance impact until you do one of the conditions above (installing a new .NET app or updating the framework), and then after that you'll notice worse performance (and in the case of framework updates, considerably worse performance).
|
# ? Jul 10, 2008 23:04 |
Is there any way to programmatically check to see if ActiveSync is installed?
|
|
# ? Jul 11, 2008 15:02 |
|
Currently we have to email Word documents to a third party in a specific PCL format. I do this (using VB.Net) by opening the document, switching to the correct print, and telling the document to print to file (by setting the relevant flag in the printout method. I then attach that document to an email and send it. However the system is changing from being email based to XML submitted of HTTP. The PCL document now needs to be encoded as a string within the XML document. What I'm wondering is if I can do this in a single step. Rather than print to file and then encode that file, can I capture the output of the document as it's printing and convert it to the appropriate format without actually saving it as a file. Probably a bit of a longshot, but I thought I'd check here as I'm not having much luck finding any information about this. Edit: I should add this isn't a big deal or anything, I can just delete the file as soon as I encode it. I guess I'm more curious than anything, it strikes me as something that shouldn't have to be this messy. Gravy Jones fucked around with this message at 15:45 on Jul 11, 2008 |
# ? Jul 11, 2008 15:06 |
|
Does anyone know of a way to do to polymorphic xml serialization of objects? I'm talking about the xml serialization you can define for a class using the definitions in System.Xml.Serialization. For example: code:
Is this possible using the existing framework?
|
# ? Jul 11, 2008 17:48 |
|
Panic! at the Fist Jab posted:Is there any way to programmatically check to see if ActiveSync is installed? Look for the registry key?
|
# ? Jul 11, 2008 18:50 |
|
Is there a good HTML parsing library for .NET? I guess I'm looking for something like Beautiful Soup that I can use in a C# project.
|
# ? Jul 11, 2008 19:47 |
|
This is kind of a javascript/C#.net question, so hopefully this is in the right thread. In my cs file I need to open up a new window for the user when they hit a button. The name of the file is stored in a string called pageToLoad and I open it up in a Response.Write() with some javascript. With a normal web address, it opens fine but when I try to put in a network location from the intranet, it errors. I have copied the data from pageToLoad into an address bar and it loads no problem, but the javascript I use seems to add things and mess with it. For example, if PageToLoad is "\\CompName\Folder\xmlFile.xml" it will switch it to "http://CompName/Folder/xmlFile.xml". Is there any way so it will just have the the string for the location and no extras added on or is there a better way to do what I am trying to do in the .Net framework? Here is the code in question: code:
|
# ? Jul 11, 2008 19:59 |
|
I'm trying to teach myself ASP.NET/C# and I've run into a problem that likely has a simple and elegant solution (but I can't think of it). I have an SQL query that returns a single column of ints. My goal is to see which int in the column has the most frequent occurrence--pretty simple, right? The real problem I'm having is populating a data structure with the data from the query so I can iterate through it and count the occurrences. Here's the code I've tried, which does not populate the array: code:
1. Try a fully qualified URL (myDomainURLVar + "CompName\Folder\xmlFile.xml") 2. Try a single slash at the beginning of the URL moww fucked around with this message at 21:06 on Jul 11, 2008 |
# ? Jul 11, 2008 20:43 |
|
moww posted:I'm trying to teach myself ASP.NET/C# and I've run into a problem that likely has a simple and elegant solution (but I can't think of it). Hint: you're not actually assigning votes[x] to anything.
|
# ? Jul 11, 2008 20:59 |
|
Richard Noggin posted:Hint: you're not actually assigning votes[x] to anything. I don't see what you mean. Am I not assigning values to votes[] when I do code:
EDIT: Thanks a million, Richard Noggin and mintskoal. The problem was using .NextResult() instead of .Read() (in the sample I posted, I accidentally wrote .MoveNext() instead of .NextResult()). moww fucked around with this message at 21:46 on Jul 11, 2008 |
# ? Jul 11, 2008 21:07 |
|
Yeah, it should. I missed the ++ at the end.
|
# ? Jul 11, 2008 21:18 |
|
moww posted:
For one thing, change .MoveNext() in the while loop to code:
|
# ? Jul 11, 2008 21:23 |
|
moww posted:I'm trying to teach myself ASP.NET/C# and I've run into a problem that likely has a simple and elegant solution (but I can't think of it). Thanks for the help, I just tagged on file:// on the front and it seemed to work. I guess it needs something otherwise it defaults to http://.
|
# ? Jul 11, 2008 21:35 |
|
Green_Machine posted:Is this possible using the existing framework? Yes. It should work exactly as you expect automatically, though you'll need to give the XmlSerializer the hint that it needs to build the logic to support Bar classes because otherwise it won't know how to handle them. Add an [XmlInclude(typeof(Bar))] attribute to either the Foo class, the MyXmlRootClass class, or in the constructor of the serializer.
|
# ? Jul 12, 2008 00:20 |
|
Linq-to-Sql question: I have a database table that will generally contain a fairly large number of rows (anywhere between 300k and 5M is normal). The primary key consists of a Guid and a DateTime. Periodically I'll get a list of identifier objects (again, a Guid and DateTime) which denote the items rows that have to be deleted from the database. Is there a clean and fast way to do this with linq-to-sql? My current solution is to enumerate through the objects and call a stored procedure for each item, which has proven to be much faster than any linq-to-sql method I've used so far, but I might be missing something.
|
# ? Jul 14, 2008 09:35 |
|
I apologize if this has been asked already, but I don't have platinum, and this thread is 70-some pages long. I have a grid view that is bound to a SQLCommand that is a stored procedure. The stored procedure returns a lot of fields that I don't want to display on my gridview. I want to hide those columns (as well as change header text, etc). here is my code: code:
|
# ? Jul 14, 2008 14:46 |
|
MuppetPastor posted:The headertext on column 1, however does not change when the application is run. Any ideas what I'm doing wrong? Are the columns being autocreated and overriding the change? I would have figured that the databinding would do the creation, but who knows, it may come after.
|
# ? Jul 14, 2008 15:20 |
|
The Noble Nobbler posted:Are the columns being autocreated and overriding the change? If I try to change anything before the databind, I would assume that the columns don't exist yet...
|
# ? Jul 14, 2008 15:57 |
|
MuppetPastor posted:If I try to change anything before the databind, I would assume that the columns don't exist yet... It might be easier to just set AutoGenerateColumns="false" and define your columns in the aspx like so: code:
|
# ? Jul 14, 2008 16:43 |
|
|
# ? Jun 10, 2024 08:48 |
|
MORE CURLY FRIES posted:I have an interesting problem: I've never actually done this on an ASP.NET page so I'm not sure if it's any different, but I have done it with sockets. Anyway, could you spawn three threads that do the DB work and as they return, asynchronously update the page? Something similar to this: http://msdn.microsoft.com/en-us/library/3dasc8as.aspx. Although in that example they wait for all the threads to finish before displaying the results, while, as you said, you'd want to update the page immediately one by one as they finish.
|
# ? Jul 15, 2008 05:20 |