David Megnin
asked on
How do I format a SSN inside a FormView label without causing an error on Edit
Inside a FormView, Item Template I have a label, SSNLable I want to format like ###-##-####. In the Database the number has no dashes, #########.
I tried this and it doesn't change the format at all. It still shows as #########:
<asp:Label ID="SSNLabel" runat="server" Text='<%# Eval("SSN", "{0:###-##-####}") %>' />
I tried this and it does format the SSN correctly, but when I click "Edit" I get, "Object not set to an instance of an object" error:
Dim SSNLabel As Label = CType(FormView1.FindContro l("SSNLabe l"), Label)
SSNLabel.Text = SSNLabel.Text.Substring(0, 3) + "-" + SSNLabel.Text.Substring(3, 2) + "-" + SSNLabel.Text.Substring(5, 4)
I'm not sure what to try next. I just want the visual display of the dashes in the ItemTemplate. Dashes in the TextBox of the EditItemTemplate would be nice, but should not add them to the database, so that's probably more trouble than it's worth.
I tried this and it doesn't change the format at all. It still shows as #########:
<asp:Label ID="SSNLabel" runat="server" Text='<%# Eval("SSN", "{0:###-##-####}") %>' />
I tried this and it does format the SSN correctly, but when I click "Edit" I get, "Object not set to an instance of an object" error:
Dim SSNLabel As Label = CType(FormView1.FindContro
SSNLabel.Text = SSNLabel.Text.Substring(0,
I'm not sure what to try next. I just want the visual display of the dashes in the ItemTemplate. Dashes in the TextBox of the EditItemTemplate would be nice, but should not add them to the database, so that's probably more trouble than it's worth.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hmmm, I have AJAX Extensions in my ToolBox, but no AJAXControlToolkit. I'm using VS2008 and my project is targeted at .NET 3.5.
What am I missing?
What am I missing?
Reference the AjaxControlToolkit DLL in your project and see if that helps
ASKER
In the Add Reference dialog I don't see anything that starts with "Ajax".
Then also if I select "Add Items" in the Toolbox, I don't see Ajax anywhere.
I must have lost my AjaxControlToolkit dll somewhere. ??
Then also if I select "Add Items" in the Toolbox, I don't see Ajax anywhere.
I must have lost my AjaxControlToolkit dll somewhere. ??
Assuming you have installed the toolkit, see under C:\Program Files\AjaxControlToolkit
There should be a directory called "SampleWebsite" and if you go to the "Bin" directory you will see the DLL.
There should be a directory called "SampleWebsite" and if you go to the "Bin" directory you will see the DLL.
ASKER
I didn't think I had to install it if it's built into VS2008.
ASKER
Oh, and I have used it in the past. It was in my ToolBox before. Perhapse with a different Project/Solution.
I'll load up another Project and see if it shows up.
I'll load up another Project and see if it shows up.
VS 2008 supports AJAX Website (using UpdatePanels, UpdateProgress, etc) but for the toolkit, you'll have to download and install it.
ASKER
Oh. I think I've downloaded it. If not I'll go get it from Microsoft.com.
ASKER
Well, I got it and loaded the solution, the Sample website. Are all the instructions over a year old? Well to make a long story short, the Tookkit was in the solution once, I loaded my solution up, nothing, loaded the sample solution backup and nothing there either. &%^&*%&^$^%
In your solution, add a reference to the DLL that is present in the "Sample Website" folder under the "Bin" directory
ASKER
It says, "To get started with source code, simply load the "AjaxControlToolkit.sln" solution in Visual Studio 2008, and run the solution."
"...run the solution." WTF does that mean. I've never seen "run" anywhere in VS, ever.
"...run the solution." WTF does that mean. I've never seen "run" anywhere in VS, ever.
To "run" the solution means, debug and deploy it (by hitting F5).
ASKER
Should I copy that dll somewhere a little more permanent that the bin directory of a "Sample Website" that I may delete tomorrow?
Yep, you can do that
ASKER
Stuff like this just gets me frustrated. "running" the solution make the AjaxControlToolkit Components come back. But since my company doesn't run on "Sample Website", where is a good place to copy that dll and register it?
You can create a folder in your Program Files, called AJAXControlToolkit, and store it there
ASKER
I put it in the bin folder of my website. There was a copy already there, but had a smaller size. I copied the new one over it. I'm sure that was a big mistake. That would just be consistent.
ASKER
Oh, yeah, I guess I should put it on my local PC rather than the Server. (or in addition to?)
On my dev box, I add reference to the DLL (it can be in any location or from another project). This places the DLL on the "bin" folder. Once the application is working, I migrate it to the Production server. If I am developing applications on my PC (which I do) then I keep a copy of it and reference it whenever needed.
ASKER
Oh, my dev environment is not exactlly right. I dev right on the server by \\Server\C$\Inetpub\Websit e.
I've copied the website to my local PC, but I've just never started doing dev locally and copying everything back up to the server.
I've copied the website to my local PC, but I've just never started doing dev locally and copying everything back up to the server.
ASKER
Thanks a lot for the help. I'm still working through the details, but your solutions were the answer to what I was looking for.
ASKER
If FormView1.CurrentMode = FormViewMode.ReadOnly Then
But, for something else and I put the SSNLabel stuff outside it. Putting it inside should clear that up. Thank you.
Yeah, I'm looking at the link that 66866 sent me about the AjaxControlToolkit. I'm trying to work it into the EditItemTemplate of my FormView.