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
271 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now