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
280 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
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 

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 500 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

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!

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 …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

726 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