Solved

Validate Range between 2 dropdown boxes

Posted on 2009-05-14
7
348 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
  • 3
  • 3
7 Comments
 
LVL 10

Expert Comment

by:MaxOvrdrv2
Comment Utility
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
Comment Utility
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
Comment Utility
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
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:SOS_Helpdesk
Comment Utility
Could a custom-Validator do the trick?
0
 
LVL 10

Accepted Solution

by:
MaxOvrdrv2 earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Custom Validator worked quite nicely.  just finished setting it up, took approximately 20 minutes.  Thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

10 Experts available now in Live!

Get 1:1 Help Now