Category Archives: code

referencing a dropdownlist in javascript from a codebehind

hopefully i actually remember this in the future, but i’m sure i won’t. there’s a trick to referencing the actual dropdownlist in .net – the select input, that is. if you don’t just want the container, but want to get to the ddl itself, using javascript specifically, you’ll have to pass the DropDownList.DropDownListUniqueID. If you are building your JS in the code[behind/beside], you can use the following for finding and comparing the ddl value.

to pass the id into a JS function, try something like this:

<function>(Me.<DropDownList>.DropDownListUniqueID)

scriptText.Append(“<function>(categoryDropdownID)” & vbCrLf)
scriptText.Append(“var categoryDropdown = document.getElementById(categoryDropdownID);” & vbCrLf)

and, to check if the dropdownlist has a selected value in JS, use something like this:

scriptText.Append(String.Concat(“if(categoryDropdown[categoryDropdown.selectedIndex].value == <value>)”, vbCrLf))

i don’t have the exact source i’m quoting in front of me, but essentially you’re – passing the DropDownListUniqueID into the JS function to be able to reference the object directly in page code. you are then adding the ID to a variable. then you can compare the control to see if it has a selected value. elegant – probably not. will i use it again – probably.

maybe you can use this, i’m sure i will need this later.

multiline search and replace tools

did you ever try to find and replace multiple lines of code at once? want to do it in Visual Studio? too bad, sorry, out of luck. thankfully, there are some intrepid coders out there who have picked up the slack and created desktop tools which fill the void.

the first i came across was Nodesoft’s Search and Replace. it’s a suitable tool in most respects. quick, easy to use, super-light footprint (it doesn’t even install – just runs on top o’ the .NET framework). my only qualm is that it throws some odd character at the end of the file after it is done editing it. not a big deal, but it’s not ideal. other than that one pet peeve, the interface is simple and quick to learn. you can filter to only search certain file types or just check them all. beware of choosing all on a directory which is under source control as it will throw you a nice little alert window for each file it can’t open – which equates to a lot of ‘ok’ clicking to get through it. it can search a whole directory and include subdirectories (bonus!). and it’s completely free, so you can beat that.

next up is Advanced Find and Replace by Abacre. this one is a little heavier – it actually has an installer. the interface is also more complex. lots of buttons to do things for you. looks like there is also a batch replace where you can save replacements you do on a regular basis (nice!). another bonus is that the s&r i was working on when i closed the program is saved, session style, when i reopen the program. it’s quick and unobtrusive and i think i might like it. bummer on this one is that it doesn’t appear to be free. might have to talk to the boss about some licensing if i find more uses.

i’m sure there are more, but i just picked the first couple in the google results because those are obviously the best. google would never steer me in the wrong direction.

my love hate relationship with the checkboxlist control

if you’re not a geek – you may want to turn your head at this point. this is going to be a fairly technical post.

i’m working on a website right now – can’t tell you much about it because it’s slightly one of those in progress, can’t talk about it much, type things. i’ve been working with asp:checkboxlist controls rather intensely over the last day or so. i’m going to document a few things here, in the hopes that they may help someone else – and because i know i’ll run into this again and need a point of reference. so, here goes:

Continue reading

microsoft popfly might just hit a homerun

popfly is a new…uh…api(?) microsoft put together that is basically a drag and drop widget mash-up tool. the idea behind it seems like yahoo pipes to some extent, although i never spent any time with pipes so i can’t give a real comparison – someone will i’m sure. it requires silverlight 1.0, but doesn’t yet support 1.1. it’s all client-side, which is pretty cool and allows you to share your creations with your friends or the world. the collaboration aspect is intriguing as this could lead to some very powerful and useful interfaces. i’d be interested to see the scaling capabilities of this as that will be a really big factor in popfly’s success.

this looks like it will be very cool for everyone who enjoys getting their data in one place, their own way. i really like the idea that they expose the code and allow you to write your own javascript – and it looked like c# at first glance – to do a little more in depth mashing if you please. it’s in extremely limited alpha, apparently, so we’ll see if my spot in the queue makes it within the initial group of 2000 invites they claim to be giving out.

if ms does this right, it could be very big – so here’s to hoping that they do it well and respond to the feedback of the testing groups. they seem to be giving the collective a bit more input into their products these days and this would be a great place to allow the community at large to get their hands in the microsoft sandbox.

via [scobleizer]

some code tips for may 1

<%#DataBinder.Eval(Container.DataItem, >>
"stringDate", "{0:MMMM d, yyyy}") %>

will display as: May 1, 2007. more details and specifics can be found on dotgnu.org

you can also call a function on a DataBinder.Eval item, such as:
<%#TruncDescrip((string)DataBinder.Eval >>
(Container.DataItem, "stringDescription")) %>

with the underlying function in the code behind looking like:

protected string TruncDescrip(string descrip)
{
string shortDescrip = descrip.Substring(0, 100);
shortDescrip += "&#8230";

return shortDescrip;
}

Also, some sweet one-line code action when using the Microsoft Enterprise Library. Create a dataset, connect to the database, and fill the dataset – all at once.

DataSet dsNewsItems = DatabaseFactory.CreateDatabase("DatabaseName"). >> ExecuteDataSet(CommandType.StoredProcedure, "uspDoSomethingCool");

line breaks (inserted for readability) denoted by >>.

maybe not all best practices, and I did read the problems surrounding the late binding of the some of the above code, but .NET 2.0 is still new to me, so I’ll stick with these for now – and it’s not for a big production system anyway.

one other note that I found today – ctrl + shift + esc – will open up task manager. pretty handy.