[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Validate Range between 2 dropdown boxes

Posted on 2009-05-14
7
Medium Priority
?
355 Views
Last Modified: 2012-05-07
Hi Experts,
 I have 2 dropdownlists in my webpart.   (project start and project end).  Each dropdown contains integers, which represent years. (ie, 2008, 2009, 2010, etc)

I need to ensure that projects dont span more than 10 years with a validator control.
I've been trying to use rangeValidator, but it gets confused between postbacks and isn't working.

Any ideas?




0
Comment
Question by:SOS_Helpdesk
[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
7 Comments
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 24385023
why don't you simply validate it either server-side or client-side? i don't like validators :S

simply check it.
0
 

Author Comment

by:SOS_Helpdesk
ID: 24385091
Ah cmon, thats no fun!
Forever trying to get a handle on these .NET controls.

If nobody else can help, i'll have to do it manually and will award points.

Thanks,
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 24385119
i think the rang validators only work on textboxes... e.g.: range in text should be between 1 and 100... doesn't check 2 controls...
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:SOS_Helpdesk
ID: 24385165
Could a custom-Validator do the trick?
0
 
LVL 10

Accepted Solution

by:
MaxOvrdrv2 earned 2000 total points
ID: 24385311
yes, but it would come back to doing it manually... the only thing is that you would put the validation code inside the validator block and not directly in your save/submit function... that would be the only difference really... but yes, you can do that.
0
 
LVL 3

Expert Comment

by:channa_m
ID: 24386992
You can use a dummy textbox to store the value of difference and apply the range validator on the textbox

See below
 <form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="ddlStartDate" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList_SelectedIndexChanged">
                <asp:ListItem>2008</asp:ListItem>
                <asp:ListItem>2009</asp:ListItem>
                <asp:ListItem>2010</asp:ListItem>
                <asp:ListItem>2007</asp:ListItem>
            </asp:DropDownList>
            <asp:DropDownList ID="ddlEndDate" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList_SelectedIndexChanged">
                <asp:ListItem>2008</asp:ListItem>
                <asp:ListItem>2009</asp:ListItem>
                <asp:ListItem>2010</asp:ListItem>
                <asp:ListItem>2007</asp:ListItem>
            </asp:DropDownList>
            <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="TextBox1"
                ErrorMessage="RangeValidator" MaximumValue="10" MinimumValue="0" Visible="false"></asp:RangeValidator>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div>
    </form>
 
 
 
 
protected void DropDownList_SelectedIndexChanged(object sender, EventArgs e)
    {
        TextBox1.Text = Convert.ToInt32(ddlStartDate.SelectedValue) - Convert.ToInt32(ddlEndDate.SelectedValue);
    }

Open in new window

0
 

Author Closing Comment

by:SOS_Helpdesk
ID: 31581445
Custom Validator worked quite nicely.  just finished setting it up, took approximately 20 minutes.  Thanks!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
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…

649 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