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
Fastbreak
Jul 4, 2002
Don't worry, I had ten bucks.
The other thread (which is here) was getting really huge so thought we would sort it out by starting a new one.

Basically if you have any questions about the .Net framework, we ask it here.

And not to chop off people who were waiting for answers in the other thread, here were the last few questions:

hopelessStoner posted:

A quick question for the .NET goons:

I have a custom control that I use to display some data, it's super simple, basically two labels and a border around it, with a selected property that switches colors around and stuff. I dynamically populate a panel with them, and everything has worked just great for a couple of months. Now I have to expand the screen, so I put the whole thing into a tabcontrol, and everything went to poo poo. The little control I have suddenly grows in size after being added to the panel. This would be strange enough, since I don't define any growing behavior or anchoring, but it grows to approximately the width of the tabcontrol that its parent panel is housed in. What the hell is going on? In the debugger it literally looks like this:

Control created // everything is normal, sizes are fine
panel.controls.add(control); // after this all the sizes are hosed

I guess I can force the size back to default after the fact, but I want to understand what the hell is happening. This worked with zero issues until I put it inside the tabcontrol. Any clues guys?

Toiletbrush posted:

To the WinFX wizards: How much of a performance impact would I get for using ResourceDictionaries (to store strings in) and DynamicResource bindings to implement multilanguage interfaces?

Edit: Crap, the icon is off. I am an idiot. Mods, help a brother out?

EDIT:

Some books for learning:
C# 3.0 Unleashed: With the .NET Framework 3.5

ASP.NET 3.5 Unleashed

Learning C# 3.0

Fastbreak fucked around with this message at 19:50 on Oct 23, 2009

Adbot
ADBOT LOVES YOU

genki
Nov 12, 2003

hopelessStoner posted:

A quick question for the .NET goons:

I have a custom control that I use to display some data, it's super simple, basically two labels and a border around it, with a selected property that switches colors around and stuff. I dynamically populate a panel with them, and everything has worked just great for a couple of months. Now I have to expand the screen, so I put the whole thing into a tabcontrol, and everything went to poo poo. The little control I have suddenly grows in size after being added to the panel. This would be strange enough, since I don't define any growing behavior or anchoring, but it grows to approximately the width of the tabcontrol that its parent panel is housed in. What the hell is going on? In the debugger it literally looks like this:

Control created // everything is normal, sizes are fine
panel.controls.add(control); // after this all the sizes are hosed

I guess I can force the size back to default after the fact, but I want to understand what the hell is happening. This worked with zero issues until I put it inside the tabcontrol. Any clues guys?
You know what would probably work, as a quick workaround. Try adding your control to a blank panel, then add the panel to the tab.

I think that will solve the sizing issue. I would assume the tab expects the contained control to expand to fill the area within the tab, so it resizes your control when it gets added. If your control is already in a panel, only the panel should be affected.

I think.

Dromio
Oct 16, 2002
Sleeper
I'm playing with WF a bit, trying to get my bearings. I feel like it might be a good fit for my next project, if I can just seem to get a feel for how it all works.

So I created an ActivityLibrary project with a few custom activities-- they don't do anything, they're just placeholders. Then I added a sequential workflow project to the solution and referenced my ActivityLibrary. But the custom activities don't show up in the toolbox when I go to the workflow designer.

All the activities and the workflow share the same namespace. Am I missing something obvious?

csammis
Aug 26, 2003

Mental Institution
Fastbreak, you missed the post icon :( Also in the case of megathreads, with sufficient pointers to the new thread, closing the old one should be okay...I did it with the last few Programming Questions threads I created anyway v:shobon:v

Reposting my answer to Toiletbrush:

Toiletbrush posted:

To the WinFX wizards: How much of a performance impact would I get for using ResourceDictionaries (to store strings in) and DynamicResource bindings to implement multilanguage interfaces?

It's a higher impact than if you were using StaticResource bindings since WPF has to create what amounts to a DependencyObject wrapper for each resource being referenced dynamically to "listen" for changes. In reality, the only impact is in a minorly higher amount of memory being consumed (basically zero processor impact since it's all done with delegates), and when it comes to WPF who really gives a rats rear end, it's pretty much in the heavyweight division no matter what you do.

