Geeks With Blogs
Bunch's Blog One day I'll have a catchy subtitle, one day ASP.Net There are 40 entries for the tag ASP.Net
RadGrid Column Sizing
I came across this column sizing weirdness the other day. Using a RadGrid the headers looked great. The rows with the data however sized however they felt like it, usually way too small. After looking around I came across this that solved my problem. Adding the meta tag of <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> in the head section of my aspx page was what I needed. My issue was pretty specific since I had to target IE8 for the app I was working on but it may apply to ......

Posted On Friday, August 31, 2012 9:54 AM

New Window Via JavaScript Clears Parent
This is not a new item at all but I came across it recently. For an app I had been using some JavaScript like: here) to open a new window via a button. That bit of code had been working great in several other apps. Then in one app that same code decided to open the new window correctly while clearing the parent of everything but [object]. The fix ended up being simple, change the javascript to: javascript:void( here); Then it worked like ......

Posted On Friday, May 25, 2012 1:28 PM

BoundField Formatting
If you have a GridView that uses BoundFields but does not display line breaks or a lot of spaces quite right here is a way to get around that. This example uses a GridView with one BoundField that uses a DataField of comments. The comments are stored in a database and entered from another page which displays the comments properly in a textbox with all the spaces and line breaks you intended. The trick to get a BoundField to show those items is to take the item and replace the \r\n with a <br /> ......

Posted On Wednesday, May 23, 2012 4:24 PM

Finding Buried Controls

This post is pretty specific to an issue I had but still has some ideas that could be applied in other scenarios. The problem I had was updating a few buttons so their Text values could be set in the code behind which had a method...

Posted On Wednesday, March 28, 2012 2:27 PM

RadGrid PagerStyle in Code Behind
Recently I ran into an issue where the paging text in a RadGrid control needed to be customizable. In my case I was specifically looking at the "Page size" and "xx items in yy pages" text. Getting around it for the "Page size" was a snap. If your RadGrid is called rgTest one line would do it: rgTest.PagerStyle.PageSizeL... = "your text here"; The "xx items in yy pages" was a bit trickier, but still handled in one line of code. rgTest.PagerStyle.PagerText... = "{4} {5} things in {1} my pages"; ......

Posted On Tuesday, March 6, 2012 3:56 PM

Retrieving a Logged On User ID
Here is an easy way to retrieve the user ID from who ever is logged on to a PC using ASP.Net. This is handy for ASP.Net applications where you want to put a "Welcome joe user" label at the top, auto populate a form with the user's ID or add the user ID to some data you are storing back into a database if you keep track of who edited a record last. The code below assumes you have an aspx page with two labels on it, lblFName and lblLName. It grabs the user ID with HttpContext and then splits the ID ......

Posted On Friday, January 20, 2012 8:22 AM

Finding a GridViews Edit Control
Here is one way to access a control in a GridView right after a user clicks a button to change from view to edit mode. This example shows a TextBox that gets populated with today's date. The GridView is setup like this:<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="TestID" DataSourceID="SqlDataSource1" onrowdatabound="GridView2_R... > <Columns> <asp:TemplateField> <ItemTemplate> <asp:Button ID="btnEdit" runat="server" Text="Edit" ......

Posted On Friday, December 23, 2011 11:40 AM

Accessing Controls Within A Gridview
Sometimes you need to access a control within a GridView, but it isn’t quite as straight forward as just using FindControl to grab the control like you can in a FormView. Since the GridView builds multiple rows the key is to specify the row. In this example there is a GridView with a control for a player’s errors. If the errors is greater than 9 the GridView should display the control (lblErrors) in red so it stands out. Here is the GridView: <asp:GridView ID="gvFielding" runat="server" DataSourceID="sqlFielding" ......

Posted On Friday, June 17, 2011 9:44 AM

