Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
cowboy beepboop
Feb 24, 2001

Am I missing something obvious here? When I create a ListBox and populate it like so:
code:
<ListBox Name="LibraryListBox" 
         Grid.ColumnSpan="2" 
         MouseDoubleClick="replacePlaylistWithSelection" 
         Margin="6,6,6,2" 
         SelectionMode="Single"/>
How come when I try to select an item it will always select the item I click on and the first item (ie index 0)?? Then if I click another item to select I've suddenly got three items selected? I assumed SelectionMode="Single" should have taken care of that :(

edit It looks like that only happens if all the listbox's entries are the same

edit2 Oh my god now it's calling that function when I double click on the loving scroll bar on the side :psyduck:

cowboy beepboop fucked around with this message at 09:19 on May 6, 2007

Adbot
ADBOT LOVES YOU

Colbo
Jul 12, 2002

The monkey is not impressed

Elky posted:

Am I missing something obvious here? When I create a ListBox and populate it like so:
code:
<ListBox Name="LibraryListBox" 
         Grid.ColumnSpan="2" 
         MouseDoubleClick="replacePlaylistWithSelection" 
         Margin="6,6,6,2" 
         SelectionMode="Single"/>
How come when I try to select an item it will always select the item I click on and the first item (ie index 0)?? Then if I click another item to select I've suddenly got three items selected? I assumed SelectionMode="Single" should have taken care of that :(

edit It looks like that only happens if all the listbox's entries are the same

edit2 Oh my god now it's calling that function when I double click on the loving scroll bar on the side :psyduck:


The mouseclick events (onclick, doubleclick, etc..) have nothing to do with the selection of an item in a listbox. You want the "SelectedIndexChanged" or "SelectedValueChanged" events.

csammis
Aug 26, 2003

Mental Institution

Colbo posted:

The mouseclick events (onclick, doubleclick, etc..) have nothing to do with the selection of an item in a listbox. You want the "SelectedIndexChanged" or "SelectedValueChanged" events.

That won't fire on double-click, just single click. This might be closer to what you're looking for:

code:
<ListBox ... ListBoxItem.MouseDoubleClick="Item_DoubleClick" />
VS's XAML editor will whine about it not being defined, but it should compile and run fine. It works for TreeView and TreeViewItem anyway.

As for your selection problems, I'm not sure what's going on from your description. Can you post code?

cowboy beepboop
Feb 24, 2001

Oh I see. Thanks Colbo and csammis. The issue with the selections is simple. I populated the listbox with a simple for loop with lots of entries that were exactly the same. For some odd reason this causes the listbox to get a bit nutty. eg
code:
xaml:
<ListBox Name="Testcase"
         SelectionMode="Single" />

cs:
for (int i=0;i < 10;i++)
{
    Testcase.Items.Add("Item");
}
That, on my system (Vista 32bit;VS2005 Express) seems to make it freak out. When I populate my listbox with something useful, it doesn't.

Dromio
Oct 16, 2002
Sleeper
Edit: Nevermind. I figured this one out. I forgot that the authentication was set for a very short timeout.

_____________________________________________________________________________________

I'm still figuring out ASP.NET and forms authentication.

I've got an ASP.NET site with forms authentication enabled. I have another application which spits .htm files into the ASP.NET site. I set up the ASP.NET application to run .htm files through the aspnet_isapi.dll and added the following to the web.config file:
code:
<httpHandlers>
      <add verb="GET,HEAD" path="*.html" type="System.Web.StaticFileHandler" />
      <add verb="GET,HEAD" path="*.htm" type="System.Web.StaticFileHandler" />
</httpHandlers>
This works! Now someone has to be authenticated to view the static pages, which is great. But those static pages might be changed several times a day, and the StaticFileHandler stupidly sets an expiration on the documents, so the end user browser caches the pages and they don't see the changes immediately.

So I write a simple httpHandler that does not set the expiration. This was also pretty easy and works well.