I use DynamicResource bindings for just about everything in shaim to provide online skinability, and the performance impact isn't noticable to the user at this point. I used WpfPerf to analyze the memory usage, and I couldn't differentiate between StaticResource and DynamicResource. The question you'll want to ask yourself is "do you want to provide support for changing languages on the fly?" If yes, use DynamicResource and don't worry about the impact. If no, use DynamicResource anyway because you may want to do it someday :v:

edit: this does of course depend on the number of strings you're talking about, but I'd still use DynamicResource first. If the performance is unacceptable, profile it and see what's going on. You may end up going with LocBaml, which I have no idea what that is but I've heard it referenced on the Avalon forum.

Victor
Jun 18, 2004
Mods: please fix the post icon.

In Part I, we discussed how the ASP.NET engine munges control IDs with runat="server" when they are nested inside another control, whether it be a datagrid, a content section of a master page, or a control in a user control. This causes problems for javascript and CSS that target tags based on IDs. To some extent, this can be solved by doing
code:
<%=lblWhatever.ClientID%> {font-weight: bold;}
and
code:
someInitFunction($(<%=btnWhatever.ClientID%>));
Is this the accepted way to do things? Unless it's safe to depend on a mangled ID, it would appear that styling elements with runat="server" based on ID in a separate CSS file isn't possible; is this true?

hopelessStoner
Sep 18, 2000

by Lowtax

genki posted:

You know what would probably work, as a quick workaround. Try adding your control to a blank panel, then add the panel to the tab.

I think that will solve the sizing issue. I would assume the tab expects the contained control to expand to fill the area within the tab, so it resizes your control when it gets added. If your control is already in a panel, only the panel should be affected.

I think.
That's basically how it is right now. I have a panel sitting in a tab, sharing the space with some buttons. Everything is just fine. Now when I add a control to a panel at run-time (via panel.Controls.Add) it screws with the sizes. I worked around that by simply reassigning the original size again after the add, but that's basically a hack, really. I want to know why it's happening.

Also, the control expands to a size that's bigger than the form it's parent's parent is on.

poopiehead
Oct 6, 2004

Victor posted:

Mods: please fix the post icon.

In Part I, we discussed how the ASP.NET engine munges control IDs with runat="server" when they are nested inside another control, whether it be a datagrid, a content section of a master page, or a control in a user control. This causes problems for javascript and CSS that target tags based on IDs. To some extent, this can be solved by doing
code:
<%=lblWhatever.ClientID%> {font-weight: bold;}
and
code:
someInitFunction($(<%=btnWhatever.ClientID%>));
Is this the accepted way to do things? Unless it's safe to depend on a mangled ID, it would appear that styling elements with runat="server" based on ID in a separate CSS file isn't possible; is this true?

I tend to just use a unique class name. It's ugly, but it works.

wwb
Aug 17, 2004

Victor posted:

Mods: please fix the post icon.

In Part I, we discussed how the ASP.NET engine munges control IDs with runat="server" when they are nested inside another control, whether it be a datagrid, a content section of a master page, or a control in a user control. This causes problems for javascript and CSS that target tags based on IDs. To some extent, this can be solved by doing
code:
<%=lblWhatever.ClientID%> {font-weight: bold;}
and
code:
someInitFunction($(<%=btnWhatever.ClientID%>));
Is this the accepted way to do things? Unless it's safe to depend on a mangled ID, it would appear that styling elements with runat="server" based on ID in a separate CSS file isn't possible; is this true?

I don't do much javascripting, but the someInitFunction technique is solid. Remember, you are pulling the client ID from the same place .NET is, so using the ClientID property is safe.

CSS stuff is a bit trickier. I usually wrap things in non-server ID'd containers and work off inheritance. Using classes is also a valid option.

Victor
Jun 18, 2004
The unique class name thing was mentioned before; it definitely is an option. This whole thing just strikes me as not being elegant, but then again, it sort of is required to guarantee ID uniqueness. I just want my code and HTML to be elegant, damnit.

poopiehead
Oct 6, 2004

Sorry this is going to be long:

I'm getting a weird error in an ASP .NET 2.0 page....

This only happens in IE7. Fine in firefox and IE6.

error posted:

Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