Access Master Page Controls II
Here is another way to access master page controls. This way has a bit less coding then my previous post on the subject. The scenario would be that you have a master page with a few navigation buttons at the top for users to navigate the app. After a button is clicked the corresponding aspx page would load in the ContentPlaceHolder. To make it easier for the users to see what page they are on I wanted the clicked navigation button to change color. This would be a quick visual for the user and is ......

Posted On Wednesday, March 16, 2011 9:09 AM

Control Parameters and DropDownList Text
This is something that I rarely need to do, grab a DropDownList’s selected item’s text for use in a datasource’s ControlParameter. To allow for this use SelectedItem.Text instead of the more common SelectedValue for the PropertyName. <asp:ControlParameter ControlID="ddlStuff" Name="stuffName" Type="String" PropertyName="SelectedItem.... /> The reason for using this is for text comparison. On rare occasions you may need to check the text against a list where the SelectedValue just does not ......

Posted On Friday, February 18, 2011 10:57 AM

Two Values Enter, One Value Leaves

This is a fairly easy way to compare values for two different controls. In this example a user needs to enter in a street address and zip code OR pick a county. After that the application will display location(s) based on the value. The application only wants a specific street/zip combination or a county, not both. This code shows...

Posted On Wednesday, December 22, 2010 1:47 PM

Setting the SlideShowExtender's Index
The AJAX SlideShowExtender is pretty useful. It does what it says and works without much fuss. There was one trick I needed it to perform that I could not find natively within the control. That was to set the slide’s current index. With a little JavaScript however I could make the control do what I wanted. The example below assumes a few things. First you already have a SlideShowExtender setup and working (or see this post). Second this SlideShowExtender is on a page all by itself so the index to ......

Posted On Wednesday, December 22, 2010 9:50 AM

URL Parameter Cleanup in JavaScript

Using a JavaScript function to show another window from an aspx page is pretty common. Often times you need to pass some variables by appending them to the URL string. And sometimes you don’t know which variables you may or may not need. This example shows one way of passing the variable(s) you need.

Posted On Monday, September 20, 2010 2:20 PM

Using the AJAX SlideShowExtender with database images

This post goes over how to display images stored in a database using the SlideShowExtender control. The examples use VB.Net (what I have to use at the office) and assumes that you are storing your images in a database, a way to retrieve the images from the database (e.g. stored procedure) and have AJAX setup in your ASP.Net project already. Also the example was based on retrieving images that are photos hence the names of some of the various functions, controls, etc.

Posted On Friday, September 17, 2010 9:51 AM

Accessing Master Page Controls
Sometimes when using Master Pages you need to set a property on a control from the content page. An example might be changing a label’s text to reflect some content (e.g. customer name) being viewed or maybe to change the visibility of a control depending on the rights a user may have in the application. There are different ways to do this but this is the one I like. First on the code behind of the Master Page create the property that needs to be accessed. An example would be: Public Property CustomerNameText() ......

Posted On Thursday, April 8, 2010 2:23 PM

Vertical Scroll Bars For GridView
Here is an old trick to get vertical scroll bars for a GridView. I find this handy when the end users do not want paging but they also do not want to have a page load a GridView that is a mile long either. The code below shows placing your GridView inside a Panel. The Panel is where the scroll bar option is set. I used “Auto” in the example, this way the scroll bar will only appear if the amount of rows in the GridView exceeds the height set. The trick lies in placing both controls inside a single ......

Posted On Monday, February 8, 2010 12:19 PM

ScriptManager is Ambiguous
This trick might work if you have an application that has been moved from the 2.0 framework to 3.5. This happened to me recently and I had tried removing the Web.Extensions reference and adding it back in, deleting old pages that had the older ScriptManager on them and manually removing then adding back the Web.Extensions sections in the web.config file. Nothing worked so I compared the web.config files from the problem project to one that was created from scratch targeting the 3.5 framework. I saw ......

Posted On Monday, November 16, 2009 6:32 AM