BUT, now every time the static page changes, ASP.NET wants the user to authenticate again. This won't fly at all. It looks like when I re-authenticate, the cookie ASP.NET is using has changed. Does anyone know how I can change this behavior?

Dromio fucked around with this message at 17:04 on May 7, 2007

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



I'm trying to output a big XML document that I'm generating in a readable, formatted way for easier editing, but It's not working right and I can't see why.

code:
XmlDocument output = new XmlDocument();
output.LoadXml("<cruisecontrol></cruisecontrol>");
XmlNode root = output.DocumentElement;

foreach(BuildDependency bd in dte.Solution.SolutionBuild.BuildDependencies)
{//executes 23 times
	root.AppendChild(output.CreateComment(bd.Project.Name + " Project Begins"));
	root.AppendChild(BuildConfigForProject(bd));
	root.AppendChild(output.CreateComment(bd.Project.Name + " Project Ends"));
	root.AppendChild(output.CreateSignificantWhitespace("\n"));
	root.AppendChild(output.CreateSignificantWhitespace("\n"));
}

XmlTextWriter writer = new XmlTextWriter(outFile, Encoding.Default);
writer.Formatting = Formatting.Indented;
output.WriteTo(writer);
writer.Flush();
writer.Close();
Outputs XML that looks like this:
code:
<cruisecontrol>
  <!--Project1 Project Begins-->
    <!--Nicely-formattted XML-->
    <ItIsTime>True</ItIsTime>
  <!--Project1 Ends-->
  
<!--project2 project Begins--><Thar be 2500-character strings in these waters cap'n>

<!--Same here times 21-->
</cruisecontrol>
Does Formatting.Indented somehow only apply to the first child node of the document root? Every example I found online that uses a XmlDocument object to build their document does it this way, but all the examples I found were also trivial. Still seems weird.

Edit: it's the meaningfull white space nodes loving it up :\

quote:

Edited by whom and in what editor?

By me in Visual Studio :smith:

Munkeymon fucked around with this message at 18:50 on May 10, 2007

BryanGT
Oct 15, 2002

Goodnight, sweet prince.

Munkeymon posted:

I'm trying to output a big XML document that I'm generating in a readable, formatted way for easier editing, but It's not working right and I can't see why.

Hol'up. Edited by whom and in what editor?

Fiend
Dec 2, 2001

Munkeymon posted:

I'm trying to output a big XML document that I'm generating in a readable, formatted way for easier editing, but It's not working right and I can't see why.



Outputs XML that looks like this:


Does Formatting.Indented somehow only apply to the first child node of the document root? Every example I found online that uses a XmlDocument object to build their document does it this way, but all the examples I found were also trivial. Still seems weird.

Edit: it's the meaningfull white space nodes loving it up :\
I removed the <thar be> node as it was bombing out. I made a tool that I put in the explorer context menu so I can view xml files that are indented like you want them.

I have this compiled as a console app that I call from a context menu:
code:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;

class Program
{
    static String FilePath;
    static String SourceFile;
    static String OutputFile;
    static void Main(string[] args)
    {
        // takes one or two arguments <exe> <inputFileName> <outputFileName>
        // if one arg was passed, that file is both input/output file
        if (args.Length == 0 || args.Length > 2)
        {
            PrintUsageInfo();
            return;
        }
        if (args.Length == 1)
        {
            FilePath = args[0].ToString();
            if (File.Exists(FilePath))
            {
                StreamReader sr = File.OpenText(FilePath);
                string s = sr.ReadToEnd();
                sr.Close();
                sr.Dispose();
                if (!IsXml(s))
                {
                    Console.WriteLine("Error: File is not xml format: \r\n" + FilePath);
                    return;
                }
                XmlDocument xld = new XmlDocument();
                xld.LoadXml(s);
                SaveXmlFile(xld, FilePath);
            }
            else
            {
                Console.WriteLine("Error: File does not exist: \r\n" + FilePath);
                return;
            }
        }

    }
    static Boolean IsXml(string xmlString)
    {
        XmlDocument xld = new XmlDocument();
        try
        {
            xld.LoadXml(xmlString);
            return true;
        }
        catch(Exception)
        {
            return false;
        }
    }
    static string SaveXmlFile(XmlDocument xld, String fileName)
    {
        StringWriter sw = new StringWriter();
        XmlTextWriter writer = new XmlTextWriter(sw);
        writer.Formatting = Formatting.Indented;
        xld.WriteTo(writer);
        String message = sw.ToString();
        StreamWriter sr = File.CreateText(fileName);
        sr.WriteLine(message);
        sr.Flush();
        sr.Close();
        return fileName;
    }

