Solved

Asp.net Dropdownlist border color not changing in case of iis7.

Posted on 2013-01-31
7
1,220 Views
Last Modified: 2013-03-01
Hi,

I am using asp.net dropdownlist and custom validator and if the dropdownlist is having nothing selected, then on button submit, I am changing the border color of dropdownlist from grey to red.

border color not changing in IIS7.

<asp:DropDownList ID="ddlScriptType" CssClass="Dropdown-Admin-req" AppendDataBoundItems="true" runat="server" DataSourceID="ScriptTypeDataSource" DataTextField="TypeName" DataValueField="ScriptType_ID" SelectedValue='<%# Bind("ScriptType_ID")%>' Width="100px"
BorderStyle="Solid" BorderWidth="1pt"    >
<asp:ListItem > </asp:ListItem>
</asp:DropDownList>
<asp:CustomValidator ID="cvScriptType" runat="server" ErrorMessage=""  ControlToValidate="ddlScriptType" ClientValidationFunction="ValidateDDScriptType"  
    OnServerValidate="CustomValidatorDDScriptType_ServerValidate"  ValidateEmptyText="True"></asp:CustomValidator>


       function ValidateDDScriptType(source, args) {
           var is_valid1 = $("#ddlScriptType").val() != "";
           $("#ddlScriptType").css("background-color", is_valid1 ? "white" : "#FFEEEE");
           $("#ddlScriptType").css("border-color", is_valid1 ? "#cccccc" : "#FF0000");
           args.IsValid = is_valid1;
       }

   protected void CustomValidatorDDScriptType_ServerValidate(object source, ServerValidateEventArgs args)
    {
        try
        {
            FormViewRow row = InsertScriptFormView.Row;
            DropDownList ddScriptType = (DropDownList)row.FindControl("ddlScriptType");
            bool is_valid1 = ddScriptType.SelectedValue != "";
            System.Drawing.Color selcolor = System.Drawing.ColorTranslator.FromHtml("#cccccc");
            System.Drawing.Color selbordercolor = System.Drawing.ColorTranslator.FromHtml("#FF0000");
            System.Drawing.Color selbackgroundcolor = System.Drawing.ColorTranslator.FromHtml("#FFEEEE");
            ddScriptType.BackColor = is_valid1 ? System.Drawing.Color.White : selbackgroundcolor;
            ddScriptType.BorderColor = is_valid1 ? selcolor : selbordercolor;
            args.IsValid = is_valid1;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }//CustomValidatorDDScriptType_ServerValidate

Open in new window

0
Comment
Question by:Saroj13
7 Comments
 
LVL 11

Expert Comment

by:mcnute
Comment Utility
This is nothing related to your webserver, since this is javascript and is happening clientside.

Change your jquery accordingly:

 function ValidateDDScriptType(source, args) {
           var is_valid1 = $("#ddlScriptType").val();
           if (is_valid !='') {
                   $("#ddlScriptType").css("background-color",  "white");
                   $("#ddlScriptType").css("border-color", "#cccccc");
           } else {
                    $("#ddlScriptType").css("background-color", "#FFEEEE");
                    $("#ddlScriptType").css("border-color", "#FF0000");
           }
           args.IsValid = is_valid1;
       }

Open in new window

0
 

Author Comment

by:Saroj13
Comment Utility
If i use iis8, then border color of dropdownchange from greyto red
0
 

Author Comment

by:Saroj13
Comment Utility
Sorry I meant to say dropdown border color not change if I use IE7. If IE browser is IE8, then its fine.
0
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

 
LVL 41

Expert Comment

by:guru_sami
Comment Utility
0
 

Author Comment

by:Saroj13
Comment Utility
Hi,

In IE8 , its working perfectly fine.

I am using IE7, dropdownlist border not changing from grey to RED.
0
 
LVL 41

Expert Comment

by:guru_sami
Comment Utility
Yes but try those solutions for IE7 as well.
0
 
LVL 20

Accepted Solution

by:
informaniac earned 500 total points
Comment Utility
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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 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

11 Experts available now in Live!

Get 1:1 Help Now