I have a repeater control with a bunch of child controls in the item template:
code:
<table class="layout">
<asp:Repeater ID="pagesDisplay" runat="Server" OnItemCreated="listing_ItemCreated">
  <ItemTemplate>
    <tr >
      <td class="bioListRow">
        <asp:Image ID="imgThumb" runat="server" style="float: left;" />
      </td>
      <td class="bioListRow">
        <strong><asp:Literal ID="lblName" runat="server" /></strong><br />
        <asp:Literal ID="lblTitle" runat="server" ><br /></asp:Literal>
        <asp:Literal ID="lblDescription" runat="server" ><br /></asp:Literal>
        <asp:LinkButton ID="btnMoreInfo" runat="server" 
                                OnClick="btnMoreInfo_Click">
                                  More Information
                                </asp:LinkButton>
      </td>
    </tr>
    <tr><td></td></tr>
    <asp:HiddenField ID="hdFacultyID" runat="server" />
  </ItemTemplate>  
</asp:Repeater>
</table>
And here is most of the codebehind. In the page_load, I databind the control. In the item_created event, I set up all the controls in the itemTemplate. In the button click, I just need to find out which one was clicked and redirect.
code:
    protected void Page_Load(object sender, EventArgs e)
    {
    Util.SetNavScript(this.Master, "mNav", "dist", "dist", null);

    BLL.FacultyTypeIdent pageType;
    bool isDefault = false;
    switch (Request["pageType"])
    {
      case "faculty":
        pageType = BLL.FacultyTypeIdent.Faculty;
        break;
      case "secondary":
        pageType = BLL.FacultyTypeIdent.SecondaryFaculty;
        break;
      case "visiting":
        pageType = BLL.FacultyTypeIdent.VisitingScholars;
        break;
      case "adjunct":
        pageType = BLL.FacultyTypeIdent.AdjunctProfessors;
        break;
      case "staff":
      case "researcher":
        pageType = BLL.FacultyTypeIdent.Staff;
        break;
      case "associate":
        pageType = BLL.FacultyTypeIdent.FacultyAssociates;
        break;
      default:
        pageType = BLL.FacultyTypeIdent.Faculty;
        isDefault = true;
        break;
    }

    using (DAL.DataConnector conn = new DAL.DataConnector())
    {
      BLL.FacultyType facType = 
        new BLL.FacultyType(conn, pageType);
      this.lblTitle.Text = facType.DisplayName;

      BLL.FacultyCollection fac =  
        BLL.Faculty.FetchVisibleRowsByFacultyType(conn,pageType);
      pagesDisplay.DataSource = fac;
      pagesDisplay.DataBind();

      this.pnlMainPage.Visible = false;
      if (isDefault)
      {
        this.pnlMainPage.Visible = true;
        this.visitingDisplay.DataSource = 
          BLL.Faculty.FetchVisibleRowsByFacultyType(conn, 
            BLL.FacultyTypeIdent.VisitingScholars);
        this.visitingDisplay.DataBind();
      }
    }
    }

  protected void listing_ItemCreated(object sender, RepeaterItemEventArgs e)
  {
    Control cont = (Control)e.Item;
    Literal name = (Literal)cont.FindControl("lblName");
    Literal description = (Literal)cont.FindControl("lblDescription");
    Literal title = (Literal)cont.FindControl("lblTitle");
    Image thumb = (Image)cont.FindControl("imgThumb");
    HiddenField facultyID = (HiddenField)cont.FindControl("hdFacultyID");

    BLL.Faculty fac = (BLL.Faculty)e.Item.DataItem;
    if (fac != null)
    {

      name.Text = fac.Name;

      string shortDesc = fac.ShortDesc;
      if (shortDesc != null && shortDesc.Length > 0)
      {
        System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(
          "</?([^>]*)>",
          System.Text.RegularExpressions.RegexOptions.IgnoreCase |
            System.Text.RegularExpressions.RegexOptions.Multiline);
        shortDesc = regex.Replace(shortDesc, " ");

        int oldShortDescLength = shortDesc.Length;

        shortDesc = shortDesc.Substring(0, Math.Min(400, shortDesc.Length));
        if (oldShortDescLength > 400)
        {
          shortDesc += "...";
        }
        description.Text = shortDesc + description.Text;
      }
      else
      {
        description.Visible = false;
      }

      if (fac.Title != null && fac.Title.Length > 0)
      {
        title.Text = fac.Title + title.Text;
      }
      else
      {
        title.Visible = false;
      }      


      facultyID.Value = fac.ID.ToString();



      bool thumbExists = false;
      thumb.Visible = false;
      if (fac.Thumbnail != null)
      {
        string filepath = thumbnailLocation + fac.Thumbnail;
        if (System.IO.File.Exists(Server.MapPath(filepath)))
        {
          thumb.ImageUrl = resizerPrefix + filepath;
          thumb.Visible = true;
          thumbExists = true;
        }
      }

      if (!thumbExists && fac.Image != null)
      {
        string filepath = imageLocation + fac.Image;
        if (System.IO.File.Exists(Server.MapPath(filepath)))
        {
            thumb.ImageUrl = resizerPrefix + filepath;
            thumb.Visible = true;
        }
      }
    }
    
  }

  protected void btnMoreInfo_Click(object sender, EventArgs e)
  {
    HiddenField hf = (HiddenField)((Control)sender).Parent.FindControl("hdFacultyID");
    int id = int.Parse(hf.Value);
    Response.Redirect("FacultyBio.aspx?id=" + id, true);
  }
