|
The following is the code for combobox along with its custom validator
<asp:ComboBox ID="cmbBusinessOwner" runat="server" MaxLength="0" DropDownStyle="DropDownList"
AutoCompleteMode="SuggestAppend">
<asp:ListItem Text="--Select--" Value="0" />
<asp:ListItem Text="HDFC Co-op" Value="1" />
<asp:ListItem Text="Limited Dividend Co-op" Value="2" />
<asp:ListItem Text="Rent Controlled" Value="3" />
<asp:ListItem Text="Rent Stablized" Value="4" />
<asp:ListItem Text="India" Value="5" />
<asp:ListItem Text="United" Value="6" />
<asp:ListItem Text="America" Value="7" />
<asp:ListItem Text="Mexico" Value="8" />
</asp:ComboBox>
<asp:CustomValidator ID="cvRequired" runat="server" ValidationGroup="Continue" ForeColor="Red"
ClientValidationFunction="cvComboBox_Validate" Text="Select Business Owner" Display="Dynamic"></asp:CustomValidator>
the script for cvComboBox_Validate function is
function cvComboBox_Validate(source, args) {
var ComboBoxCtrl = $find('cmbBusinessOwner');
if (ComboBoxCtrl.get_textBoxControl().value == "--Select--")
args.IsValid = false;
else
args.IsValid = true;
}
This code gives me the error message "Select Business Owner" next to the control on button click. But the message "Select Business Owner" fails to appear in validation summary.
My validation summary is as follows
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="false" EnableClientScript="true"
CssClass="validationsummary" ValidationGroup="Continue" DisplayMode="BulletList"
HeaderText="<div class='validationheader'> Please correct the following errors:</div>" />
Rest all the control on the page works fine except for this combobox.
Help will be greatly appreciated.
Thanks
|
|
|
|
|
It's been over 5 years since I've used one of those valicators, but on a dropdownlist, you have to add the default value to the validator for it to work on a dropdownlist. I don't remember the exact use, but I think it's
<asp:CustomValidator ID="cvRequired" runat="server" ValidationGroup="Continue" ForeColor="Red" defaultvalue="0"
ClientValidationFunction="cvComboBox_Validate" Text="Select Business Owner" Display="Dynamic"></asp:CustomValidator>
Without the default value, the validator has no clue what to validate.
|
|
|
|
|
Thanks for the reply.
The defaultvalue="0" does not work either.
The problem isn't that the validation does not work. It works fine. I see the message displayed next to the combobox control on button click.
The issue is that the validationsummary does not capture this custom validator.
|
|
|
|
|
[EDIT]
your missing the validation group on the combobox
[End of EDIT]
I've never used the validation summary, can't tell you why it doesn't work with the combo box.
All I can say is that you missing something, or mistyped a value like the validation group name.
I stopped using the validation controls about 4 years ago, because I found that they were unreliable, and got too many complaints about them. Across all the computers in the world, they just didn't work on all of them. Go Figure.
Now I do real time validation, in which I validate each time the field changes, and validate again before submission, and validate again on the server side. At the same time, I check for script injection, and correct values on the fly, or offer a list of suggestions.
All in Javascript.
|
|
|
|
|
real time validation --- sounds interesting..
can you given an example.... say with respect to a textbox..
how will you validate them with the different scenario you mentioned("I validate each time the field changes, and validate again before submission, and validate again on the server side. At the same time, I check for script injection, and correct values on the fly, or offer a list of suggestions.")
Thanks
|
|
|
|
|
i use jquery
I bind an event called blur to the textbox, when the user changes fields, the blur is fired, and validates the textbox. I can then format the data, if the value is not correct, then you can paint a red border around the entire area, and change the background color of the textbox.
A red border around the textbox is more visible and non-intrusive than a giant validation message.
A Jquery file designed to work with an update panel. It validate a textbox for an email address. This is one of the designs I use. I have many designs.
$(document).ready(function () {
initiateBinding();
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
});
function EndRequestHandler(sender, args) {
initiateBinding();
}
function initiateBinding() {
$(document).ajaxStart(function () {
});
$(document).ajaxStop(function () {
});
$('[id*="_txt_Email_Jquery_FriendsName_Field"]').blur(function() {
validate_Email();
});
}
function validate_Email() {
var validation_Flag = true;
var txtFocus;
var txtError;
txtFocus = $('[id*="_txt_Jquery_txtFocus"]').val();
txtError = $('[id*="_txt_Jquery_txtError"]').val();
var friendsName_length;
friendsName_length = $('[id*="_txt_Email_Jquery_FriendsName_Field"]').val().length;
if (friendsName_length < 2) {
$('[id*="_txt_Email_Jquery_FriendsName_Field"]').css('background-color', txtFocus).fadeOut("slow");
$('[id*="_txt_Email_Jquery_FriendsName_Field"]').css('background-color', txtError).fadeIn("slow");
$('[id*="_img_Email_Jquery_FriendsName_Error"]').delay(800).fadeIn(300).show("normal");
validation_Flag = false;
}
else if (friendsName_length > 2) {
$('[id*="_txt_Email_Jquery_FriendsName_Field"]').css('background-color', txtError).fadeOut("slow");
$('[id*="_txt_Email_Jquery_FriendsName_Field"]').css('background-color', txtFocus).fadeIn("slow");
$('[id*="_img_Email_Jquery_FriendsName_Error"]').fadeOut(500).hide("normal");
}
var emailAddress_length;
emailAddress_length = $('[id*="_txt_Email_Jquery_EmailAddress_Field"]').val().length;
if (emailAddress_length < 2) {
$('[id*="_txt_Email_Jquery_EmailAddress_Field"]').css('background-color', txtFocus).fadeOut("slow");
$('[id*="_txt_Email_Jquery_EmailAddress_Field"]').css('background-color', txtError).fadeIn("slow");
$('[id*="_img_Email_Jquery_EmailAddress_Error"]').delay(800).fadeIn(300).show("normal");
validation_Flag = false;
}
else if (emailAddress_length > 2) {
$('[id*="_txt_Email_Jquery_EmailAddress_Field"]').css('background-color', txtFocus).fadeIn("slow");
$('[id*="_img_Email_Jquery_EmailAddress_Error"]').fadeOut(500).hide("normal");
var re_EmailAddress = new RegExp("\\w+([-+.']\\w+)*@\\w+([-.]\w+)*\\.\\w+([-.]\\w+)*");
var txt_EmailAddress_Validate = $('[id*="_txt_Email_Jquery_EmailAddress_Field"]').val();
var match_EmailAddress = re_EmailAddress.exec(txt_EmailAddress_Validate);
if (match_EmailAddress == null) {
$('[id*="_txt_Email_Jquery_EmailAddress_Field"]').css('background-color', txtFocus).fadeOut("slow");
$('[id*="_txt_Email_Jquery_EmailAddress_Field"]').css('background-color', "#C6DEFF").fadeIn("slow");
$('[id*="_img_Email_Jquery_EmailAddress_Error"]').delay(800).fadeIn(300).show("normal");
$('[id*="_lbl_Email_Jquery_EmailAddress_Label"]').text("Your format is not valid! (eg. someone@domain.com)").delay(800);
validation_Flag = false;
} else if (match_EmailAddress !== null) {
$('[id*="_txt_Email_Jquery_EmailAddress_Field"]').css('background-color', txtFocus).fadeIn("slow");
$('[id*="_img_Email_Jquery_EmailAddress_Error"]').fadeOut(500).hide("normal");
$('[id*="_lbl_Email_Jquery_EmailAddress_Label"]').text("Enter your friends email address:").delay(500);
}
}
if (validation_Flag == true) {
$('[id*="_txt_Jquery_Approved"]').val("jquery_approved");
}
else {
$('[id*="_txt_Jquery_Approved"]').val("jquery_declined");
}
}
|
|
|
|
|
Thanks jkirkerx. I have no idea about J quey. But this gives me some idea as to what this code intends to do. I will do some research on what you suggested. Probably could incorporate in my project.
Appreciate it.
|
|
|
|
|
All the asp.net validation controls do is load some javascript or microsoft jscript, and run the regex that you assign to it against the textbox value. Then they display some text via javascript, with the text message you assign to it.
Computer users are not that smart, although they think there smart, and the UI (user interface) will become your biggest challenge. Writing a page application is half the battle, the easiest part. The hardest part is validating the form before submission.
If you can't convey the errors to let's say your mom, then the program is partially useless.
|
|
|
|
|
i get error in IE 8 for the code bellow (but it work in IE9)
<script type='text/javascript'>alert('Saved Successfully !')</script><script language='JavaScript'> window.location('../../Personal/View/Default.aspx');</script>
<script type="text/javascript">
the error is :
Message: Object doesn't support this action<br />
Line: 236<br />
Char: 2<br />
Code: 0<br />
URI: http://192.168.0.110:8080/crm/WorkFlows/Forms/WorkReport/default.aspx?md=new&operation=4<br />
thanks in advanced!
modified 14-Aug-12 0:35am.
|
|
|
|
|
Hi,I have Done That!
string url = "../../Personal/View/Default.aspx";
string jScriptValidator = "<script>";
jScriptValidator += "window.open('" + url + "','_self')";
jScriptValidator += " </script>";
page.ClientScript.RegisterStartupScript(typeof(Page), "regJSval", jScriptValidator);
|
|
|
|
|
Error executing child request for new_Page.aspx.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Error executing child request for new_Page.aspx.
Source Error:
Line 14: Server.Transfer("new_Page.aspx");
Above is the error found. It works fine in local host but not when I trying to run in on virtual directory.
When I deleted the Export Excel Function in my page, the error gone.
Microsoft.Office.Interop.Excel.Application xlApp =
new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook xlWorkbook = xlApp.Workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
Microsoft.Office.Interop.Excel.Sheets xlSheets = null;
Excel.Worksheet xlWorksheet = null;
Anyone know how to fix this?
|
|
|
|
|
Not sure, are you getting this error: "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack." ?
|
|
|
|
|
No.
I think it might because of the server doesn't have excel library??
I have no idea how to fix this.
|
|
|
|
|
Member 9169887 wrote: I think it might because of the server doesn't have excel library??
Correct.
Member 9169887 wrote: I have no idea how to fix this.
Install the Excel-interop libraries.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
can you deploy Excel ddl to application path or install Excel InteropServices
-Vijay
|
|
|
|
|
Yes, I can.
I guess the question should rather be "how do I". Answer is on MSDN[^].
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
I have the following table:
<asp:Table runat="server">
<asp:TableRow ID="headerROW">
<asp:TableCell></asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="contentROW">
<asp:TableCell></asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="footerROW">
<asp:TableCell></asp:TableCell>
</asp:TableRow>
</asp:Table>
I want to know how can bring the footerRow to the absolute bottom of the page when the contentROW is less than the page height?
|
|
|
|
|
how to diplay data into a gridview on selecting a value from a dropdownlist.the dropdownlist has set of values.when i select one value,the details based on that value should be displayed in a dropdownlist
M.Sravani
|
|
|
|
|
I am not sure what you expect from such a vague description of your problem. When the index selected changes for your dropdownlist, get the values from where ever you are storing them and then display them in the grid.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
sorry.i got the answer.thank you
|
|
|
|
|
Aoa friendz,i am a beginner in Asp.net.i have been given a task that is how to extrack an image from an email and save it on a disk.so intially help me how to start..how to send an image to an email account in asp.net.i have to use google server i-e my gmail account.
|
|
|
|
|
|
I have a question about what is the best way of setting up session variable(s) in the following situation for a change I am making to a C# web form application.
Currently when the users enter a specfic transaction code that = '123', a property of a textbox is set to visible and the user can enter a comment that is up to 20 characters long. Now the user want to be able to enter a comment that can be up to 15,000 characters.
To accomodate this request, I am going to make a change where the user will be pointed to a new web form page where the user can enter the information. Once the user has entered the information, they will click the save button and will be taken back to the orginal screen they started on.
**Note: A new web form page is going to be generated since there is not enough room on the orginal page to enter the information.
When the user clicks the 'save' button and return to the original web page, I am not going to update the database at that time. I want to pass the transaction id (unique identifier) and the new text field that is up to 15,000 characters back to the original web page as session variable(s). Once the user is on the original web page, I will take the session variable that is up to 15,000 characters and update the database in the same manner the database is currently updated.
Thus can you tell me if using session variables in the case listed abover is a good idea? Why or why not?
Also if there is a better way to accomplish this goal, can you tell me what the better method would be?
|
|
|
|
|
Displaying a new web page just to get an additional field may hinder the user experience. I would suggest that start looking for alternatives like AJAX popups or jQuery popups that dynamically show popups in the same page using visual effects rather than opening new pages. Sharing a field withing the same page is also much easier compared to sharing it between two pages.
|
|
|
|
|
Hi,
I have an asp.net WCF Service, my client application is going to send me excel file as byte array. I have to read those bytes and upload data in the database.
Microsoft Jet, or Ace drivers take the excel file name, is there any way that I can read those excel file bytes directly without storing the file in my file system.
Thanks in advance.
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|