    /// <summary>
    /// Prints the usage information for this app.
    /// </summary>
    static void PrintUsageInfo()
    {
        string sOut = "Usage: \r\n";
        sOut += " fXml.exe <fileName>";
        Console.WriteLine(sOut);
    }
}
Here is the registry information to add a "formatXml" option when you right click on an xml file in explorer:
code:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\xmlfile\shell\formatXml]

[HKEY_CLASSES_ROOT\xmlfile\shell\formatXml\command]
@="C:\\WINDOWS\\system32\\fXml.exe \"%1\""

genki
Nov 12, 2003

Fiend posted:

...code...
Uh, you know you aren't handling the case where the user passes in 2 arguments, right?

Fiend
Dec 2, 2001

genki posted:

Uh, you know you aren't handling the case where the user passes in 2 arguments, right?
Yep.

Nibelheim
Jul 7, 2006

Could anyone recommend me a good reference book to learn ASP? (.net)
I've been coding for years, I've built tons of PHP apps, I don't need an introduction to web programming. Just a reference book.

Thanks !

Dromio
Oct 16, 2002
Sleeper
Is there any way to configure the "Application Settings" portion of an IIS virtual directory? For example, I want to programatically create a virtual directory in IIS, create "Application Settings" (like when you click "Create" on the Directory tab of the virtual directory properties), then add ISAPI mappings for .htm and .html files to that virtual directory's application configuration.

I can access a bunch of properties using System.DirectoryServices, but I don't see the mappings anywhere in there. Does anyone have any ideas?

Edit: Got it:

code:
using System.DirectoryServices;
        private static void CreateVirtualDirectory(string Name)
        {
            DirectoryEntry Parent = new DirectoryEntry(@"IIS://localhost/W3SVC/1/ROOT");
            DirectoryEntry NewVD = Parent.Children.Add(Name, "IIsWebVirtualDir");
            NewVD.Properties["Path"].Insert(0, "c:\\Props");
            NewVD.Invoke("AppCreate", true);
            NewVD.Properties["AppFriendlyName"].Value = Name;
            PropertyValueCollection Maps = NewVD.Properties["ScriptMaps"];
            PropertyValueCollection ParentMaps = Parent.Properties["ScriptMaps"];
            foreach (string Map in ParentMaps)
            {
                Maps.Add(Map);
            }
            Maps.Add(@".htm,c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1");
            Maps.Add(@".html,c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1");
            NewVD.CommitChanges();
            Parent.CommitChanges();
            NewVD.Close();
            Parent.Close();
        }

Dromio fucked around with this message at 14:26 on May 11, 2007

Obsurveyor
Jan 10, 2003

Nibelheim posted:

Could anyone recommend me a good reference book to learn ASP? (.net)
I've been coding for years, I've built tons of PHP apps, I don't need an introduction to web programming. Just a reference book.
Are you familiar with the .NET Framework? If not, I suggest picking up a book that has to do with the language you ultimately want to program in. I went "Learning C#" by O'Reilly->"Visual C# 2005 Step-by-Step" by Microsoft Press->"Visual C# 2005: The Language" by Microsoft Press(more as a reference, did not read cover to cover)->"ASP.NET 2.0 Step-by-Step"->"ASP.NET 2.0 Core Reference" by Microsoft Press.

You could pick up a book specifically on the .NET Framework but I found that the two C# books covered a lot of what I needed to know anyway.

BryanGT
Oct 15, 2002

