?
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
?
301 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
  • 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
Technology Partners: 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month15 days, 22 hours left to enroll

850 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