Apply CSS to all Textboxes
Here is a really quick CSS item to apply styles to different types of textboxes in an ASP.Net application. A plain old vanilla asp:textbox control will show as an Input if you view the source of the page. To set the styles of all those controls from a css file you can add this to your css: input[type=”text”] { font-size: 8pt; font-family: Arial; } Then you do not need to add the CssClass property to the textboxes in the aspx file. The input section of the css will be applied automatically. This saves ......

Posted On Friday, November 13, 2009 6:21 AM

HTML Tables Side by Side II
I had posted this last month and saw a comment posted quickly that you can use CSS as well. A way to use CSS is listed below. <table style="float: left; width: 300px; margin-left: 15px"> </table> <table style="float: right; width: 500px; margin-right: 15px" > </table> Technorati Tags: HTML,ASP.Net ......

Posted On Wednesday, September 30, 2009 1:44 AM

HTML Tables Side by Side
Here is a long time issue and this is by no way the first post about it (or probably even the 1000th). In the code below I have two tables that needed to be side by side. The first one on the left allows a user to search for site notes. Just a few dates and a note type. The second table allows a user to enter a new note. Even less to enter just a date and the text for the note. Since I needed the tables side by side I nested both into one big table, keeping each table in it’s own cell and both cells ......

Posted On Wednesday, August 12, 2009 5:32 AM

Accordion Arrows
This is one way to have up/down or open/close arrows appear on an AJAX AccordionPane. First add a div and an img to the Header of the AccordionPane along with the title (the example uses ‘Add Widget’). <cc1:AccordionPane ID="apTest" runat="server" > <Header> <div id="div1" onclick="UpDownIcons('imgAc... Add Widget&nbsp;&nbsp;&... src="Images/arrow_down.ico" id="imgAcc" alt="expand" /> </div> </Header> Note the onclick function for the div, that ......

Posted On Wednesday, June 24, 2009 3:35 AM

Passing a GridView value to Javascript
This is a similar technique to the one outlined in this post. The idea is simple, you have a data value that you want to pass to a Javascript function through a button click on a GridView row. The example below shows how to pass a variable, in this case OtherID, to a Javascript function that opens a new modal window which holds a different aspx page. function ShowOther(OtherID) { window.showModalDialog('Oth... + OtherID, 'dialogHeight:600px;dialogW... } In the GridView ......

Posted On Monday, June 8, 2009 7:33 AM

Calendar Extender Display Issue – Update Panel Weirdness
This issue started for me after I added an Update Panel to the aspx page. If the calendar extender is showing up weird, like with no background and is displayed no where near where it should be this could fix your problem. Take the original css from the control toolkit (AjaxControlToolkit\AjaxCon... and copy it into your css file in the application. No css modification is needed and you do not need to set the CssClass property to the control on the aspx page. Technorati ......

Posted On Monday, May 18, 2009 3:07 PM

Loading Data on a Ajax TabPanel Click
Here is one way to have data load only when a TabPanel is clicked. In my example I have an aspx page with a TabContainer, two TabPanels both with their own ObjectDataSources that fill GridViews. The first tab’s ObjectDataSource and GridView will run on the page load and that is fine since it would be the first thing a user sees. The overall idea is to have the ObjectDataSource for the second tab to not run on the page load and then have the GridView on the second tab databind only when the tab is ......

Posted On Friday, May 15, 2009 10:48 AM

Calendar Extender Display – Easier Workaround
This post goes along with this previous post on calendar extender display issues. However the formatting fix I used was much less involved than before. Again I had a GridView with some text boxes for dates that I added the CalendarExtender to. And just like before the GridView had some CSS specific to it’s td which involved padding and text alignment. I added all the CalendarExtender styles to my css file and the extender worked fine but did not look quite right. The current date listing was quite ......

Posted On Friday, May 15, 2009 10:27 AM

DetailsView Blank with Single Record and Paging
I ran into an issue using the DetailsView with and ObjectDataSource and paging. In this setup the DetailsView would populate data based off the user’s selection from a dropdown. The paging itself was not the issue that worked just fine. The issue I had was that if the DetailsView displayed data with multiple pages and the user selected a page other than the first and then picked a different value from the dropdown that only had one page to display in the DetailsView it would default to the EmptyDataTemplate. ......

Posted On Tuesday, March 31, 2009 10:58 AM

Calendar Extender Display Issues
I was recently working on a GridView and needed to add a calendar for two of the columns while in edit mode. I added the AJAX CalendarExtender and it returned the selected date with no issues. <EditItemTemplate > <asp:TextBox ID="txtDate1" runat="server" Text='<%# BIND("Date1", "{0: MM/dd/yyyy}") %>'></asp:TextBox> <cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtDate1" PopupPosition="Right" CssClass="caltheme" > </cc1:CalendarExtender> ......

Posted On Friday, March 6, 2009 3:49 PM

Quick and Dirty Calendar Validation (Date Required)
Probably everyone has at one time or another had a form that needed some sort of date to be entered. If you are like me and use ASP.Net and want to use the ASP calendar control the asp validators don’t work. Well without some work arounds to the calendar control. However if you just needed to validate if the user clicked on a date in the calendar control you can just use the regular calendar control and a customvalidator like this. The calendar control: <asp:Calendar ID="caltest" runat="server" ......

Posted On Tuesday, February 17, 2009 3:00 PM

Publishing Error (Old items just don’t go away)
I inherited an app to make some updates. It was an older 1.1 ASP.Net application that was already upgraded to 2.0. All the new files I wrote worked fine and it built error free. I could debug the app and run it locally with no problems. Once I was ready to publish the app it then finally decided to give me some grief. I would get an error after the build completed and the publish started. The error was: Data at the root level is invalid. Line 1, position1. When I clicked on the error line in VS it ......

Posted On Friday, January 16, 2009 10:52 AM

2-Way Binding with CascadingDropDown
This post deals with 2-way binding of data to a CascadingDropDown. It assumes that the CascadingDropDown is already configured to return data to the list. I had my DropDownList and CascadingDropDown pairs within a FormView and it is bound to a SqlDataSource. < asp : Label ID ="Label1" runat ="server" Text ="Mfr" /> < asp : DropDownList ID ="ddlMfrs" runat ="server" /> < cc1 : CascadingDropDown ID ="cddMfr" runat ="server" TargetControlID ="ddlMfrs" Category ="MfrID" PromptText ="Select ......

Posted On Wednesday, October 1, 2008 9:08 AM

Web Service Not Called From Ajax Control
Here was some more Ajax fun I recently had. I was trying to use a CascadingDropDown using Ajax 1.0 (the version for VS2005). I had everything setup the DropDownList and CascadingDropDown controls on my aspx page, the data access functions in a class and the web methods in the asmx's code behind. Everything was also in one project. No matter what I did I would only get ‘Method Error 500’ in the drop down and when I put a break point in the function of the asmx it would never get hit. I searched around ......

Posted On Friday, September 26, 2008 1:25 PM

Tabbing Issue with AutoPostBack
Here was a little issue that caused some frustration. I have an app with an UpdatePanel and inside that are two Textboxes each with their own RequiredFieldValidator. Both Textboxes had AutoPostBack set to True. Also each used an OnTextChanged event to trigger some checks from the code behind. The issue was after entering a valid value in Textbox1 you could not tab directly to Textbox2. When you hit the tab key the cursor would blink once in Textbox2 and then disappear. If you kept hitting tab the ......

Posted On Thursday, September 18, 2008 3:17 PM

No Show on Second ValidatorCalloutExtender
I was working on an application recently that was pretty typical data entry stuff. Nothing fancy but I did want to try out the AJAX ValidatorCalloutExtenders. I had them all setup using the ValidatorCalloutExtenders to well extend my RequiredFieldValidators. They were then tied to a button to save the data back to the database. All told there were seven different required fields for this form. <asp:Button ID="btnInsert" runat="server" CommandName="insert" Text="Add New" Visible="true" CausesValidation="true" ......

Posted On Wednesday, September 3, 2008 10:46 AM

EVAL and replace
This is somewhat related to my previous post. I needed to strip out a leading character from an EVAL when I appended that value to a URL. Luckily the character was always the same, in this example an X. The solution was to simply use Replace on the EVAL and replace the X with “”. <asp:HyperLink ID="hlID" runat="server" Text='<%# EVAL("ID") %>' NavigateUrl='<%#"Default... + Replace(EVAL("ID"),"X", "") %>'/> Technorati Tags: ASP.Net ......

Posted On Wednesday, July 30, 2008 2:51 PM

NavigateUrl and EVAL
Here is how you can add a database value to the URL of a HyperLink that is in a GridView. In this example the text displayed is the same as the value added to the URL. Also the data is bound through a SqlDataSource and the “ID” value is from the output of the Select statement the SqlDataSource uses. This is a quick way to put the data in the URL without using any code in the code behind. <asp:TemplateField HeaderText="ID" > <ItemTemplate> <asp:HyperLink ID="hlID" runat="server" Text='<%# ......

Posted On Wednesday, July 30, 2008 2:45 PM

Design View Error
I’ve been using Visual Studio 2008 for a few weeks now and came across a small issue. Of course it was with a new feature I wanted to use. When I would try and view the Design or Split (like I’m used to seeing in Dreamweaver) view in an ASP.Net page of a content page that points back to a master page I would get the following error: Luckily the fix was really simple although I do need to do it every time I load the project. Click on View/Refresh when viewing the Design or Split mode and the page ......

Posted On Monday, April 21, 2008 3:12 PM

CSS, Themes, Master Pages and Ajax Tabs
This was done using ASP.NET 3.5 in VS 2008. I had an application that I was using an Ajax TabContainer and TabPanels. The tabs looked great but I had wanted to change the background color of the tab body to a standard color my company uses. I took the default /*XP Theme*/ styles from Tabs.css and put them in my own CSS file. On the TabContainer I set the CssClass=”tabBackground” (tabBackground was the name I gave the class in my CSS file). I changed the background-color in .ajax_tab_body and everything ......

Posted On Monday, April 21, 2008 2:58 PM

Using Ajax Tabs
Prior to utilizing Ajax making a page with tabs was a bit of a pain. I would setup a MultiView and add in Views for each tab. Ajax’s Tab Container control is much easier to use. I’ve listed below the order on a sample aspx file that I setup the various Ajax controls to get it all to work. The only real tricks I saw were to add the ScriptManager and the order of the TabContainer/TabPanel/Conte... The ScriptManager and Tab controls went inside the <div> and I made sure that the toolkit ......

Posted On Tuesday, March 25, 2008 9:03 AM

Cascading DropDowns within a FormView (Without AJAX)
This was something else that gave me fits recently. I have a web app that uses a formview, which wasn’t that big a deal to me. Until I tried to have the value in one dropdown affect the value(s) in a second dropdown. For my problem the first dropdown holds manufacturer names and then the second displays the models by the selected manufacturer in the first dropdown. I could get the dropdowns to load up proper on the first load based on a SQL query, but the issue came about when I was testing changing ......

Posted On Monday, March 10, 2008 2:29 PM


Hello everyone!

This is my first post on my blog here so this is more a test than anything. I hope to blog about various items regarding SQL Server, VB.Net, ASP.Net and Ajax/JavaScript. Other technical blogging interests will most likely revolve around Windows, Linux, PC hardware and the XBox 360. Outside of the geeky realm I'll mostly write about soccer (or football if you prefer). Yeah I'm a Yank but I still love the beautiful game!


Posted On Tuesday, March 4, 2008 11:23 PM

Copyright © Bunch | Powered by: