Tuesday, September 25, 2012

installtuil – System.Security.SecurityException: The source was not found, but some or all event logs could not be searched

The lesson for this one is when in doubt, explicitly run as administrator.  Even though my colleague is an administrator to his Windows 7 machine, when he dropped to DOS prompt to install a service using installutil, he got an error message:


"Removing EventLog source service.
An exception occurred during the uninstallation of the System.Diagnostics.EventLogInstaller installer.
System.Security.SecurityException: The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security.
An exception occurred while uninstalling. This exception will be ignored and the uninstall will continue. However, the application might not be fully uninstalled after the uninstall is complete."



To get around this, we simply right clicked on  Command Prompt icon and chose to “Run as administrator“.  Then the installutil call worked fine and dandy.

Tuesday, September 18, 2012

Auto Resizing Images for Mobile Screens


One thing that I found out very quickly when working with jQuery Mobile was that my images did not auto resize to the device. If I made an image that was fairly large and looked ready for an iPad screen, that same image would be off in some way when viewed from an iPhone.
REMOVE HEIGHT AND WIDTH FROM YOUR IMG TAGS
After doing some research I found a simple fix that I wanted to share. There are a couple of things you need to do but the first thing is to not assign width and height dimensions for your images. For example, when you are inserting an image inside your HTML, typically you assign a width and a height to the image you insert, but when you are working with multiple screen sizes you don’t want your images to always be that size. If you assign a width and height to the image then no matter what that image will be that width and height and will never resize to the size you need. So again, do not assign width and height attributes to any of the images you want to resize, and it should look something like this

ADDING THE CSS TO MAKE IT ALL WORK
Now comes the important part, After you have removed all the width and height attributes from your img tags add this section to your main css file.
img, object{ max-height:90%; max-width:90%; }
You can change the max-height and max-width to whatever you want but we are addressing the objects within the img tags which in this case is the actual images and saying you have a max height/width of 90% that means you cannot go beyond 90% of the screen real-estate so if your image is wider than 90% it will auto resize but it will keep your image proportional. So I can take an image that would look great on an iPad and use it for an iPhone and not worry about it going off the screen.
CENTERING THE IMAGE
One other thing I am asked a lot is how to center the image. If you are targeting mobile then most likely the browser will support HTML5 so you can use HTML5′s center tag to accomplish this like the following.
<center><br /></center>
By wrapping the image inside of the center tags, it will always center my image in the middle of the screen. You can do this with any HTML element so it does not have to be an image.

Sunday, September 2, 2012

Removing both table and span tags from asp:DataList


A DataListis rendered with <table> or <span> tags, which I don't want.
I've set RepeatLayout="Flow" but that still gives me spans. I've setRepeaterDirection="Horizontal" but that still give me the tables.
how can i get a simple datalist without all the spans \ tables?

Solution 1:

 you might find it easier to use a repeater which will allow you to set your own markup.
Bascially, create an asp repeater, bind your data to it in much the same way as the datalist, and build your markup in the "itemtemplate " tag. (warning this is from memory - I'm on my roving laptop, so don't have Visual Studio to check syntax.)
<asp:Repeater runat="server" id="MyRepeater">
    <HeaderTemplate><h1>My Data Title</h1></HeaderTemplate>
    <TtemTemplate>
        <p>Any Markup you want. This bit gets repeated</p>
        <%#Container.DataItem("DataKeyOrColumnName")%>
    </ItemTemplate>
    <FooterTemplate><p>The footter (and header) only appear once.</p><p>you could use them to start and end a list or table</p></FooterTemplate>
</asp:Repeater>
You will only get the markup you put in the templates, nothing else. You can skip the header and footer if you don't need them. And if you want no markup at all, just have no tags in your template, the data will come out as plain text.

Solution 2:

Sometimes you can't use Repeater, because DataList provides additional possibilities (like updating the database via UPDATE and DELETE commands, working directly with the asp:DataSource).
Therefore, if you still need to use DataList but want to avoid it's html, you can do a bit of jQuery on top of it as I did it.
aspx code:
<ul class="list">
    <asp:DataList ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" DataKeyField="photo_id" RepeatLayout="Flow" RepeatDirection="Horizontal">
        <ItemTemplate>
            <li class="item" id='<%# Eval("photo_id") %>'>
                Whatever else you need here.
            </li>
            </ItemTemplate>
        </asp:DataList>
    </ul>
This will produce HTML like this:
<span id="SomeId" style="">
   <span>
      <li class="item ui-droppable" id="31349">
        Whatever else you need here.
     </li>
   </span>
</span>
Obviously there are 2 span tags you don't need. To remove them, you can add jQuery script on the page.
<script type="text/javascript">
$(document).ready(function () {
    $('.item').unwrap(); $('.item').unwrap();
});
</script>
In my case, I wanted to produce unordered list that I control. But as obvius, you can do it any other way by changing the HTML in DataList and targeting the right item in jQuery (.item).
Hope this helps someone else that needs DataList functionality and can't do it with Repeater.


How to do SELECT TOP @Param in a Stored Procedure?

Error:

I'm trying to do the following in a proc, but getting an incorrect syntax error:


SELECT TOP @NumberOfResultsToReturn * 
What am I doing wrong here? 

Solution:
This is old Method:
SET @@ROWCOUNT = @NumberOfResultsToReturnSELECT ........
SET @@ROWCOUNT = 0
This will work, although SELECT TOP (@NumberOfResultsToReturn) is preferable if you're using SQL server that supports this syntax:

New Method:
SQL Server: Put the argument in parens:
SELECT TOP (@NumberOfResultsToReturn) *