Goodnight, sweet prince.

Nibelheim posted:

Could anyone recommend me a good reference book to learn ASP? (.net)
I've been coding for years, I've built tons of PHP apps, I don't need an introduction to web programming. Just a reference book.

Thanks !

They're not very much alike, and shouldn't be.

poopiehead
Oct 6, 2004

Nibelheim posted:

Could anyone recommend me a good reference book to learn ASP? (.net)
I've been coding for years, I've built tons of PHP apps, I don't need an introduction to web programming. Just a reference book.

Thanks !

Like the other two said, ASP .NET isn't really going to be anything like PHP. Classic ASP is bascially just PHP but with VBScript and new names for some of the server stuff.

ASP .NET is a framework. It does a lot for you and really isn't designed to be used with a bunch of echo statements. You can definitely write ASP .NET pages like PHP pages, but you'd be missing the major advantages of ASP .NET. Also, if your only coding experience is with PHP, there probably will be some amount of transition involved in using a more strongly typed and object oriented language.

If you have a bunch of experience programing and once you're somewhat familiar with C# or VB .NET(probably C# in your case), Wrox Professional ASP .NET is probably a really good resource. It's not a reference but it covers a lot of ground.

Nibelheim
Jul 7, 2006

poopiehead posted:

Like the other two said, ASP .NET isn't really going to be anything like PHP. Classic ASP is bascially just PHP but with VBScript and new names for some of the server stuff.

ASP .NET is a framework. It does a lot for you and really isn't designed to be used with a bunch of echo statements. You can definitely write ASP .NET pages like PHP pages, but you'd be missing the major advantages of ASP .NET. Also, if your only coding experience is with PHP, there probably will be some amount of transition involved in using a more strongly typed and object oriented language.

If you have a bunch of experience programing and once you're somewhat familiar with C# or VB .NET(probably C# in your case), Wrox Professional ASP .NET is probably a really good resource. It's not a reference but it covers a lot of ground.

I've got experience in many different languages. I've mainly coded in C++, Java and Python. I've been writing scripts in VB for a good 7 months now, and am slowly getting used to the syntax.

I've fetched my first job in the field as a junior networks technician for this summer, but I'll have a few side projects to work on. I have to write small web applications (DB fetches, search functions, form/data processing) that I could very easily do in PHP, but the corporation is strictly under MS frameworks. I'm just looking for a good book to make me understand the logic behind .NET and be able to write my small applications under them in ASP.

My college's web courses concentrated on PHP/JS with Oracle DB access.

