Hendrik Swanepoel

June 2004 - Posts

Displaying thumbnail previews for non-image files

We have to include functionality into an application of ours which will show thumbnail previews for certain HTML files.

This functionality is used for choosing a template in a content management product of ours.

In order to get the preview, there are some shell programming involved. Luckily, I didn't have to work on the shell coding myself, because I found a link that contains code for an object that does all this for you - in C#.

To access the code, follow this link.

Easy peasy.

Posted: Jun 30 2004, 11:16 AM by hendrik | with no comments
Filed under:
Displaying HTML tables without causing a line break

When inserting a table into your markup, the default behavior is that it will automatically start on a new line.
Sometimes this is not the desired behavior.

I had to write a custom control recently in order to display a complex custom button. Due to some tiling issues involved, we had to use a table. The button displayed fine, but we found that when we wanted to display the button in a paragraph, it always started on a new line.

This is an  example of what I mean:

This is the text of the paragraph, I want the table to display here ->

table contents

As you can clearly see, the table displays in the next line - although I want it to display in-line.

The solution for this is very simple. Just include a css attribute on the table tag, display: inline. So insert the following text into your table element: style=”display: inline”.

This example uses this attribute, and you can clearly see that it resolves the problem:

This is the text of the paragraph, I want the table to display here ->

table contents

VSS DB migration

I had to migrate our vss db to another server.

I found a resource on the web on how to split up a vss db into 2 dbs. The same steps can also be used to migrate the database:

http://blogs.msdn.com/korbyp/archive/2003/10/20/54226.aspx

 

Posted: Jun 28 2004, 12:48 PM by hendrik | with no comments
Filed under:
Patterns & Practices event 1

I attended the Patterns & Practices event at Microsoft on Saturday. This is a level 300 event, which assumes that you know the basics of .Net. The event covers development using patterns - GOF patterns and Microsoft's patterns. The lecturer is PDev's Ayal Rosenberg.

I think the covered content was useful and I look forward to the next three lectures. We went over the use for patterns in development and then covered a few GOF patterns with code samples. We lost a bit of momentum while covering the basic patterns like the Singleton. At the end we covered the Bridge pattern in detail.

I think now that we have covered the basics in the first lecture, the following lectures are going to be very useful.

 

 

Posted: Jun 28 2004, 08:29 AM by hendrik | with no comments
Filed under:
Intersoft mega book sale

I received an e-mail containing this:

Posted: Jun 22 2004, 11:47 AM by hendrik | with no comments
Filed under:
Problem with accessing runat server controls on the client-side

When you place controls inside of a UserControl (and provide them with the runat=server attribute), those controls' IDs will differ in the resulting client-side HTML from their respective IDs that you defined on the server side.

For example:

I have a UserControl called sub.ascx. In this uc I define a textbox control, give it the id of txtCal and run a page containing sub.ascx as a child control. This all works fine.
I now add a button which will execute some client-side code. I want the client-side code to set txtCal's value to 0. So I go ahead and write the code like this:

document.all[”txtCal”].value =0;

This results an an error that conveys the message that the object could not be found..

The reason for this is due to the fact that the UserControl implements INamingContainer. When a control implements this interface, all it's child controls' IDs will be changed, in order to prevent duplicate ID attributes in the hierarchy. Say for instance we put a txtCal textbox in the container page and a txtCal textbox in the usercontrol, this will result in duplicate IDs, preventing any client-side code from working.

So how to hook the client-side code up to the control?

At runtime, you will have access on the server-side as to what the id of the control will be on the client-side. This means that you can go and write a simple method like this in order to let your client-side code know what ID's to use for discovery of the objects - you can call this method from your Page_Load method:

 

        private void RegisterClientIds()
        {
            // for each object you want to access on the client-side - provide that id here
            // this is done by accessing the UniqueId property of the server-side object
            string scriptStr = "var txtCalVar = '" + txtCal.UniqueID.Replace(":", "_") + "';";
            scriptStr += "var txtOtherVar = '" + txtOtherVar.UniqueID.Replace(":", "_") + "';";
            Page.RegisterClientScriptBlock("clientsideVars", "<scri" + "pt>" + scriptStr + "</scr" + "ipt>");
        }

 

Now, you adapt your client-side code to access the objects by way of using the variables you set:

 

<script>
    function setText(){
        document.all[txtCalVar].value = "this is the text";
    }
</script>
Posted: Jun 22 2004, 09:13 AM by hendrik | with 3 comment(s)
Filed under:
Geek dinner

I attended the Microsoft Pta dinner last night at Primi Piatti in Menlyn. Kaylash and SimonS went through a whole bunch of questions, trying to get input from the developers on how to improve the SADev community, support, events, etc.

A few issues that surfaced which I personally agree with:

  • Microsoft certification sucks - it might be useful to have a more practical approach to the examination process - like some Sun and Cisco exams. I feel that 80% of the exams can still be monkey puzzles, due to the obvious costs involved in the admin of practical exams. Then to get the certification, like MCSD, you need to do one practical exam.
  • A merit system needs to be introduced on SADev, in order to encourage people to contribute more of heir knowledge.

A few of dotnet.org.za's bloggers were there:

  • Armand
  • Kevin
  • Thea
  • Iwan
  • Deon
  • Cobus
  • Ralf

<update>
And I only found out last night that Armand and Thea are now SADev's representatives for Pretoria - congrats!
</update>

Posted: Jun 22 2004, 08:38 AM by hendrik | with 2 comment(s)
Filed under:
MSMQ

I found this post on Ingo Rammer's blog very useful, due to the fact that I'm researching the use of MSMQ in one of my upcoming projects: http://www.thinktecture.com/staff/ingo/weblog/archives/001397.html.

Posted: Jun 21 2004, 10:41 AM by hendrik | with 1 comment(s)
Filed under:
SpaceShipOne

There is an interesting article on space.com regarding the private spaceflight attempt that's going to take place today.

The project is funded by Microsoft's co-founder Paul Allen.

Posted: Jun 21 2004, 07:22 AM by hendrik | with no comments
Filed under:
Creating a thumbnail image dynamically

I was really surprised about how easy this is. The last time I played with the System.Drawing namespace was when I dynamically created images when I first started playing around with ASP.Net.

I'm currently including functionality into a product that allows it to display images on the server as thumbnails, and these thumbnails needs to be dynamically generated. The following snippet shows how to dynamically generate a thumbnail and display it.

        public bool ThumbnailCallBack()
        {
            return false;
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            System.Drawing.Image.GetThumbnailImageAbort callback = 
                new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallBack);
            System.Drawing.Image im = System.Drawing.Image.FromFile(Server.MapPath("Sample.jpg")); 
            System.Drawing.Image thumb =  im.GetThumbnailImage(50, 50, callback, IntPtr.Zero);
            thumb.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
        }
Posted: Jun 08 2004, 08:44 AM by hendrik | with 1 comment(s)
Filed under:
Launching a server side click event from the client side

Wow, confusing title...

Often I want to incorporate some logic on the client-side in order to alleviate the need for an unnecessary postback. This means that want the power of linking up client-side logic with the server side, being able to launch server side event handlers from the client side - through the normal channels. This means that I don't want to redirect to the same page using querystrings and call the correct function from the Page_Load method..

I want the same behavior as when an asp:button object has been clicked. Normally what happens here is: the hidden variable is set in the page on the client side (__VIEWSTATE ), then the server side (the asp.net engine) checks the __VIEWSTATE variable to see which element caused the post back and then checks to see which event handler has beens assigned for the event. The asp.net engine then executes the correct event handler.

I really had to think hard to come up with a simple and explanatory example. What I came up with doesn't really illustrate a real practical scenario, but hopefully conveys the concept. So there are numerous other ways to solve the given problem.

You wrote a library application. The library application allows the user to capture detail about the books, including a short disclaimer, like whether it's suitable for children, etc. When capturing the detail of the book, you can choose one of the populated descriptions from the list, or you can choose to add a new one. To add a new disclaimer from this screen, you will launch another screen where the user can then populate the disclaimer and save it. This image depicts the scenario:

The trick is that you want this newly added disclaimer to be available immediately in the list of disclaimers in the main page. Also, you want to save the changes to the db which has already been populated. This means that it would've been nice if we could trigger the 'Submit' button, so that it's event fire on the server side. In this event's handler we'll save the populated fields to the db and also add the refresh the view containing the available disclaimers.

Fortunately, it's very easy to do just this! In the main page we'll have a function that'll find our 'Submit' button, and cause it to be “clicked”, firing the correct event on the server side. The opened page where we add our disclaimer will just call this function:

 

<script>
            function causeSubmit(){
                //we have to look for the element with a loop, due to the fact that 
                //    because it has a runat="server" attribute the INamingContainer 
                //    functionality will cause the id to be changed 
                //  Thus, we'll lok for it by it's value attribute, because that will remain the same 
                //    on the client side 
                for(i=0;i//I loop through the forms elements, because this will provide me with input elements
                    //ensure it has a value attribute
                    if(document.forms[0].elements[i].value){
                        if(document.forms[0].elements[i].value == "Submit"){
                            // or look for whatever your button's text is
                            // the following line causes the element to be "clicked" causing
                            // the correct event on the server side to be fired
                            document.forms[0].elements[i].click(); 
                        }
                    }
                }
            }
script>
Bowling

I enjoyed the PTA MS bowling event the other night. Although I can't bowl to save my life, it was a lot of fun.
Thanks to MS for organizing the event, it was cool meeting the other people in my area.

It was a bit weird though. We were split up into groups per lane, and as it turned out, all the people in our group went to the same high-school. And there were 5 people at the event who matriculated with me at the same high-school!

Thea provided the link to view the pictures of the event.

Posted: Jun 03 2004, 06:48 AM by hendrik | with no comments
Filed under: