Archive

Archive for the ‘Uncategorized’ Category

Validation against Controls outside of the current NamingContainer

June 25th, 2017 Michael Bell 1 comment

I had a situation where I needed to do this recently. I googled of course, and came up with an overloaded FindControl method. I implemented this in my code, and all seemed well. UNTIL… came the time to get the data posted from my control. I had controls nested in a UserControl, and that usercontrol nested within a FormView. When the postback occurred, I was able to retrieve all values from controls directly in the formview but none from within the controls inside my usercontrol. A buddy of mine helped me out on this, and believe me.. it was no fun tracking down. the values “not being posted” was actually a flaw in the FindControl method override. Please use this piece of code in the naming container that your validators reside, if they in fact need to validate against controls outside:

protected override Control FindControl(string id, int pathOffset)
{
Control c = base.FindControl(id, pathOffset);
if (c != null)
return c;
return FindControl(Page, id);
}
public Control FindControl(Control parent, string id)
{
Control recurse;
if (parent.ID == id)
{
return parent;
}
foreach (Control child in parent.Controls)
{
recurse = FindControl(child, id);
if (recurse != null)
{
return recurse;
}
}
return null;
}
Categories: ASP.NET, Uncategorized, Whatever, c# Tags:

Ampersand Issues in Code

June 25th, 2017 Michael Bell No comments

This is something that’s ticked me off repeatedly in the last few months. When I try to put a URL in say… the OnClientClick property of a ImageButton, and the URL has more than one argument (blah.aspx?a=1&b=2), the & gets replaces with &. This takes place I guess in the Render or RenderControl method. This also happens in Page.ClientScript.GetPostBackEventReference, and I’m sure these aren’t the only spots. Annoying!!! My only fix so far is just in the OnClickClick, call a javascript function that does yoru redirect, and pass it arguments.

Categories: Uncategorized Tags:

Upload with Progress Bar

June 25th, 2017 Michael Bell No comments

I found an awesome control for uploading via web browser, WITH a progress bar. Dean Brettle is the author, and his website is at: http://www.brettle.com . It’s a .NET control and it’s very easy to use.

I did have a need for multiple upload controls in a single page, with the option to add more as needed. The upload control didn’t have the capability built in to handle a collection, so I created one myself with the use of the System.Collections.Generic namespace. This is the code I used for uploading multiple images:

1. Included the System.Collections.Generic namespace

2. Added this generic property to my class:

List<InputFile> _InputFileCollection = new List<InputFile>();
    public List<InputFile> InputFileCollection
    {
        get
        {
            foreach (Control ctrl in this.Controls)
            {
                if (ctrl.GetType() == typeof(InputFile))
                {
                    _InputFileCollection.Add((InputFile)ctrl);
                }
            }
            return _InputFileCollection;
        }
    }

3. On the button click/upload event:

foreach (InputFile file in InputFileCollection)
        {
            if(file.HasFile)
           {
               _CurrentImageName = file.FileName;
               if(File.Exists(SavePath + _CurrentImageName))
               {
                   int i = 0;
                   while(File.Exists(SavePath + _CurrentImageName))
                   {
                       string s = file.FileName;
                       int dotLocation = s.IndexOf(“.”);
                       s = s.Insert(dotLocation,i.ToString());
                       _CurrentImageName = s;
                       i++;
                   }
               }
               file.MoveTo(SavePath + _CurrentImageName, MoveToOptions.Overwrite);
            }
        }

Works fantastically, and you can add all the input controls you want. 

Categories: Uncategorized Tags:

IE8, Table Rows, and the jQuery “toggle” Method

June 25th, 2017 Michael Bell No comments

I was recently on a project that required collapse/expand functionality. Upon implementation, I ran into a problem where IE6, IE7, and Firefox were working as expected, but IE8 was not. After spending more time on the issue that I care to admit, I found that IE8 has an issue with table rows (<tr>) and the jQuery toggle method. I was able to get around the issue by substitute this line of code:

$(tr).next().toggle();

with

$(tr).next().toggle($(tr).next().css(‘display’) == ‘none’);

Categories: Uncategorized Tags: