Archive for December, 2008

_aspx’ does not contain a definition for ‘btn_Click1’

December 17, 2008

this is not a visual studio bug; I did it to myself. Here’s how:
1) I needed to modify a screen, and I needed to get to the button handler. So in Visual Studio design mode, I clicked on the button.
2) instead of going to the existing button handler, it created a new one and went to it. Well I didn’t want that new one, so I promptly deleted it and scrolled up to the real one. Then I went on to other things and forgot about it.

This cost me a lot of grief later, since I could see that I definitely had a handler for my button, but I got the error
_aspx’ does not contain a definition for ‘btnRunReport_Click1’.
Note that it said “Click1”, not “Click”.
Where was this mysterious missing function ‘btnRunReport_Click1’ referenced?
It turns out that when I clicked on the button in design, vstudio put a javascript event handler on my button, OnClick=”btnRunReport_Click1″ , but when I deleted the unwanted function, the form would no longer compile.

I’m working on this project in C#, and I don’t remember seeing this behavior in VB.

javascript debugging

December 10, 2008

you know how cool it is when you open a page and IE hits one of your javascript errors and visual studio automatically comes up to the exact line of the bug?

Well, what if it doesn’t work?

I just found a bug – I had an extra close bracket at the end of one of my include javascript files. When I refreshed my page in IE, I got a message that a javascript runtime error had occurred, in line 78, but there was nothing in line 78 of “view source” that was related, and Visual Studio did not come up. I was stuck. Firefox did not complain about the page at all.

Someone in a javascript site mentioned that you could find errors by entering “javascript:” in the location line of a mozilla browser (firefox).

Wow – that returns all kinds of neat stuff – it found my bug, which was the very end of that include file, and it found dozens of minor issues with css files.

Try it sometime – what a lifesaver for me. I had spent an hour last night on this. Maybe if I followed a practice of checking each javascript include file with some kind of debugger every time I edited it, then I could prevent a simple typo from costing me hours. At one point last night I was getting portions of my viewstate highlighted as though they were the javascript error, and IE seemed to be totally flummoxed.

String Checkbox Control

December 9, 2008

I want to display an array of checkboxes in a gridview.
It should look like this:
grid_of_checkboxes

But, there is a trick – my database query returns booleans, but the only thing I can bind to the “checked” property of the asp:checkbox control is a string. Too bad. I’ll include some of the work arounds I attempted – I thought they were interesting, but nothing worked.

(OOPS - word press is deleting my code ... sorry)

            <asp:Label ID="lblTest" runat="server" Text='' />

<asp:CheckBox ID="test" runat="server" Checked='' />
<asp:CheckBox ID="test" runat="server" Checked= />


The checkbox above returned “InvalidCastException”. Take my word for it, I tried many variations on the above.

So how did I eventually get the display to work?
I think there are two possible ways.
I did not attempt a server side handling of the row-data-bound event to find the checkbox control and set it to the correct value, although I think that would work.

Instead, I made a simple user control called a StringCheckBox, and set it with the “1” or “0” that my bind syntax was producing, and that worked well.

REVISION – when a simple checkbox is printed, it never prints as checked. I don’t know why. I changed the control so that it displays two images instead of the checkbox.
Here is the (revised) server side of the control in its entirety:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace TBRSurvey.UTReports
{
public partial class ctlStringCheckBox : System.Web.UI.UserControl
{

private string m_checked ="";
public string ctl_checked
{
get { return m_checked; }
set { m_checked = value; }

}

protected void Page_Load(object sender, EventArgs e)
{
CheckBox1.Checked = false;
// images from http://openacs.org/doc/acs-subsite/images.html
imgCheckBox.ImageUrl = "~/images/checkbox.gif";

if (m_checked == "1")
{
CheckBox1.Checked = true;
imgCheckBox.ImageUrl = "~/images/checkboxchecked.gif";
}
if (m_checked.ToLower() == "true")
{
CheckBox1.Checked = true;
imgCheckBox.ImageUrl = "~/images/checkbox.gif";
}
}
}
}