After doing some reading on the error, it seems that the problem is that I'm re-databinding the control and ASP .NET doesn't like that. So if I put the databinding part inside of an if(!IsPostback), the error does go away, but then when I get to the click event, the HiddenField has no value.

I was able to avoid the problem by getting rid of the useless postback that shouldn't have been there in the first place and just making it a link.
code:
<a href="FacultyBio.aspx?id=<%# DataBinder.Eval(Container.DataItem,"ID") %>">More Information</a>
But does anyone understand what problem I was actually running into? I can't seem to figure out what I was doing wrong or how to fix it other than to disable validation.

Combat Pretzel
Jun 23, 2004

No, seriously... what kurds?!

csammis posted:

FThe question you'll want to ask yourself is "do you want to provide support for changing languages on the fly?" If yes, use DynamicResource and don't worry about the impact. If no, use DynamicResource anyway because you may want to do it someday :v:
Live theme switching, man :)

As far as on-the-fly language switching, on one hand, this seems a defacto standard with a lot of freeware applications, on the other hand, you switch it only once. I have to ask the magic eight ball...

quote:

edit: this does of course depend on the number of strings you're talking about, but I'd still use DynamicResource first. If the performance is unacceptable, profile it and see what's going on. You may end up going with LocBaml, which I have no idea what that is but I've heard it referenced on the Avalon forum.
Since hashtables are used to store the RD entries, it shouldn't be affected much with the amount of entries.

csammis
Aug 26, 2003

Mental Institution

Toiletbrush posted:

Live theme switching, man :)

As far as on-the-fly language switching, on one hand, this seems a defacto standard with a lot of freeware applications, on the other hand, you switch it only once. I have to ask the magic eight ball...

Mine says "I SAY YES," then I asked it if it was sure and it said "NO" :v:

quote:

Since hashtables are used to store the RD entries, it shouldn't be affected much with the amount of entries.

I wasn't talking about the amount of data in the RD, I meant the number of strings that are inserted into the application via DynamicResources. It's the DR count you'd want to be concerned with if it even turned out to be a problem, which as I said I doubt.

Wizzle
Jun 7, 2004

Most
Parochial
Poster


OK, I have 2 (hopefully) simple questions.

1. I've had to write a custom control for a form. (C#) I wrote it with System.Drawing objects. Basically, it's a graph. I can't seem to make it draw when the form loads. I've made the draw function it's own function overloaded to be an event handler or take no arguments. I've had the function call from the contructor and I've gone so far as to make the function public so that the underlying form which calls this form can call the drawing function.

The only way I can make it draw is to bind it to a bunch of other events like Move, then move the window and it works fine. Any ideas?

2. How do I run an application from a remote share? I keep getting security exceptions.

superb0wr
Jun 2, 2004

funky
Anybody know what those [SquareBracket] directives or whatever you can use in c# are called, and if its possible to write custom ones? Like [STAThread] or [WebMethod]?

poopiehead
Oct 6, 2004

superb0wr posted:

Anybody know what those [SquareBracket] directives or whatever you can use in c# are called, and if its possible to write custom ones? Like [STAThread] or [WebMethod]?

They're called Attributes and they're accessible through Reflection.