Fryedegg
Jan 13, 2004
Everquest killed my libido (and my cat). 8(

Nibelheim posted:

I've got experience in many different languages. I've mainly coded in C++, Java and Python. I've been writing scripts in VB for a good 7 months now, and am slowly getting used to the syntax.

I've fetched my first job in the field as a junior networks technician for this summer, but I'll have a few side projects to work on. I have to write small web applications (DB fetches, search functions, form/data processing) that I could very easily do in PHP, but the corporation is strictly under MS frameworks. I'm just looking for a good book to make me understand the logic behind .NET and be able to write my small applications under them in ASP.

My college's web courses concentrated on PHP/JS with Oracle DB access.

I highly recommend this title:
http://www.amazon.com/Pro-2005-NET-Platform-Third/dp/1590594193

I bought it new at Barnes and Noble for $60. I started with .NET/C# at my job a few months ago working on coding a new Call Tracker for our help desk. I had no previous experince with the framework, but I had taken a few C++/Java courses in college, and this book was just the perfect level for me.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
Ok so I'm writing a program to plot the Mandelbrot Set (wiki). I'm using a seperate thread to generate the image, and then sending that back to the main GUI thread to be displayed. Problem is, the images often take a long time to generate and in order to keep things interesting I wanted to display the image as it's being generated. How would I do this while keeping it threadsafe? I thought to make a delagate that sets a pixel and using BeginInvoke, but that seems like a lot of overhead to me and I don't want to slow the program down. However I don't really know how .NET handles delegates internally so I could be wrong about that. Any ideas or info would be appreciated.

Hypnotadpole
Apr 20, 2007

HappyHippo posted:

Ok so I'm writing a program to plot the Mandelbrot Set (wiki). I'm using a seperate thread to generate the image, and then sending that back to the main GUI thread to be displayed. Problem is, the images often take a long time to generate and in order to keep things interesting I wanted to display the image as it's being generated. How would I do this while keeping it threadsafe? I thought to make a delagate that sets a pixel and using BeginInvoke, but that seems like a lot of overhead to me and I don't want to slow the program down. However I don't really know how .NET handles delegates internally so I could be wrong about that. Any ideas or info would be appreciated.

Probably the most sensible option is to call CreateGraphics (it's safe to call CreateGraphics from other threads) on the control that you are painting the set in from the thread that is calculating it, and update the drawing as you go. Obviously in the paint method for the control you'll still need to handle drawing it, since the thread doing the calculation will only temporarily pain tthe pixels but it won't handle repainting later on.

Make sure you don't forget to dispose the returned Graphics object when you finish with it.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Hypnotadpole posted:

Probably the most sensible option is to call CreateGraphics (it's safe to call CreateGraphics from other threads) on the control that you are painting the set in from the thread that is calculating it, and update the drawing as you go. Obviously in the paint method for the control you'll still need to handle drawing it, since the thread doing the calculation will only temporarily pain tthe pixels but it won't handle repainting later on.

Make sure you don't forget to dispose the returned Graphics object when you finish with it.

This combined with Graphics.DrawImage did the trick. Thanks.

KiwiDNA
Mar 6, 2003
I'm pulling a file from a SQL database, storing it in a byte array, creating a memory stream from that byte array, and then trying to create a DIME attachment with that stream. Unfortunately I'm getting a "Object reference not set to an instance of an object" exception.

fileData = r("data")
binaryFile = New MemoryStream(fileData)
Dim attachment As New DimeAttachment(mimeType, TypeFormat.MediaType, binaryFile)
ResponseSoapContext.Current.Attachments.Add(attachment)

Any idea what I'm missing? This is in a Web Service by the way.

stramit
Dec 9, 2004
Ask me about making games instead of gains.
Hey guys, I'm a Java guy but have recently been playing around with C# at uni for a group project. It's a pretty nice system and I wouldn't mind staying if it weren't for a few little things. But that's beside the point; I've come to ask a question.

I have written a webservice and it works pretty handily on the server side, responding to all the requests I send at it. The problem I having is at the client side, the responses I receive are dumb 'bean' objects mapping to the WSDL file. That's all well and good but I was wondering if there was quick and non hacky way to convert these objects back into their native type. My idea was to write a look up / mapping service for the client that could do this; but then I realised that this would probably be a common issue. I don't want to re-roll a feature which could well be built into C#

Thanks for the help.

DLCinferno
Feb 22, 2003

Happy

Stramit posted:

I have written a webservice and it works pretty handily on the server side, responding to all the requests I send at it. The problem I having is at the client side, the responses I receive are dumb 'bean' objects mapping to the WSDL file. That's all well and good but I was wondering if there was quick and non hacky way to convert these objects back into their native type. My idea was to write a look up / mapping service for the client that could do this; but then I realised that this would probably be a common issue. I don't want to re-roll a feature which could well be built into C#
I've never worked with webservices so someone correct me if I'm wrong but this sounds like you could use the serialization functionality in C# to great effect.

I was going to type out an example, but I think you could find a better rundown on this page. Basically, .NET makes it incredibly easy to do what you need.

http://www.dotnetjohn.com/articles.aspx?articleid=173

uXs
May 3, 2005

Mark it zero!
I have a problem with namespaces:

I'm working on a project (asp.net, c#), with several layers:
-The WebUI (= a website)
-A businessrules layer (= a class library)
-A datalayer (= a class library)

All layers are in seperate projects. There's also a third class library that contains the business objects. The datalayer gets stuff from the database, puts it in a business object, and passes them on to the business layer, which passes it to the WebUI. (All projects are different namespaces as well.)

Now the problem I'm having is that for a specific business object, the WebUI layer (sometimes) only recognizes them when I fully qualify it with the namespace.

Example:

code:
WeirdClass myObject = WeirdClassManager.GetItem(id_object_needed);
"WeirdClass" is located in the namespace Company.Project.BusinessObjects, and Intellisense recognizes it as such. The GetItem function (located in the business rules layer) returns an object of that same class. But when I try to compile it, I get the error "Cannot implicitly convert type 'Company.Project.BusinessObjects.WeirdClass' to 'WeirdClass'. When I add the namespace, it does work correctly:

code:
Company.Project.BusinessObjects.WeirdClass myObject = WeirdClassManager.GetItem(id_object_needed);
The page has a reference to the business objects project and a "using Company.Project.BusinessObjects" statement, so why wouldn't it work ? In fact, there are other classes, that work exactly the same way, for which it does work ! I compared the code for those classes, and I can't see any difference.

Same problem: when I declare an object of that class (without fully qualifying with the namespace), I can't even use its properties. Intellisense recognizes the object and shows the properties, but compiling tells me that "'WeirdClass' does not contain a definition for 'Id_weirdClass'". When I qualify it, it does work.

When I right-click the class, and do "go to definition", it shows me a definition generated "from metadata", that includes all the right properties, and is in the correct namespace. Fully qualifying the class, and then asking for the definition again, shows me exactly the same thing. But still the compiler thinks they're different.

I'm stumped. (I could just always name fully name them, but that annoys me.) Any ideas ?

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
uXs, do you happen to have a namespace with the exact same name as the class you're having problems with? If I recall correctly, that caused a problem for me, too. If you had a namespace named 'WeirdClass', the compiler won't be able to tell the difference between the class and the namespace, and fully qualifying the class name would be necessary.

uXs
May 3, 2005

Mark it zero!
Oh god yes thank you. I should've known it was something stupid like that. There was a webpage with that same name. (And webpages are classes as well in .NET.)

It didn't give the same error for the other object that did work correctly, because while there was also a page for that object, the capitalization was slightly different so there was no conflict there. :suicide:

Thanks ! (And now, weekend ! :toot: )

Obsurveyor
Jan 10, 2003

I am just getting started with ASP.NET AJAX and I have been going through examples and things, just getting a feel for it. I noticed something which seems wrong to me: If you fire an asynchronous postback, the page updates *all* controls on the page that have changed, not just the ones in the UpdatePanel. This seems to me like it could get my applications into an invalid state. For example:

test.aspx:
code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"  />
		<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><div>
			&nbsp;</div>
		<asp:UpdatePanel ID="UpdatePanel1" runat="server">
			<ContentTemplate>
				<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>&nbsp;<br />
			</ContentTemplate>
			<Triggers>
				<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
			</Triggers>
		</asp:UpdatePanel>
				<asp:Button ID="Button1" runat="server" Text="Button1" />
		<br />
		<br />
		<asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" />
		<asp:Label ID="Label3" runat="server" Text="Label" Width="173px"></asp:Label>
		<asp:Button ID="Button2" runat="server" Text="Button2" />
    </form>
</body>
</html>
test.aspx.cs:
code:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
		Label1.Text = System.DateTime.Now.ToString();
		Label2.Text = System.DateTime.Now.ToString();
    }

	protected void CheckBox1_CheckedChanged( object sender, EventArgs e )
	{
		Label3.Text = "Checked!";
	}
}
If you run this page, clicking Button1 will update the second label, showing the time change for the asynchronous update. However, if you check the checkbox, click Button1, uncheck the checkbox and then click Button2 which submits a regular postback, the third label changes to "Changed" even though, to the user, they did not really change any settings.

Now, granted, this is a situation I have created to show off the issue but is this something to worry about in real life applications? Is there a best practice for mixing AJAX and non-AJAX postbacks that I should keep in mind?

Dromio
Oct 16, 2002
Sleeper
What is going on here? Why is this string not defined? In the debugger, I step past the following code:

code:
string DocGUID = OutputNode.ParentNode.Attributes["title"].Value;
After that the immediates window and I have the following conversation:
code:
? DocGUID;
The name 'DocGUID' does not exist in the current context
string DocGUID = OutputNode.ParentNode.Attributes["title"].Value;
"3284E45F-6DD9-4ac4-8BFD-98F6A649C233"
? DocGUID;
"3284E45F-6DD9-4ac4-8BFD-98F6A649C233"
No other code was executed between the line and my work in the immediates window. Why is it treating me like this?

Edit: Even worse, if I initialize DocGUID as an empty string before this, then just set it's value here instead of initialize AND set, it STILL claims that DocGUID does not exist in the current context.

Final Edit: AHA! I was running under the "Release" configuration, which I guess drops any variables which aren't read later in the code. Since I hadn't written any code to actually read the DocGUID string and use it later, it was pretending it didn't exist at all.

Dromio fucked around with this message at 20:44 on May 17, 2007

poopiehead
Oct 6, 2004

I have to make an ASP .NET application that allows user registration and login, etc. I've only really done authentication using Windows Authentication so far. So I have a question.

Do you people generally use the built in ASP .NET login and account creation controls(and membership service) or do you tend to roll your own?

If you do use the .NET membership service, how do you deal with extra user information? Do you add to the users table itself or do you make your own separate table with a foreign key?

Dromio
Oct 16, 2002
Sleeper

poopiehead posted:

I have to make an ASP .NET application that allows user registration and login, etc. I've only really done authentication using Windows Authentication so far. So I have a question.

Do you people generally use the built in ASP .NET login and account creation controls(and membership service) or do you tend to roll your own?

If you do use the .NET membership service, how do you deal with extra user information? Do you add to the users table itself or do you make your own separate table with a foreign key?

I've just started with ASP.NET Membership, but it seems to work great for me. The site itself uses the standard "Create User Wizard" control to add new users, and I wrote a winforms app to do the initial setup and populate the initial admin accounts before the site goes online.

You can use Profiles to add more information to the users.

poopiehead
Oct 6, 2004

Dromio posted:

I've just started with ASP.NET Membership, but it seems to work great for me. The site itself uses the standard "Create User Wizard" control to add new users, and I wrote a winforms app to do the initial setup and populate the initial admin accounts before the site goes online.

You can use Profiles to add more information to the users.

Thanks! I guess I'll have to jump in and start playing.

Dromio
Oct 16, 2002
Sleeper
I'm still trying to figure out all this ASP.NET stuff.

This ought to be a simple one, but it's not working like I expected. I'm using a master page that is housed in the main folder of my application, and that master page has a hyperlink to a page in the same folder. Something like this:

code:
<Site>
  masterpage.master (has link to "~/ChangePassword.aspx")
  ChangePassword.aspx
  <SubSite>
    SubPage.aspx (uses ..\masterpage.master)

But in the SubSite/SubPage.aspx, the link ends up pointing to http://server/Site/SubSite/ChangePassword.aspx. I thought the ~ meant to go to the application root.

Here's the hyperlink in the masterpage:
code:
<asp:HyperLink ID="HL1" runat="server" NavigateUrl="~/ChangePassword.aspx">
  Change Password
</asp:HyperLink>
Did I misunderstand what "~" does?

Edit: And again I struggle for hours, post, then immediately figure it out on my own. There was an errant base tag in the header that was screwing with my relative links.

Dromio fucked around with this message at 20:59 on May 18, 2007

Horse Cock Johnson
Feb 11, 2005

Speed has everything to do with it. You see, the speed of the bottom informs the top how much pressure he's supposed to apply. Speed's the name of the game.
Can anyone suggest a good book on .NET remoting? Ingo Rammer's Advanced .NET Remoting gets a lot of high praise, but the description says its targeted at .NET 1.1 and work with 2.0.

Is it safe to say that not much has changed between 1.1 and 2.0 with regards to remoting or is there another book out there I should look into?

mcw
Jul 28, 2005
This will indeed be a stupid question, but...

I'm learning C# from a book and though the book in question (Essential C# 2.0 by Mark Michaelis) is generally very good, the chapter on interfaces has me confused. Given the way it's explained in this book, I really don't understand the concept of interfaces and why I would want to use one. Could someone give me an example of an area in which an interface would be helpful, so I could get a better idea of how and why I would use one of these in practice?

Thank you!

biznatchio
Mar 31, 2001


Buglord

MariusMcG posted:

I really don't understand the concept of interfaces and why I would want to use one. Could someone give me an example of an area in which an interface would be helpful, so I could get a better idea of how and why I would use one of these in practice?

An interface is a way of implementing strongly-typed contracts on an object independent of the inheritance heirarchy.

A good example from the framework itself is IDisposable. An object that implements the IDisposable interface guarantees that there's a Dispose() method you can call to cleanup unmanaged resources held by the object. Without an interface, the only other way of doing that would be to make all disposable objects subclassed from some DisposableObject base class, which given C#'s design of single-inheritance is quite an unworkable solution, or to use reflection to try to find a Dispose() method dynamically at runtime (slow, not strongly-typed so you'd have runtime errors instead of compiler errors).

Another good example from the framework itself is IComparable. By implementing it, you can add more rich comparison logic to any class you create, and that object will "just work" with things like Dictionaries, anything that does sorting, etc.

Interfaces are also useful in remoting server scenarios, where you want to publish a limited API, and have that API be completely detached from the actual code providing the implementation. Your remoting server offers up the interface instead of a specific class. You can even swap in a completely different implementation class behind the scenes on the server and the clients would have no idea.

biznatchio fucked around with this message at 03:39 on May 19, 2007

mcw
Jul 28, 2005
Hmm... I still must not be getting it because that just sounds like a security nightmare waiting to happen. Thanks very much for the explanation, though. As part of my efforts to learn C# I'm writing some small programs, and once I try using interfaces in them I should have a better understanding of what benefits they can offer.

csammis
Aug 26, 2003

Mental Institution

MariusMcG posted:

Hmm... I still must not be getting it because that just sounds like a security nightmare waiting to happen.

How does any of that sound like a security nightmare? Dropping a new implementation class behind the interface without the client's knowledge isn't as scary as it sounds; it's not something that can be done as a man-in-the-middle attack if that's what you're thinking.

mcw
Jul 28, 2005
It probably just sounds that way to me because C# embodies a different sort of programming paradigm than what I usually work with. From here on out I'll just refrain from commenting until I've actually used something in a program.

csammis
Aug 26, 2003

Mental Institution

MariusMcG posted:

It probably just sounds that way to me because C# embodies a different sort of programming paradigm than what I usually work with. From here on out I'll just refrain from commenting until I've actually used something in a program.

Oh no, comment away, just explain yourself so we can corroborate or deny it :)

Adbot
ADBOT LOVES YOU

biznatchio
Mar 31, 2001


Buglord

MariusMcG posted:

Hmm... I still must not be getting it because that just sounds like a security nightmare waiting to happen.

If you're referring to the remoting scenario, in situations where security is a concern you'd have the appropriate amount of security at a lower level in the networking infrastructure to prevent any sort of attacks (encryption, certificate exchange, etc.). But on the level that an attack like that would take place, there's no difference between remoting with an object or with an interface; both would be equally vulnerable to man-in-the-middle types of attacks because an attacker wouldn't be constrained by your object's existing base class implementation, they play outside those rules.

In an in-process situation, there are numerous security options you have to verify that even untrusted third-party plugins running behind an interface are safe. (Interfaces are quite useful in plugin models, since they describe the API and don't restrict the implementation in any way.) You have code signing, appdomain isolation, and CAS all at your beck and call to control untrusted code.

biznatchio fucked around with this message at 18:24 on May 19, 2007

  • Locked thread