[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do I format a SSN inside a FormView label without causing an error on Edit

Posted on 2009-02-23
24
Medium Priority
?
566 Views
Last Modified: 2012-05-06
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.FindControl("SSNLabel"), 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.


0
Comment
Question by:megnin
  • 14
  • 9
24 Comments
 
LVL 21

Accepted Solution

by:
66866 earned 1600 total points
ID: 23714759
If you have used AJAX extensions, there is an extension called "Masked Edit" that allows you to have a custom format for collecting data. Here's the link
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/MaskedEdit/MaskedEdit.aspx
0
 
LVL 16

Assisted Solution

by:TSmooth
TSmooth earned 400 total points
ID: 23714874
Your "Object not set to an instance of an object" error is probably coming because you don't have your code inside an if block that only runs when the formview is readonly mode. It's probably also running when the formview is in edit mode at which point that label doesn't exist as it's replaced by a textbox for entry. Therefore you need to move that code inside an if block that checks the currentmode of the formview control.

For your second issue, look at the Microsoft Ajax control toolkit. I believe it has a masked edit box that would do the trick. www.asp.net/ajax
0
 
LVL 1

Author Comment

by:megnin
ID: 23714916
Your right about the readonly mode.  I have:
        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.  
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:megnin
ID: 23715381
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?
0
 
LVL 21

Expert Comment

by:66866
ID: 23715400
Reference the AjaxControlToolkit DLL in your project and see if that helps
0
 
LVL 1

Author Comment

by:megnin
ID: 23715442
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.  ??
0
 
LVL 21

Expert Comment

by:66866
ID: 23715463
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.
0
 
LVL 1

Author Comment

by:megnin
ID: 23715469
I didn't think I had to install it if it's built into VS2008.
0
 
LVL 1

Author Comment

by:megnin
ID: 23715492
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.
0
 
LVL 21

Expert Comment

by:66866
ID: 23715497
VS 2008 supports AJAX Website (using UpdatePanels, UpdateProgress, etc) but for the toolkit, you'll have to download and install it.
0
 
LVL 1

Author Comment

by:megnin
ID: 23715507
Oh.  I think I've downloaded it.  If not I'll go get it from Microsoft.com.
0
 
LVL 1

Author Comment

by:megnin
ID: 23716011
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. &%^&*%&^$^%
0
 
LVL 21

Expert Comment

by:66866
ID: 23716031
In your solution, add a reference to the DLL that is present in the "Sample Website" folder under the "Bin" directory
0
 
LVL 1

Author Comment

by:megnin
ID: 23716043
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.
0
 
LVL 21

Expert Comment

by:66866
ID: 23716053
To "run" the solution means, debug and deploy it (by hitting F5).
0
 
LVL 1

Author Comment

by:megnin
ID: 23716056
Should I copy that dll somewhere a little more permanent that the bin directory of a "Sample Website" that I may delete tomorrow?
0
 
LVL 21

Expert Comment

by:66866
ID: 23716064
Yep, you can do that
0
 
LVL 1

Author Comment

by:megnin
ID: 23716085
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?
0
 
LVL 21

Expert Comment

by:66866
ID: 23716114
You can create a folder in your Program Files, called AJAXControlToolkit, and store it there
0
 
LVL 1

Author Comment

by:megnin
ID: 23716116
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.
0
 
LVL 1

Author Comment

by:megnin
ID: 23716120
Oh, yeah, I guess I should put it on my local PC rather than the Server. (or in addition to?)
0
 
LVL 21

Expert Comment

by:66866
ID: 23716142
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.
0
 
LVL 1

Author Comment

by:megnin
ID: 23716226
Oh, my dev environment is not exactlly right.  I dev right on the server by \\Server\C$\Inetpub\Website.  

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.
0
 
LVL 1

Author Closing Comment

by:megnin
ID: 31550259
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.
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question