?
Solved

How do I get my ASP.NET page to retain the value when I select another dropdown control

Posted on 2015-02-23
6
Medium Priority
?
285 Views
Last Modified: 2015-02-25
Hi guys,

I have a small problem that is turning into a headache. I have a requirement whereby I need to have a dynamic input mask that is set based upon what has been selected prior. This part is done - I've achieved this through making use of the AjaxMaskedEdit control and retrieving the values from my SQL Server database.

When I type into the box I can see my delimiter such as "-" or a "/". The problem occurs when I select another dropdown control and change its value and when the page reloads 123-456 becomes 123456 and I need it to retain the "-". I've seen a few examples where a session may be the best way to go about it but I have had no such luck getting it to work as yet.

I suppose my question in a nutshell is how can I store the value after the focus is shifted from the control that I have given the masked input?

Thanks
0
Comment
Question by:ric134
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 10

Expert Comment

by:Najam Uddin
ID: 40626164
Can you attach/ place code here? I believe on post-back, AjaxMaskedEdit is losing format (which you pull from database) Store that information in session and set AjaxMaskedEdit formatting from those value on page load event.
0
 

Author Comment

by:ric134
ID: 40627840
Hi Najam,

Thanks very much for getting back to me. I've tried setting the mask this morning via the session however I'm not having much luck still. I've pasted some code below that I'm able to - perhaps I'm not setting the session correctly?

Protected Sub DDLAwarding_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDLAwarding.TextChanged
        

        If DDLAwarding.SelectedValue.ToString = "" Then
            DDLExamMethod_voc.Enabled = False
            ddlExamLevel_voc.Enabled = False
        Else
            DDLExamMethod_voc.Enabled = True
            DDLSchool_voc.Enabled = True
            'ddlExamLevel.Enabled = True
        End If
        txtExamCode.Text = ""
        'Method will change the value of the input mask based upon the id of the value in the 
        'awarding body dropdown 
        Dim dvSql As DataView = DirectCast(SqlInputMask.[Select](DataSourceSelectArguments.Empty), DataView)
        For Each drvSql As DataRowView In dvSql
            If drvSql("exam_code_input_mask").ToString = Nothing Then
                txtExamCode_MaskedEditExtender.Enabled = False
            Else
                txtExamCode_MaskedEditExtender.Enabled = True
                txtExam_MaskedEditValidator.Enabled = True
                txtExamCode_MaskedEditExtender.Mask = drvSql("exam_code_input_mask").ToString()
                Session("MASK") = txtExamCode_MaskedEditExtender.Mask


            End If
        Next
    End Sub
	
	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        

        If Not IsPostBack Then
            
            If Not Session("MASK") Is Nothing Then

                txtExamCode_MaskedEditExtender.Mask = Session("MASK")
           End If
		   
		   End If
End Sub

Open in new window


UPDATE:
Also when I click back into the textbox - my delimiter reappears. it is once I select another dropdown control and the page reload that I lose my delimiter.
0
 
LVL 10

Expert Comment

by:Najam Uddin
ID: 40628478
If Not IsPostBack Then            
     If Not Session("MASK") Is Nothing Then
                txtExamCode_MaskedEditExtender.Mask = Session("MASK")
     End If
End If

Open in new window

This code will execute only first time as you have put it in NOT PostBack, please try after taking this out.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ric134
ID: 40628588
Ah that was silly! sorry however my issue still exists when I put the code block below NOT postback. If I click into the text box, my delimiter reappears. Not really sure of other options at this point.
0
 
LVL 10

Accepted Solution

by:
Najam Uddin earned 2000 total points
ID: 40629170
try adding this to ClearMaskOnLostFocus="false" MaskedEditExtender control
0
 

Author Comment

by:ric134
ID: 40630139
Perfect. Thanks very much for helping me out with this. Really appreciate it.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

771 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