I've never used them before, but this looks like a good explanation:

Wizzle
Jun 7, 2004

Most
Parochial
Poster


superb0wr posted:

Anybody know what those [SquareBracket] directives or whatever you can use in c# are called, and if its possible to write custom ones? Like [STAThread] or [WebMethod]?

I had to use them to import a non .NET Dll file. They show up in ASP.NET a lot too.

superb0wr
Jun 2, 2004

funky

poopiehead posted:

They're called Attributes and they're accessible through Reflection.

I've never used them before, but this looks like a good explanation:

Badass, thanks a lot

DLCinferno
Feb 22, 2003

Happy
I'm trying to quickly read through many TIF files and determine if each pixel is either white or something else. After some searching, I've found information on using LockBits but I don't know how to implement it. I think I'm on the right track:

code:
foreach (string file in Directory.GetFiles(path, "*.tif"))
{
    Bitmap image =  new Bitmap(file);
    BitmapData data = image.LockBits( new Rectangle( 0 , 0 , image.Width ,
          image.Height ) , ImageLockMode.ReadOnly  , PixelFormat.Format24bppRgb  );
    if(DetectColor(data))
    {
        //Do stuff
    }
}

private bool DetectColor(BitmapData data)
{
    unsafe
    {
        byte* imgPtr = (byte*)(data.Scan0);
        for (int i = 0; i < data.Height; i++)
        {
            for (int j = 0; j < data.Width; j++)
            {     
                [b]// what goes here to return TRUE if the pixel is not white?[/b]
                imgPtr += 3;
            }
            imgPtr += data.Stride - data.Width * 3;
        }
    }
    return false;
}

DLCinferno
Feb 22, 2003

Happy

DLCinferno posted:

I'm trying to quickly read through many TIF files and determine if each pixel is either white or something else. After some searching, I've found information on using LockBits but I don't know how to implement it. I think I'm on the right track:
Bah! Nevermind, I think I worked it out. Here is what I put in "what goes here":

code:
if((((byte*)((int)data.Scan0 + (int)i * data.Stride) + (int)(j))[0]) != 255)
     {
         return true;
     }

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
When I check a NetworkStream's DataAvailable property, I get false, yet I can do a Read() and get bytes (in this case, the expected messages from a POP3 server). What's up with that?

Walrus791
Sep 4, 2002

Ugly, greasy retard.
I've been writing a small DB-driven app to get learning .NET in general. The language I've been using is C# and I've been hearded into using this ADO.NET thing. The C# and the .NET in general I like, but its ADO.NET that I am skeptical about.

How practical is this disconnected data source? Is it really a good idea to download at first go everything that your application may need from the database? Is this something that could differ from app to app? It seems like my program would be better off just running queries when it needs something, but that could just be me trying to resist a different way.

Is there some good guidelines on when and what to throw in your DataSet's? Help!!

Heffer
May 1, 2003

Okay heres a question that there's pretty much a zero chance of getting answered, since it seems even microsoft itself is lovely about documenting it.

I'm writing a program to access an Exchange public folder. Since the domain admins have the exchange server locked up pretty tight, I'm opting to make use of the internal webmail server running OWA. What's awesome about this is that is has full WebDAV support, meaning I can get lots of XML formatted information about the document. Whats bad about this is that it has full WebDAV support with very very minimal documentation from microsoft.

How WebDAV works is essentially you do an operation other than POST or GET over HTTP, like PROPFIND and SEARCH, and as the body of the request you pass an XML formatted document. In return you get an XML formatted document with the requested data. So in .NET I need no API's other than HttpWebRequest and HttpWebResponse.

The problem I'm running into now is that I'm doing a SEARCH operation on three web folders, neccesitating three different WebRequests to be made. Except Every Other WebRequest fails with a "The remote server returned an error: (400) Bad Request." exception.

So basically my outpot is this:
code:
Checking folder A...
A has 74 new emails
Checking folder B...
The remote server returned an error: (400) Bad Request.
Checking folder C...
C has 16 new emails
But if I double up on the requests I make, it goes like this
code:
Checking folder A...
A has 74 new emails
Checking folder B...
The remote server returned an error: (400) Bad Request.
Checking folder B...
B has 77 new emails
Checking folder C...
The remote server returned an error: (400) Bad Request.
Checking folder C...
C has 16 new emails
My best guess is I have somehow gummed up either the server's connection, or my local port through the HttpWebRequest or HttpWebResponse. Other than that, no clue.

