Web Forms :: Custom Validation Of Two Controls As A Unit?

Sep 28, 2010

How can we implement a custom validation of two controls as a unit, say a picture upload control and a dropdown ("0", ""100", "200") for the width of the picture display.

View 1 Replies


Similar Messages:

How To Make Sure That CreateChildControls () Method Is Called When Unit Testing Custom .NET Web Controls

Feb 10, 2010

I want to unit test my rendering engine for an ASP.NET app. I have some custom controls created in that app. Most of those control rely on having CreateChildControls() method called by the ASP.Net engine wheather during initial call or a postback.When running a test CreateChildControls() does not get called and the control is in an "invalid" state.

As a workaround to get the tests going I explicitly call some other public method that calls EnsureChildControls() in it. This in effect causes CreateChildControls() to be executed and the control being initialized properly (just as it would normally when hosted on web server). I would like to get rid of that extra method call and the control to still be in a proper state for testing.

View 1 Replies

Custom Server Controls :: Custom Validator Client-side Validation Cannot Work?

Jan 13, 2010

I've been trying to get a custom validator component working that ensures at least one checkbox from a checkboxlist has been checked. I've been used some code I found on dotnetjunkies.com but the client-side validation didn't work. I've been attempting to modify it to get the client-side javascript validation to work with no luck. Basically, I compile the below code into a DLL and add it to my bin folder.

[Code]....

View 2 Replies

Custom Server Controls :: Custom Control Causing Validation?

May 25, 2010

I've got a custom control with asp:hyperlinks that's causing validation which I don't want... Is there anyway I can stop this from happening?

View 1 Replies

How To Unit Test For Turning Off Request Validation

Dec 20, 2010

I created a little web service to minify JavaScript, and everything was nice, with all my tests passing. Then I noticed a bug: if I tried to minify alert('<script>');, it would throw a HttpRequestValidationException.

So that's easy enough to fix. I'll just add [AllowHtml] to my controller. But what would be a good way to unit test that this doesn't happen in the future?

The following was my first thought:

[TestMethod]
public void Minify_DoesntChokeOnHtml()
{
try
{
using (var controller = ServiceLocator.Current.GetInstance<MinifyController>())
{
return controller.Minify("alert('<script></script>');");
}
}
catch (HttpRequestValidationException)
{
Assert.Fail("Request validation prevented HTML from existing inside the JavaScript.");
}
}

However, this doesn't work since I am just getting a controller instance and running methods on it, instead of firing up the whole ASP.NET pipeline.

What would be a good unit test for this? Maybe reflector on the controller method to see if the [AllowHtml] attribute is present? That seems very structural, and unlikely to survive a refactoring; something functional might make more sense.

View 1 Replies

C# - Unit Testing Custom BuildProvider?

Feb 18, 2011

How can BuildProvider's GenerateCode method be tested. I created a BuildProvider and now I want to unit test it. Is it possible? Initial question was not clear enough. I don't want to stub AssemblyBuilder, I want to mimic asp.net request. I want to make sure that VirtualPathProvider and BuildProvider work fine together.

One more clarification, I am not really interested in generated code from build provider, it is used only to kick-start compilation in medium-trust environment, I already have a code, I need build provider just so I could compile since CodeDomProvider is not accessible directly in medium trust.

public override void GenerateCode(AssemblyBuilder assemblyBuilder)
{
string outputName = VirtualPath.Substring(VirtualPath.LastIndexOf('/') + 1);
outputName = outputName.Substring(0, outputName.LastIndexOf('.'));
_compilationContext = (CompilationContext)HttpContext.Current.Items[outputName];
var tw = assemblyBuilder.CreateCodeFile(this);
tw.Write(_compilationContext.Content);
tw.Flush();
foreach (var assembly in CompilerServices.GetLoadedAssemblies().Where(a => !a.IsDynamic))
assemblyBuilder.AddAssemblyReference(assembly);
}

View 1 Replies

MVC :: Unit Testing Custom RequestValidator For Class?

Jun 30, 2010

I wrote a custom RequestValidator implementation to deal with W.I.F. security tokens. Now I am trying to write a unit test for this class. This method is protected internal. Even using InternalsVisibleToAttribute, I am having no luck being able have my unit test compile against my implementation of:

bool
IsValidRequestString(HttpContext context,
string value, RequestValidationSource rvs,
string
collectionKey, out
int validationFailureIndex)

2. The HttpContext class used by this method is sealed so I am not sure how to mock one up with a mocking framework (i.e. rhinomocks in my case).

View 11 Replies

Web Forms :: Validation With Custom Controls Client-Side

Jan 14, 2010

I have a custom control which I need to be able to operate with the validation controls available within asp.net. I would like the message to be shown to the user client-side so as not having to wait for a postback each time.I have the ValidationPropertyAttribute("value") set at the top of the control. However it is still being completely ignored by the validation controls. I have found the following from microsoft, but I'm not sure I'm interpreting it correctly, could someoneIn order to be referenced by a validation control, a control must have a validation property. All controls that can be validated have a ValidationPropertyAttribute, which indicates which property should be read for the purposes of validation. If you write your own control, you can make it take part in validation by providing one of these attributes to specify which property to use.

View 3 Replies

MVC :: Unable To Unit Test The Custom Action Filter

Jul 17, 2010

I have a custom actionfilter that strips out the whitespaces before the html is rendered in browser and it is working fine. However I have been unable to unit test the custom action filter. Ideally I want to do an assert on the sample html that all whitespaces have been removed. Code looks something like this.

[Code]....

View 1 Replies

Unit Test An UrlHelper Custom Helper Method?

Mar 10, 2011

I am using ASP.NET MVC 3 and NUnit. I am trying to write a unit to test one of my helper methods. Here it is:

public static class UrlHelperAssetExtensions
{
private static readonly string yuiBuildPath = "http://yui.yahooapis.com/2.8.2r1/build/";
public static string YuiResetFontsGridsStylesheet(this UrlHelper helper)
{
return helper.Content(yuiBuildPath + "reset-fonts-grids/reset-fonts-grids.css");
}
}

Here is my unit test:

[Test]
public void YuiResetFontsGridsStylesheet_should_return_stylesheet()
{
// Arrange
RequestContext requestContext = new RequestContext();
UrlHelper urlHelper = new UrlHelper(requestContext);
// Act
string actual = urlHelper.YuiResetFontsGridsStylesheet();
// Assert
string expected = yuiBuildPath + "reset-fonts-grids/reset-fonts-grids.css";
Assert.AreEqual(expected, actual);
}....................................

View 2 Replies

Forms Data Controls :: Custom Validation Of Gridview Row When Checkbox Selected?

Jan 29, 2010

I want to validate a GridView row only if the checkbox is selected.

My page contains a gridview and 1 button, I have used custome template for few fields in GridView. All fields are currently validated using requiredfield validator.

The validation workd fine when I click the button, but now I want custome validation, means only the rows which are selected shoud be validated.

I have inserted one more column with checkbox.

View 6 Replies

MVC :: Register Client-side Validation For Custom Validation Attribute?

May 19, 2010

I am trying to create a custom password validation attribute which has these requirements

1. cannot be empty.

2. doesn't contain space or other special chracters, which I'll define later.

3. length is between 6 - 12

[Code]....

it works fine on the server-side but I'd like to make this work on the client side as well, so I created a PasswordAttributeAdapter class

[Code]....

and in global.asax I added

[Code]....

View 6 Replies

MVC :: Custom Validation Attribute Is Not Called By Validation Mechanism?

Aug 28, 2010

Custom Validation Attribute is not called by validation mechanism?

[Code]....

ViewModel

[Code]....

View 3 Replies

Forms Data Controls :: Javascript Validation For Assigning Validation Group To Validation Summary On Datalist Item Click?

Dec 25, 2010

I am using one datalist control for uploading multiple images.I hv used one Asp:FileUplaod Control and one button in one itemtemplate.I am using reqired field validator and regular expression validator for file upload cntrl I am assigning validation group for both of them on ItemDataBound event of my datalist so that each upload cntrl hv same validaton group as required field and regular expression validator.Now what i want to do is - i want to show my error message in validation summary which is right at the top of the page.I want one know how to write javascript that will assign validation group of my control in datalist on which i click ?

View 1 Replies

Validation - Adding Custom Valiadtion To .NET Controls

Apr 14, 2010

We're trying to build a simple asp control for some clients where they can just drop in a single block -i.e.

<captcha:CaptchaControl ID="CaptchaControl1"
runat="server"
Server="http://localhost:51947/"
/>

and have it render the control. The catch is that I can't get this to include custom validation. Right now I'm using the RenderContents function to display the layout of the control itself as well as hook it up the to Javascript. The problem is that I don't know how to get custom validation to fire when used as part of a control.

[code]...

View 2 Replies

How To Go For Custom Validation Control And When To Do Validation In Javascript

Mar 12, 2010

When to go for custom validation control and when to do validation in javascript? What are pros and cons of each of them?

View 3 Replies

Unit Testing Error - The Unit Test Adapter Failed To Connect To The Data Source Or To Read The Data

May 6, 2010

I'm using VSTS 2K8 and I've set up a Unit Test Project. In it, I have a test class with a method that does a simple assertion. I'm using an Excel 2007 spreadsheet as my data source.

My test method looks like this:

[Code]....


As indicated in the method decoration attributes, my Excel spreadsheet is on my local C:/ Drive. In it, the sheet where all of my data is located is named "Sheet1".I've copied the Excel spreadsheet into my project and I've set its Build Action = "Content" and I've set its Copy to Output Directory = "Copy if Newer".

When trying to run this simple unit test, I receive the following error:

The unit test adapter failed to connect to the data source or to read the data. For more information on troubleshooting this error, see "Troubleshooting Data-Driven Unit Tests" (http://go.microsoft.com/fwlink/?LinkId=62412) in the MSDN Library. Error details: ERROR [42S02] [Microsoft][ODBC Excel Driver] The Microsoft Office Access database engine could not find the object 'Sheet1'. Make sure the object exists and that you spell its name and the path name correctly.

I've verified that the sheet name is spelled correctly (i.e. Sheet1) and I've verified that my data sources are set correctly.Web searches haven't turned up much at all.
[Code]....

View 5 Replies

Web Forms :: Custom Validation For Email?

Apr 3, 2010

I am creating a system in visual web developer. I want to use the custom validation to validate an email address.I am using Visual basic to do it in.so far i have

Dim ampposition As Integer
Dim dotposition As Integer
For i = 1 To Len(txtemail.Text)
Next

As i want to use a for loop to validate the email

View 4 Replies

Web Forms :: Setting Up Custom Validation With VB Code-Behind?

Mar 3, 2011

I am trying to set up my first custom validator in VS 2010 VB. I want it to use a Sub or Function that is in my code-behind. I have searched the WEB but the instructions and examples that I have found do not show me how to use code-behind.

The main problem that I am running into is that I can not find a way to connect the validator to a sub that preforms the validation check.

View 3 Replies

Web Forms :: Dropdown List & Textbox Custom Validation

Mar 19, 2011

We have a page with quite a few textboxes and a dropdown list at the end. The dropdown list at the end is a "Result" and dependant on the result certain textboxes need to be filled in and this needs to be checked when they submit the page. I was thinking of using a custom validator

View 3 Replies

Web Forms :: Custom Validation Only Works For FileUpload Control

Oct 12, 2010

I have 2 custom validator controls on my page but for some strange reason the Custom Validator for FileUpload control works and the custom validator for TextBox control does not work. Here is the aspx code:

<asp:FileUpload ID="_fileCv" runat="server" Width="500px" /><br />
<asp:RequiredFieldValidator ID="_rfvFileCv" runat="server" ErrorMessage="Resume; " ControlToValidate="_fileCv" SetFocusOnError="True" ValidationGroup="APPLY">
<img src="images/mandatory.gif" alt="Required" /></asp:RequiredFieldValidator
<asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="_fileCv"
ErrorMessage="Max file size for documents is 4MB." OnServerValidate="CustomValidator1_ServerValidate" ValidationGroup="APPLY"></asp:CustomValidator>
<asp:TextBox ID="_txtHealthComments" runat="server" TextMode="MultiLine" Rows="5" Width="500" />
<asp:CustomValidator ID="CustomValidator2" runat="server" ControlToValidate="_txtHealthComments"
ErrorMessage="Kindly enter health Comments ." OnServerValidate="CustomValidator2_ValidateHealth" ValidationGroup="APPLY"></asp:CustomValidator>

Here is the code behind:
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args) {
if (_fileCv.FileBytes.Length > 4194304) {
args.IsValid = false;
} else { args.IsValid = true; } }
protected void CustomValidator2_ValidateHealth(object source, ServerValidateEventArgs args) {
if (_rdoHealth.SelectedValue == "1" && _txtHealthComments.Text == "") {
args.IsValid = false; } else { args.IsValid = true; } }

View 1 Replies

Web Forms :: Custom Validation, Show Message But Run Some Code?

Jan 10, 2011

I have web form in c# asp.net. I have an textbox where the user can enter some part number. When he click on the search button I would like to do some validation of the search text. It is not possible to use the following charachters (- _ / . spaces). When the custom validation found one of these characters I would like to show some error message (It is not possible to use one of these special characters: -, _, /, , . and spaces.). And than I would like to remove the special characters from the search text and execute a method to search.Can I do it with a custom validation like:

<asp:textbox id="TextBox1" runat="server"></asp:textbox><asp:CustomValidator id="CustomValidator1" runat="server" OnServerValidate="TextValidate" ControlToValidate="TextBox1" ErrorMessage="It is not possible to use one of these special characters: -, _, /, , . and spaces."></asp:CustomValidator>
protected void TextValidate(object source, ServerValidateEventArgs args){ args.IsValid = (args.Value.Contains(""); string newSearchValue = // remove the special characters -, _, /, , . and spaces. // Run the search method without the special character, but show a error message search(newSearchValue);}

View 2 Replies

Web Forms :: Password Field Validation Using Custom Validator?

Jan 12, 2010

How can validate Password field using Custom validater control in asp.net 2.0 ?

View 1 Replies

Data Controls :: File Type And Extension Validation For Multiple File Upload Controls Using Custom Validator

May 7, 2015

I was referring muddasar's one of the article for the validation. Below is my code and i am trying to validate the file upload selected file format on the submit button. I have 4 upload control and  fu1 is mandatory field and others are not mandatory fields. Though i need to validate all the four uploads if the files have been selected. My full sample code is below for easy testing,

<asp:FileUpload runat="server" ID="fu1" />
<asp:Label ID="lblMessage1" runat="server"></asp:Label>
<asp:FileUpload runat="server" ID="fu2" />
<asp:Label ID="lblMessage2" runat="server"></asp:Label>

[code]...

I am doing slight mistake on the return to the main function. if i test indvidual function it works fine. whereas if i include the 4 functions in one function  with the return statement, it's not validating. goes to to the server.

View 1 Replies

Web Forms :: Custom Login Control In Masterpage With Coded User Validation?

Jan 17, 2010

I have a little doubt about creating a login control in the master page within a contentplaceholder.

What i want is to create my own login control in the masterpage, using a loginview inside a contentplaceholder. The code is the following:

[Code]....

So far so good, but now i want to create the logic to do the actual login. In a regular aspx page i'll do it in the cmdlogin click event, but as i'm in the masterpage, i'm not sure if i can do that. I actually tried to do it in the code behind of the masterpage, but it didn't work. What can do?? do i ahve to use the asp.net login control?

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved