Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
R

Rick van Woudenberg

@Rick van Woudenberg
About
Posts
107
Topics
38
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Method not firing
    R Rick van Woudenberg

    Dear all, I use the code below for firing a method, however .. it's not firing. I use the same piece of code (different class though) a little further in my application and it's working fine.

    protected void Page_Load(object sender, EventArgs e)
    {
    Control ce = LoadControl("TimeEntry.ascx");
    pnlProjects.Controls.Add(ce);

            foreach(Control ctl in pnlProjects.Controls)
                if (ctl.GetType() == typeof(TimeEntry))
                {
                    TimeEntry te = (TimeEntry)ctl;
                    te.LoadControls();
                }
        }
    

    I don't want to put

    LoadControls();

    in my Page_Load of TimeEntry.ascx because it's posting back when I navigate away from the page and thus firing the method again. Can any tell me what I am doing wrong. Kind regards,

    ASP.NET

  • Problems with Site.Master
    R Rick van Woudenberg

    Richard, Thank you for your reply. Response.Redirect fixed the problem. And also many thanks to GenJerDan for explaining to me what caused the issue in the first place. Kind regards,

    ASP.NET csharp html asp-net database postgresql

  • Problems with Site.Master
    R Rick van Woudenberg

    Dear All, I'm pretty good with C# however I can't figure out ASP.NET with C#. It's not the C# bit that gives me headaches but the ASP stuff. I have the following problem. I've created an ASP website ( not entirely true, I used one of VS2010 templates ) and it's has login functionality. I'm using a Postgresql database in the backend and I can login fine. My Site.Master page got buttons in it, but I want a whole new series of buttons when the user has logged on correctly. I've created a new .aspx site that needs to load with a new Master Page. So I've created a new master page, called Site1.Master. It's pretty much the same as Site.Master but it allows me to use different buttons. But for some reason the login information is not display when this new page is loaded. Only after I hit 'F5' on my keyboard ( refresh ) it will show the info and the page works properly. Site.Master :

    <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="Urenboeken.SiteMaster" %>

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head runat="server">
    <title></title>

    </head>
    <body>
    <form runat="server">

                    KMO Urenboeken
    

    ====================================================

                \[ [Log In](~/Account/Login.aspx) \]
                    
                    Welcome !
                        \[ \]
    
    ASP.NET csharp html asp-net database postgresql

  • a try inside another
    R Rick van Woudenberg

    I totally agree with you, and I would never show an exception to a user. Hence the

    // or show something else..

    , but I still think that you should at least say something when anything important messes up, like .. euhh .. a database connection that fails ? I don't think it's wise to redirect general user messages that could be caused by an exception to the windows logs. Not very user friendly.

    C# help

  • a try inside another
    R Rick van Woudenberg

    Well, as far as I'm concerned both would be nice. Sure, the connection to the database has priority over user notification, however when something stuffs up, I generally let the user know. In that particular case I would do something like :

    private void DoSomething()
    {
    SqlConnection connection = null;
    try
    {
    connection = new SqlConnection();
    // Do something that might cause an exception...
    connection.Open();
    }
    catch(SqlException ex)
    {
    MessageBox.Show(ex.ToString(); // or something else to notify the customer
    }
    finally
    {
    if (connection.ConnectionState == ConnectionState.Open)
    connection.Close();
    }
    }

    Then you actually have both of two worlds. However, that puts us right back to the essence of this discussion. Having a catch clause in a method is not something to be ashamed of, though I get the feeling that many developers think that way.

    C# help

  • About SplitContainer Resize
    R Rick van Woudenberg

    I'm slightly confused about the way the problem is explained and presented. I get the first bit : You have two splitcontainers, each horizontally orientated and you've put Split2 in Panel 1 of Split1. The second bit is what confuses me. Could you please refraise that sentence for me. I'm not sure what you're trying to achieve.

    C# tutorial question

  • a try inside another
    R Rick van Woudenberg

    Pete, Good point. I guess you're sample is way better than I used to do it. ( see code below ). Other than the obvious thread freezing and just the fact that handling exceptions are 'expensive'.

    private void DoSomething()
    {
    SqlConnection connection = null;
    try
    {
    connection = new SqlConnection();
    // Do something that might cause an exception...
    connection.Open();
    }
    catch
    {
    MessageBox.Show("Connecting to the database failed..");
    }

    if (connection.ConnectionState == ConnectionState.Open)
    connection.Close();
    }

    C# help

  • a try inside another
    R Rick van Woudenberg

    Well, if you don't use an inner catch, every exception in both the inner and outer try block, will be caught by the outer catch block.

    C# help

  • a try inside another
    R Rick van Woudenberg

    .. euhmm .. debatable I guess. Technically speaking you're right, I agree. But what's the use of a try block without a catch block. The try block contains the guarded code that may cause the exception. The block is executed until an exception is thrown or it is completed successfully. The catch clause can be used without arguments, in which case it catches any type of exception, and referred to as the general catch clause. It can also take an object argument derived from System.Exception, in which case it handles a specific exception. So, keeping all that in mind, I'm hard to convince why you'd want two or more try clauses with just one catch clause, as each try block is examined in order of importance and thus handled by the same catch clause. .. or have I completely lost my mind again.

    C# help

  • default value in combobox
    R Rick van Woudenberg

    When you're application loads, or when the combobox is filled, use this :

    comboBox.SelectedIndex = 0; // ( or 1,2,3 .. depending on the item you'd like to show first )

    C# question csharp

  • a try inside another
    R Rick van Woudenberg

    Guy ( or girl .. dunno ) A try is always followed by a catch section, hence the name try.catch block. The sample you provided is legal, however I would add an additional catch block in case anything goes wrong in the second try section.

    try
    {
        try
        {
            ...
        }
        catch
        {
            //Do Something to alert the user
        }
        finally
        {
            ...
        }
    }
    catch
    {
        throw;
    }
    
    C# help

  • multiple socket connection
    R Rick van Woudenberg

    Multithreading will do the trick. Just open a each TcpListener or Socket(udp) connection in a seperate thread.

    C# tutorial csharp sysadmin help

  • how to update progressbar in Child Form from Parent Form
    R Rick van Woudenberg

    Parent Form :

    public ProgressBar pb;

    private void openChild_Click(object sender, System.EventArgs e)
    {
    ChildForm cf = new ChildForm();
    cf.pf = this;
    cf.open();
    }

    Child Form :

    public ParentForm pf;

    private void runProgressBar_Click(object sender, System.EventArgs e)
    {
    for(int i = 0;i<100;i++)
    {
    pf.pb.Value++;
    }
    }

    C# tutorial announcement

  • need some quick help thx : how can i access and open form2 from form1 menu item
    R Rick van Woudenberg

    Double click on the menu button in your designer. This will create an EventHandler. Inside the EventHandler, put the following code :

    private void OpenFix_Click(object sender, System.EventArgs e)
    {
    Form2 fix = new Form2();
    fix.Open();
    }

    C# help design question

  • Theading problem
    R Rick van Woudenberg

    Dear all, Could anyone please help me with the following problem. I have a MainForm in my application. I call a background worker thread to do some work. This thread never finishes, so it will always run in the background and will be closed when the application closes. This works perfect. Then I open a new form from my main thread and in that form I call another backgroundworker. As long as backgroundworker 2 is running, backgroundworker 1 becomes unresponsive. The MainForm stays responsive, the newly opened form stays responsive, but the two backgroundworkers don't seem to like each other and seems to be competing over resources. * MainForm - backgroundworker 1 * subForm - backgroundworker 2 When backgroundworker 2 is running, backgroundworker 1 becomes unresponsive until backgroundworker 2 is finished. Weird huh ? Kind regards,

    C# help mobile question

  • More elegant way then .Split(']');
    R Rick van Woudenberg

    Dear All, I have ListView full of things, but basically all the items have the same format : TY223 [16] TW121 [223] ... ... If I want to substract the value 16 and TY223 from TY223 [16] , I go about it like this :

                string\[\] a = itm.Value.ToString().Split('\[');
                string\[\] b = a\[1\].ToString().Split('\]');
    
                string first = a\[1\].ToString().Trim();
                string second = b\[0\].ToString().Trim();
    

    This works fine, however I'm only after the value 16. Is there a more elegant way of extracting this value from the item, instead of using

    .Split()

    Kind regards,

    C#

  • CultureInfo and DateTime settings
    R Rick van Woudenberg

    Thank you all for your reply :)

    DateTime lastTime = DateTime.ParseExact(dt.Rows[lastRow]["date"].ToString(),"dd-MM-yyyy HH:mm:ss", CultureInfo.InvariantCulture);

    did the trick :) Once again, thank you kind regards,

    C# help tutorial question

  • CultureInfo and DateTime settings
    R Rick van Woudenberg

    Thank you for your feedback, it does indeed fix half of my problem. I can get the date right in the logfile, however .. it will not fix the below calculation :

    DateTime lastTime = Convert.ToDateTime(dt.Rows[lastRow]["date"].ToString());

    Where the value in the DataTable is "19-01-2009 13:45:59", the error is :

    1/19/2009 4:34:24 PM System.FormatException: String was not recognized as a valid DateTime.
    at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
    at System.DateTime.Parse(String s, IFormatProvider provider)
    at System.Convert.ToDateTime(String value)
    at Loudnixx_RealTime.RealTimeRadar.ExceedTrackTime()
    at Loudnixx_RealTime.RealTimeRadar.ProcessString(String dat)
    at Loudnixx_RealTime.RealTimeRadar.Listen()

    Somehow there has to be a way to set it globally throughout the program. Can you point me in the right direction ? kind regards,

    C# help tutorial question

  • CultureInfo and DateTime settings
    R Rick van Woudenberg

    Gents, I have the following problem that drives me insane. I've written a service that runs in the background. However, I can't get the DateTime format right. I must have tried everything to get it right, but to no avail. When the service starts or stops, it will tell me by writing to a log file. The output of the log file looks like this : 1/19/2009 1:48:40 PM Manager: Service Stopped 1/19/2009 1:48:43 PM Manager: Service Started 1/19/2009 2:17:05 PM Manager: Service Stopped 1/19/2009 2:17:29 PM Manager: Service Started 1/19/2009 2:18:02 PM Manager: Service Stopped 1/19/2009 2:20:27 PM Manager: Service Started Now .. When it writes to the logfile, it uses the above format for DateTime.Now , while I want to use "dd-mm-yyyy HH:mm:ss" I set the regional setting in Control Panel as well as the Date and Time format. It shows up perfect in my system clock. It still spits out the above to the logfile. Then I tried the following in my code, so set it programmatically :

        // The main entry point for the process 
        static void Main()
        {
            //Set the culture
            CultureInfo newCulture = new CultureInfo("en-US", false);
            newCulture.DateTimeFormat.FullDateTimePattern = "dd-mm-yyyy HH:mm:ss";
            System.Threading.Thread.CurrentThread.CurrentCulture = newCulture; 
    
            System.ServiceProcess.ServiceBase\[\] ServicesToRun;
            // More than one user Service may run within the same process. To add 
            // another service to this process, change the following line to 
            // create a second service object. For example, 
            // 
            // ServicesToRun = New System.ServiceProcess.ServiceBase\[\] {new WinService1(), new ySecondUserService()}; 
            // 
            ServicesToRun = new System.ServiceProcess.ServiceBase\[\] { new RealTime() };
            System.ServiceProcess.ServiceBase.Run(ServicesToRun);
        }
    

    That didn't fix it .. still the same output. When I put a MessageBox in between somewhere to let me show DateTime.Now.ToString(), it also comes back with 1/19/2009 2:20:27 PM. Some of the methods in the service report an invalid <code>DateTime</code> conversion when I try the following code :

    DateTime time = Convert.ToDateTime("19-01-2009 13:12:56");

    It drives me insane. Can please someone point me in the right direction ? Kind regards,

    C# help tutorial question

  • Socket Connections
    R Rick van Woudenberg

    Dear all, I'm trying to get my computer to listen on a port and pass on the received data ( after some modification ) over Multicast. I'm receiving data on the socket every second. I wrote the code below and it works perfect. The problem that I require some assistance with is pretty simply. Everytime a string of data is received, the socket is closed and new socket is opened to wait for the next string. When the next string of data comes in, it gets processed and the socket is closed again. This means that after a period of time, lots of socket connections are made. One of them is active and the others are in a TIME_WAIT state ( and that list keeps growing ) Is there a way around this ?

    Int32 port = 31008;

                IPAddress localAddr = IPAddress.Any;
                server = new TcpListener(localAddr, port);
                server.Start();
    
                // Buffer for reading data
                Byte\[\] bytes = new Byte\[256\];
                String data = null;
    
                while (true)
                {
                    client = server.AcceptTcpClient();
                    data = null;
                    NetworkStream stream = client.GetStream();
    
                    int i;
    
                    while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                    {
                        data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
                        data = data.ToUpper();
                        byte\[\] msg = System.Text.Encoding.ASCII.GetBytes(data);
                        
                        SendMulticast(MultiCastIP, MultiCastPort, msg);
                    }
                    client.Close();
                }
    

    kind regards, Rick

    C# sysadmin help question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups