Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
?
294 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

636 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