Adding Google Chrome to Visual Studio

Want to default Google Chrome as your browser for debugging in Visual Studio?  Follow these steps:

1) Right click on any web form (.aspx extension)

2) Click “Browse With”

3) Click “Add”

4) Navigate to where you have Google Chrome installed (mine was: "C:\Users\bolandt\AppData\Local\Google\Chrome\Application\chrome.exe"

image

Read More

Add Web References to Visual Studio 2008

So I’m doing a little work connecting to a Currency Exchange rate web service, simple enough.  Normal steps are to right click your solution->Add Web Reference, punch in the WSDL location and bang, web service goodness is at hand.

But with VS 2008 the option I have is "Add Service Reference".  So I run thru these steps and things are smooth again.  But now all the documentation the vendor provided seems way off in terms of naming and such.  Long story short is you need to click the advanced tab

image

And then go the compatibility section to add it the .NET 2.0 way.

image

Read More

ASP:HyperLink & Mailto

Recently I had a bit of trouble getting the HyperLink control to push out a mailto link in a Details View.

<asp:HyperLink NavigateUrl=’mailto:’ Text=’<%# Bind(“Email”) %> runat=”server” ID=”hlEmail”></asp:HyperLink>

 

This leaves a hyperlink but with a blank mailto - i.e. test@techtoolblog.com

So I assume if I stick in the bind (or eval) text to the Navigate URL we should be good to go:

<asp:HyperLink NavigateUrl=’mailto:<%# Bind(“Email”) %> Text=’<%# Bind(“Email”) %> runat=”server” ID=”hlEmail”></asp:HyperLink>

 

This gives me a link that is NOT clickable – If I view the source I see

<a id=”Details_hlEmail” href=”mailto:&lt;%#%20Bind(&quot;Email&quot;)%20%>”>test@techtoolblog.com </a>

 

My next guess is that this has something to do with formatting string, sure enough it is: This is the solution that ended up working for me:

<asp:HyperLink NavigateUrl=’<%# Bind(“Email”, “mailto:{0}”) %> Text=’<%# Bind(“Email”) %> runat=”server” ID=”hlEmail”></asp:HyperLink>

Read More

e.Row.RowState

I’m building a GridView that contains edit/update capabilities.  In edit mode for certain rows I need to turn on a drop down list, and based on that row add/remove Items from the list, other rows I want to show a text input to edit, all based on Foreign Key for that row in the database (which I store in a DataKey to access).  I handle the OnRowDataBound with a custom subroutine.  This hasn?t been an issue in the past but this time I have multiple controls in the ItemTemplate and need to manipulate at databound time, which is a first. 

<EditItemTemplate>

<asp:DropDownList ID=?ddlAnswer? runat=?server? Visible=?False?>

<asp:ListItem Value=?Yes? Text=?Yes? />

<asp:ListItem Value=?No? Text=?No? />

<asp:ListItem Value=?Neutral? Text=?Neutral? />

</asp:DropDownList>

<asp:TextBox ID=?txtAnswer? runat=?server? Text=?<%# Bind(?Answer?) %>? Visible=?False?></asp:TextBox>

</EditItemTemplate>

 

Both have visible=false so I need to get at the bound event and flip one on and change the item list if it?s the DropDownList.

RowState

I find the e.Row.RowState property and assign an if conditional to DataControlRowState.Edit. 

 

If e.Row.RowState = DataControlRowState.Edit Then

 

?CHANGE UPDATE COMMAND ARGUMENT

CType(e.Row.FindControl(?lbUpdate?), LinkButton).CommandArgument = _

e.Row.RowIndex.ToString()

 

Dim iAnswerTypeID = CInt(gvEditSurveyResults.DataKeys(e.Row.RowIndex).Item(0))

?TURN ON CORRECT TYPE OF INPUT

Select Case CInt(gvEditSurveyResults.DataKeys(e.Row.RowIndex).Item(0))

Case 1

CType(e.Row.FindControl(?ddlAnswer?), DropDownList).Visible = True

CType(e.Row.FindControl(?ddlAnswer?), DropDownList).SelectedValue = _

CStr(gvEditSurveyResults.DataKeys(e.Row.RowIndex).Item(2))

 

Case 2

CType(e.Row.FindControl(?txtAnswer?), TextBox).Visible = True

 

Case 3

 

Case 4

CType(e.Row.FindControl(?txtAnswer?), TextBox).Visible = True

CType(e.Row.FindControl(?txtAnswer?), TextBox).TextMode = TextBoxMode.MultiLine

 

Case 5

CType(e.Row.FindControl(?ddlAnswer?), DropDownList).Visible = True

Dim oldListItem As ListItem = CType(e.Row.FindControl(?ddlAnswer?), DropDownList).Items.FindByValue(?Neutral?)

?REMOVE NEUTRAL

CType(e.Row.FindControl(?ddlAnswer?), DropDownList).Items.Remove(oldListItem)

?ADD NA

CType(e.Row.FindControl(?ddlAnswer?), DropDownList).Items.Add _

(New ListItem(CStr(gvEditSurveyResults.DataKeys(e.Row.RowIndex).Item(1)), CStr(gvEditSurveyResults.DataKeys(e.Row.RowIndex).Item(1))))

CType(e.Row.FindControl(?ddlAnswer?), DropDownList).SelectedValue = _

CStr(gvEditSurveyResults.DataKeys(e.Row.RowIndex).Item(2))

End Select

 

End If

 

This doesn?t work, I never get into the if block for all rows. Setting a debug point I find the state of the row is not always DataControlRowState.Edit, but sometimes Alternate with an enumeration of 5.  Looking thru Microsoft documentation I don?t see any 5 reference. 

My Assumption

I am assuming that every property of the DataControlRowState handler has an Alternate row of that plus 1.  So edit  = 4 and edit on an alternative row is 5.

Stored Procedures vs Ad Hoc SQL

Stored procedures debate from my point of view:

Pros of using Stored Procedures

  • Cleaner code.  Thousand lines of logic and sql statements can be traded in for hundreds.
  • Push more work to someone else besides developer.  If you have a dedicated DB guy, this can really help in your timing. 
  • Put much more logic into Stored Procedure then Ad Hoc SQL
  • Faster. Ok, maybe a little bit, but with processing power and RAM does this really matter anymore?
  • Permissions are centralized and encompassed.
  • Trips to the database server can be reduced.

Cons of using Stored Procedures

I’m not entirely sure which side of the fence I lie.  Right now I’m more comfortable with not using stored procedures because of the maintenance factor.  I really think LINQ is going to make stored procedures deprecated.

.NET specific – Here is a nice line of code to keep around when working with stored procedures that I end up using when getting the the dreaded “Parameters do not match” error.  You can put this on your datasource Inserting Event.

For x As Integer = 0 To e.Command.Parameters.Count – 1

Trace.Write(e.Command.Parameters(x).ParameterName)

Trace.Write(e.Command.Parameters(x).Value)

Next

Read More

Subdomain Cookies and Localhost

So I have a site – we’ll call www.site1.com that sets a client side cookie named CookieName1 and I need a subdomain test.site1.com to be able to read that value. Using php’s standard setcookie() method I set the cookie on www by using:

setcookie( “CookieName1″, $CookieName1Value, $CookieExpDate, “/”, “.site1.com” );

This works, no problem.  Now test.site1.com uses .NET to read in the value and do something.  Pretty standard stuff here:

  If Request.Cookies(“CookieName1″) IsNot Nothing Then

   ”DO SOMETHING

  End If

 

Build > Debug, set a breakpoint on the if block, skips right over it.  Huh?  I make sure IE has the cookie, try again.  Nope, Request.Cookies(“CookieName1″) is Nothing.  Can’t be an IE thing can it?  Run same scenerio in FireFox – same result.  Then it dawns on me, I’m not running this under test.site1.com, I’m running this under localhost.  Everything was working as expected, cookies can only be read by *.site1.com.  So how am I going to test this thing on my local machine? I do have a sandbox, test1sandbox.site1.com, but what if I didn’t?  A simple solution is to change the host file found at %SystemRoot%\system32\drivers\etc\ with:

127.0.0.1 localhost
127.0.0.1 test1.site1.com

Run another Debug, change the http://localhost to http://test1.site1.com and now I’m able to read cookies from *.site1.com. Nifty.

Read More

Ajax.Net Pro and Atlas Together

I’ve been using AJAX with ASP.NET 2.0 for over a year now, mostly using Ajax.Net Professional. Now that Atlas is version 1.0 I’ve been playing around with it a bit. I ran into an issue having Ajax.Net Pro & Atlas running in the same web.config. I had a generic httpHandlers set for Ajax.Net Pro that was interfering with the Atlas setting. The fix was adding more meta data to the Ajax.Net Pro httpHandler.

<httpHandlers>

        <add verb=* path=*.ashx type=AjaxPro.AjaxHandlerFactory,AjaxPro.2, Version=6.10.6.2, Culture=neutral,PublicKeyToken=4735ae9824c7d3ec/>

      </httpHandlers>

Read More

Adding a Javascript Confirm Alert to a .NET Checkbox control in a GridView

One issue I recently ran into dealing with the gridview control in .NET is adding a javascript confirm box when a user selects a checkbox control and have a postback event fired. The dopostback event is tied to the onclick event, so I was unable to add it to the template item itself. I ended up having to manually call the dopostback myself with the javascript below.

function confirmSubmit(mycheckbox) {
 var agree=confirm("Are you sure you want to delete this quote?");
 if (agree) {
 setTimeout('__doPostBack(\'gvQuotes$ctl07$btnDelete\',\'\')', 0)
 return true ;
 }
 else {
  mycheckbox.checked = false;
  return false ;
  }
}

Here is the itemtemplate code that fires the javascript code:

<asp:TemplateField HeaderText="delete">
<ItemTemplate>
<asp:CheckBox ID="btnDelete" runat="server" Text="" 
onclick="confirmSubmit(this)"  
OnCheckedChanged="FireDeleteQuote"  />
<ItemStyle HorizontalAlign="Center" Width="0px" />
</ItemTemplate>
</asp:TemplateField>

If anyone has found an easier way to accomplish this let me know.



Adding code for checkbox control is a good idea. Coding makes everything so much more convenient, from bar code scanners to helpful web code. A symbol scanner can also simplify business processes by reading code. Partnered with a touch screen monitor these barcode readers and scanners become the ultimate in convenience.

Read More

IE 7 – Native xmlHttpRequest Not So Good

When I found out IE7 was going to implement a native javascript object, xmlHttpRequest, in addition to their own Microsoft.XMLHTTP object, I was thrilled. This meant once IE 6 was phased out of the world, all my ajax stuff wouldn’t need to check browser before proceeding. For the most I use ajax frameworks (http://www.ajaxpro.info/) that already have this built in but I do write my own xmlhttp request on occasion.

For an internal application I have an ajax search functionality built that queries a database and returns customers names on key entry. So I type in “Acm” I get a listing of:

Acmanda
Acmat
Acme

This is very similar to Google suggest, but I display the results in a fixed height div tag with auto scroll enabled. The ajax returns li tags with href tags around the company names. This works on IE 6, FF, and Safari. However in IE7, there is some real slowness to this. When I use Fiddler I see the Request returning from the AJAX calls but the results do not show up. I tried setting the page cache to nothing, but still no luck. I then ran into several articles questioning the XmlHttpRequest javascript object.

I also found out IE 7 is slow on some Google sites where a ton of XML traffic is being returned, like their Google Maps.

I started playing around with IE 7′s options, turning off Phishing filter, testing, no luck and so on. When I turned off the native XMLHttp support as seen below, my application ran perfectly fast on IE7. IE 7 is set up to fall back to the Microsoft.XMLHTTP Active X object if this gets turned off.

So this makes me wonder.

  • Did the IE 7 team really implement a native javascript XmlHttpRequest object?
  • If so, did they follow the spec?
  • If so, is their object code buggy or just plain slow

OR

  • Is their native XmlHttpRequest object really a javascript object or did they cut corners and implement an object that acts native but in all reality is a deformed active x object?
  • If so, why would you ship with this option turned on by default?

This has egg on the face written all over it.


Did you know you could browse IE with handheld computers? Modern technology makes everything more portable, like barcode readers and mobile computers. Zebra card printers are now portable, too, so you can print on the go!

Read More

Free Programming Video Tutorials

Microsoft just released a series of free c# video tutorials . It starts at a beginners level but moves to more advanced stuff like creating a RSS reader. They also have the same videos in VB in case that peaks your interest.

Some of the more interesting lessons that I’ve watched are:

  • Lesson 10: Working with XML
  • Lesson 12: The RSS Reader Project – Designing and Planning
  • Lesson 16: The RSS Reader Project – Fortifying, Testing and Deploying the Application
  • Lesson 6: How to create a System Tray application using the NotifyIcon control

The tutorials were made by http://www.learnvisualstudio.net/default.aspx, they too have more free tutorials on their site. – Enjoy!

Read More