It's really obscure, but does anybody have any ideas?

csammis
Aug 26, 2003

Mental Institution

Mustach posted:

When I check a NetworkStream's DataAvailable property, I get false, yet I can do a Read() and get bytes (in this case, the expected messages from a POP3 server). What's up with that?


The DataAvailable property looks at the base socket's Available property, which uses native ioctl methods to determine how many bytes of data are available for reading. I don't know why it isn't working, but ioctl mixed with .NET may just be a receipe for problems. Just use BeginRead() on the socket, that way you won't be bothered until/unless there's data. If the socket disconnects, you'll get an exception in the callback method from EndRead().

Victor
Jun 18, 2004
Heffer, one idea would be to install the trial version of WebDAV for Exchange 1.1 and then look at the messages it's sending and receiving. My shop actually bought it because I didn't want to figure out WebDAV, but perhaps you could use it for some reverse engineering?

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

csammis posted:

The DataAvailable property looks at the base socket's Available property, which uses native ioctl methods to determine how many bytes of data are available for reading. I don't know why it isn't working, but ioctl mixed with .NET may just be a receipe for problems. Just use BeginRead() on the socket, that way you won't be bothered until/unless there's data. If the socket disconnects, you'll get an exception in the callback method from EndRead().
Okay, thanks! I did some more messing around with it, and found that if you Read() once, it'll return an accurate value from then on.

Heffer
May 1, 2003

Victor posted:

Heffer, one idea would be to install the trial version of WebDAV for Exchange 1.1 and then look at the messages it's sending and receiving. My shop actually bought it because I didn't want to figure out WebDAV, but perhaps you could use it for some reverse engineering?

Of course moments after I give up and post for help on the Internet, I figure it out.

I had:
RequestStream.Close();
Request.ContentType = "text/xml";

which I guess was bad because I was sending out header information after the body of the request had been sent. Moving the Content Type setting to above the writing of the body gave me the behavior I wanted, although I still don't know why it would fault a completely different request made in a completely different function.

Figuring WebDAV out only took me about a day, but probably because I have a lot of familiarity with low level HTTP operations already. What really confuses me is communication with Exchange, because they use really weird data schema's and SQL variants.

For instance if you do: "SELECT * FROM "server/public/foldername" it doesn't actually give you all the information. It only gives you all properties for the DAV XML namespace. To get something like the body, you have to specifically specify it like "SELECT "urn:schemas:httpmail:textdescription" FROM "server/public/foldername". That took me about 4 hours to figure out.

Also, if you want to get mails from within a specific range you would like to do " WHERE "DAV:creationdate" > '" + dtYesterday + "'" . Except a) you have to cast the date inside the sql statement to 'dateTime' (make sure to capitalize the T or else it doesnt work) and b) you have to be casting it from UTC formatted Zulu time, so be sure to shift for timezone, and c) less-thans and greater-thans mess up the HTML request, so you have to use &lt; and &gt;

ALSO, there is no specific count function, so you use a property called DAV:visiblecount instead. However, that only works when you use GROUP BY statements, even if you really only want one single number.

All this gives you a SQL statement that looks like this:
code:
SELECT  "DAV:visiblecount" , "urn:schemas:httpmail:to" FROM "server/public/folder/" 
WHERE "DAV:creationdate" &gt; CAST(" + aDate.ToString("s") + "Z" as 'dateTime')
AND \"DAV:creationdate\" &lt; CAST(" + aDate.AddHours(24.0).ToString("s") + "Z" as 'dateTime')"
AND \"urn:schemas:httpmail:subject\"  LIKE 'Thank You%'"
GROUP BY \"urn:schemas:httpmail:to\""

Dromio
Oct 16, 2002
Sleeper
Still hoping someone has experience with WF and can help with my previous issue, but now I've got something else!

I'me using System.Runtime.Serialization to save a class to a file, then load it up later. But it appears that using this serialization does not call the class constructor! This leaves some crucial properties as null. For example:

code:
public class Document{
  [NonSerialized]
  //This could be different on someone else's computer, don't save it.
  private string _TempLocation;

  //This does NOT get called during deserialization.
  public Document()
  {
    //I need a place to keep my stuff!
    _TempLocation = System.IO.Path.GetTempPath + System.Guid.NewGuid().ToString() +"\\";
  }

  public DoSomethingWithFiles()
  {
    //When try to save something to _TempLocation with a deserialized instance, it's null!
  }
}
This also occurs if I set _TempLocation during the declaration. Has anyone encountered this? Any suggested workarounds?

genki
Nov 12, 2003

Dromio posted:

Still hoping someone has experience with WF and can help with my previous issue, but now I've got something else!

I'me using System.Runtime.Serialization to save a class to a file, then load it up later. But it appears that using this serialization does not call the class constructor! This leaves some crucial properties as null. For example:

code:
public class Document{
  [NonSerialized]
  //This could be different on someone else's computer, don't save it.
  private string _TempLocation;

  //This does NOT get called during deserialization.
  public Document()
  {
    //I need a place to keep my stuff!
    _TempLocation = System.IO.Path.GetTempPath + System.Guid.NewGuid().ToString() +"\\";
  }

  public DoSomethingWithFiles()
  {
    //When try to save something to _TempLocation with a deserialized instance, it's null!
  }
}
This also occurs if I set _TempLocation during the declaration. Has anyone encountered this? Any suggested workarounds?
Lazy instantiation?

code:
public class Document{
  [NonSerialized]
  //This could be different on someone else's computer, don't save it.
  private string _TempLocation;

  //This does NOT get called during deserialization.
  public Document()
  {
  }

  private void SetTempLocation()
  {
    _TempLocation = System.IO.Path.GetTempPath + System.Guid.NewGuid().ToString() +"\\";
  }

  public DoSomethingWithFiles()
  {
    if (_TempLocation == "")
    {
      SetTempLocation();
    }
    // do stuff
  }
}
There's probably a more standard way to check if the temp location has been set. I'm not sure what it would be. null? EmptyString()?

csammis
Aug 26, 2003

Mental Institution

genki posted:

There's probably a more standard way to check if the temp location has been set. I'm not sure what it would be. null? EmptyString()?


String.IsNullOrEmpty() :eng101:

Fiend
Dec 2, 2001

Victor posted:

Mods: please fix the post icon.

In Part I, we discussed how the ASP.NET engine munges control IDs with runat="server" when they are nested inside another control, whether it be a datagrid, a content section of a master page, or a control in a user control. This causes problems for javascript and CSS that target tags based on IDs. To some extent, this can be solved by doing
code:
[b]#[/b]<%=lblWhatever.ClientID%> {font-weight: bold;}
and
code:
someInitFunction($(<%=btnWhatever.ClientID%>));
Don't forget to prefix that style with a '#' to let the parser know it's referencing the object ID and not an HTML element :)
code:
// The <BODY> element
body {[i]...style...[/i]}
// A class named "body"
.body {[i]...style...[/i]}
// an element with the ID "body"
#body {[i]...style...[/i]}
It's also important to understand the "why" as well as the "what". ASP.NET generates the client ID for ALL server-side controls based on the control's hierarchy within the application. So any client-side script that needs to reference a control by ID will need to use the ASP.NET generated ID instead of the server-side ID.

Victor posted:

Is this the accepted way to do things? Unless it's safe to depend on a mangled ID, it would appear that styling elements with runat="server" based on ID in a separate CSS file isn't possible; is this true?

It would be possible if you create an aspx page that has a response.contenttype of "text/css" and the output is in CSS format, AND if that aspx page can reference the control. But it was said earlier that you're probably better off using classes.

Victor
Jun 18, 2004

Fiend posted:

It would be possible if you create an aspx page that has a response.contenttype of "text/css" and the output is in CSS format, AND if that aspx page can reference the control. But it was said earlier that you're probably better off using classes.
First, thanks for noticing the lack of a '#'; I do know enough about CSS to know why it's required. ;P

I was under the impression that ASPX pages cannot reference each due to the 2.0 website compilation model, but perhaps web application projects allow one to revert to 1.x abilities in that respect. One thing I don't like about your approach is that the styled controls need to be made internal, but I guess that's unavoidable without C++ -style friends.

Fiend
Dec 2, 2001

Victor posted:

First, thanks for noticing the lack of a '#'; I do know enough about CSS to know why it's required. ;P

I was under the impression that ASPX pages cannot reference each due to the 2.0 website compilation model, but perhaps web application projects allow one to revert to 1.x abilities in that respect. One thing I don't like about your approach is that the styled controls need to be made internal, but I guess that's unavoidable without C++ -style friends.
I think it's less "project type" and more "security modifiers + property accessors" that you'd wanna use to make this happen.

code:
// asp code
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="sample.ascx.cs" Inherits="sample" %>
<asp:Label ID="lblWhat" runat="server" Text="o rly?" />
// code behind
public class _HURRRRRRRR : System.Web.UI.UserControl
{
    protected System.Web.UI.WebControl.Label lblWhat;
    public string ControlClientID
    {
        get 
        {
            return lblWhat.ClientID;
        }
    }
    public string LabelText
    {
        get
        {
            return lblWhat.Text;
        }
        set
        {
            lblWhat.Text = value;
        }
    }
}
// asp code
<%@ Register TagPrefix="uc1" TagName="sample" Src="sample.ascx" %>
<uc1:sample ID="usrControl" runat="server" />
// code behind
public class Page : System.Web.UI.Page
{
    protected Page_Load(object gently caress, EventArgs zomg)
    {
        // return the client ID for lblWhat in the _HURRRRRRRR user control
        Response.Write(usrControl.ControlClientID);
        if(!Page.IsPostBack)
        {
            usrControl.LabelText = "o rly";
        }
        else
        {
            usrControl.LabelText = "no wai";
        }
    }
}
I'm not sure what you mean in regards to the differences in the compilation models.

genki
Nov 12, 2003

csammis posted:

String.IsNullOrEmpty() :eng101:
Haha, I knew there was something. Thanks! :D

Dromio
Oct 16, 2002
Sleeper

genki posted:

Lazy instantiation?

I ended up doing this, but it makes me sad.

I'm amazed that the deserialier can create the objects without using constructors. I guess it makes sense, since it's the only one I've seen that doesn't require that there be a parameterless constructor on the class.

poopiehead
Oct 6, 2004

csammis posted:

String.IsNullOrEmpty() :eng101:

Isn't there some kind of bug associated with that function? It seems so convenient but I've been nervous to use it since I heard it doesn't always work.

Victor
Jun 18, 2004

poopiehead posted:

Isn't there some kind of bug associated with that function? It seems so convenient but I've been nervous to use it since I heard it doesn't always work.
The bug has to do with JITing code in loops; it isn't a problem with String.IsNullOrEmpty itself. If you don't use the method in loops, you're golden, otherwise you might want to look up the bug details.

poopiehead
Oct 6, 2004

Victor posted:

The bug has to do with JITing code in loops; it isn't a problem with String.IsNullOrEmpty itself. If you don't use the method in loops, you're golden, otherwise you might want to look up the bug details.

Thanks. good to know. I'll have to look up the details.

Victor
Jun 18, 2004
I got unlazy and found the JIT bug involving String.IsNullOrEmpty.

Altec
May 13, 2004

In college, I took a few courses that focused on ASP (about 4 years ago). I am not a programmer by trade, nor is coding really part of my job, but I have extra time at work now, so I figure I'll learn a new skill. I have MS SharePoint 07 at work, and am most familiar with VB.

So, what's a good book for teaching yourself ASP.NET? Thanks!

Adbot
ADBOT LOVES YOU

Tinyn
Jan 10, 2003

Wizzle posted:

OK, I have 2 (hopefully) simple questions.

1. I've had to write a custom control for a form. (C#) I wrote it with System.Drawing objects. Basically, it's a graph. I can't seem to make it draw when the form loads. I've made the draw function it's own function overloaded to be an event handler or take no arguments. I've had the function call from the contructor and I've gone so far as to make the function public so that the underlying form which calls this form can call the drawing function.

The only way I can make it draw is to bind it to a bunch of other events like Move, then move the window and it works fine. Any ideas?

The Control class, which your graph control should inherit from (actually from UserControl probably). When the base class gets important events from above, they call a number of OnWhatever() functions, which belong to the base class. The OnWhatever functions are intended to be overridden by your child class. So just make a OnPaint() function, and do your drawing code in that. OnPaint will then get called whenever the base class thinks its time to redraw.

  • Locked thread