How to use webdings character map in asp.net - asp.net

I want to use webdings characters in .net application.
Does anyone know how to do this.
I tried using :
ASPX:
<asp:Label ID="lblSample" runat="server" Font-Names="Webdings" ></asp:Label>
CODE BEHIND:
lblSample.Text = "0x61"
But it doesn't displaying properly.

As can be seen in any ASCII table, character 0x61 is a lower case a.
You are trying to output the string "0x61" instead of a lower case a.
You should be doing this:
lblSample.Text = "a"

Related

regular expression for this format 00-0000000

<td><asp:RegularExpressionValidator ID="rev" runat="server" ControlToValidate="registry_no"
ErrorMessage="Invalid Format!" ForeColor="#a90329" Font-Size="Small" ValidationExpression="/^\d+(-\d+)*$/"/></td>
regular expression for this format 00-0000000
i want to validate the user textbox input , the format should be like this one : 00-0000000, two digits followed by a dash , followed by 7 digits .
thanks
You can specify the exact number of repetitions with braces, like so:
^\d{2}-\d{7}$

ASP.NET File Upload Validation

I have a requirement to do multiple validations on a file upload control. I have the following code for now:
<asp:Button id="btnUploadFile" class="ms-ButtonHeightWidth" runat="server" OnClick="UploadFile_Click" Text="Upload File"></asp:Button>
<asp:RequiredFieldValidator ID="InputFileValidator" ControlToValidate="InputFile" Text="You must specify a value for the required field" runat="server" />
I need to add this ^(?!..)(?!...)(?=.[^.]$)[^\"#%&:<>?\/{|}~]{1,128}$ Regex validation from here in addition to the required field validator. How do I do this?
UPDATE:
You could probably adapt the regex instead to allow for backslashes up to the filename and disallow them in the filename, but the complexity of such a beast would not likely be worth the time and effort to construct it.
Since the original regex was for validating a textbox where the user was typing a filename (and not a file input where the name is generated by the OS), I think the better course of action would be to use an <asp:CustomValidator> control instead and split the value on \ to get more easily parseable chunks.
The primary advantage of this approach is that you can break that complex regex down into multiple simpler (and more easily understood) regexes and test them one at a time against the filename.
<script type="text/javascript">
var validateFile = function validateFile(sender, args) {
'use strict';
var fileWithPath, //split on backslash
fileName = fileWithPath[fileWithPath.length - 1], //grab the last element
containsInvalidChars = /["#%&*:<>?\/{|}~]/g, //no reason to include \ as we split on that.
containsSequentialDots = /[.][.]+/g, //literal .. or ... or .... (etc.)
endsWithDot = /[.]$/g, // . at end of string
startsWithDot = /^[.]/g, // . at start of string
notValid = false, //boolean for flagging not valid
valid = fileName.length > 0 && fileName.length <= 128;
notValid = containsInvalidChars.test(fileName);
notValid = notValid || containsSequentialDots.test(fileName);
notValid = notValid || endsWithDot.test(fileName);
notValid = notValid || startsWithDot.test(fileName);
args.IsValid = valid && !notValid;
};
</script>
<asp:FileUpload ID="InputFile" runat="server" />
<asp:RequiredFieldValidator ID="rqfvInputFile" runat="server" ControlToValidate="InputFile" ErrorMessage="File is required"></asp:RequiredFieldValidator>
<asp:CustomValidator ID="cstvInputFile" runat="server" ControlToValidate="InputFile" ClientValidationFunction="validateFile" ErrorMessage="File is not a sharepoint file"></asp:CustomValidator>
<asp:Button ID="Button1" runat="server" Text="Button" />
One caveat to the above is that the filename chunks are split on \, which is not likely to be the path separator for Unix or Mac systems. If you need this to run on those clients as well, you'll likely have to split on either \ or / which you should be able to do with this:
var filePath = args.Value.split(/\\|\//g); //not tested.
ORIGINAL:
Add in an <asp:RegularExpressionValidator> control and set the ControlToValidate property to your file uploader control.
You can have as many validator controls as you like pointed towards a single input.
Just set the appropriate properties (such as the ValidationExpression in the <asp:RegularExpressionValidator>) and make sure the ControlToValidate property is pointed towards the input to validate.
Example:
<asp:Button id="btnUploadFile" class="ms-ButtonHeightWidth" runat="server" OnClick="UploadFile_Click" Text="Upload File"></asp:Button>
<asp:RequiredFieldValidator runat="server" ID="RequiredInputFileValidator" ControlToValidate="InputFile" Text="You must specify a value for the required field" />
<asp:RegularExpressionValidator runat="server" ID="RegexInputFileValidator" ControlToValidate="InputFile" ErrorMessage="Only valid SharePoint files are allowed."
ValidationExpression="^(?!..)(?!...)(?=.[^.]$)[^\"#%&:<>?\/{|}~]{1,128}$" />
You may also want to look into Validation groups

zipcode regular expression validation

I would like to have a regular expression validator for validating zip code. My zip code length varies up to 9 digits. User can enter either 5 or 9. I should valid if he enters 5 digits or 9 digits. Any thing other than that I would like to raise error.
I tried this expression
ValidationExpression="\\d{5}(-\\d{4})?$"
This is my design I am using rad controls
<telerik:RadMaskedTextBox Mask="#####-####" runat="server" ID="txtcontactZipCode"
Width="200px" ValidationGroup="contactValidation">
</telerik:RadMaskedTextBox>
<asp:RequiredFieldValidator runat="server" ID="rqrdcontactZipCode" ValidationGroup="contactValidation" Display="Dynamic"
ForeColor="Red" ControlToValidate="txtcontactZipCode" ErrorMessage="Zip Code is required"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regexpcontactZipCode" runat="server" ControlToValidate="txtcontactZipCode"
ValidationGroup="contactValidation" Display="Dynamic" ForeColor="Red" ErrorMessage="Should be 5 or 9 Digits"
ValidationExpression="\\d{5}(-\\d{4})?$"></asp:RegularExpressionValidator>
But I am unable to valid if I enter as follows 11111-____
Can some one help me..
The issue is that your regular expression indicates the four digits must exist if you have the dash. Generally that would be okay but since you're using an input mask the dash always exists, even when it's only five digits. Try the following expression.
ValidationExpression="\d{5}-?(\d{4})?$"
You should only use \\ to escape when you're setting it through C# code-behind.
Use this...
ValidationExpression="\d{5}(-\d{4})?$"
If you were setting it through the C# in the background, then you would need \\d because \d would be considered to be a control character...
txtcontactZipCode.ValidationExpression = "\\d{5}(-\\d{4})?$";
This is unless you precede the string with #, in which case it could be done as...
txtcontactZipCode.ValidationExpression = #"\d{5}(-\d{4})?$";
What about :- [0-9]{5}(\-[0-9]{4})?
[0-9] Any number between 0 and 9, {5} = only 5 characters; Altarnativly \d depending on what you find easier to read.
( ) - Create a group
\-[0-9]{4} A Dash followed by 4 numbers
? Optional - Zero or One
Use this method:
public static boolean validateZip( String zip )
{
return zip.matches( "\\d{5}" );
}

How to change DataField of BoundField

When using the asp:boundfield, can I call a C# function that return a string which corresponds to the column name instead of writing the column itself?
<asp:BoundField DataField="Notes" HeaderText="Notes"/>
Instead of having DataField="Notes", I want to have DataField=FUNCTION_NAME.
I tried using the following but it didn't work:
DataField=<% FUNCTION_NAME %>
Try this:
DataField="<%=FUNCTION_NAME %>" (extra equals)
What you had was simply an embedded code block which didn't have an output. However the = produces output to the page (similar to response.write()).
See the difference here

Custom Repeater with hiractial Databinding

Im using a Custom NestedRepeater Control for ASP.NET which can be found on code project
The source is in c# which i have converted to vb and plugged into my solution, so far so good. The problem, im having is databinding to the repeater, my code behind looks like this...
'' get all pages
Dim navPages As DataSet = Navigation.getMenuStructure()
navPages.Relations.Add(navPages.Tables(0).Columns("ID"), navPages.Tables(0).Columns("ParentID"))
NestedRepeaterNavigation.RelationName = RelationName
NestedRepeaterNavigation.DataSource = navPages
NestedRepeaterNavigation.RowFilterTop = "ParentID is null"
NestedRepeaterNavigation.DataBind()
Then in the item template of my custom repeater im trying the following...
<ItemTemplate>
<img src="/pix.gif" height="10" width="<%#(Container.Depth * 10)%>">
<%# (Container.DataItem as DataRow)["DESCRIPTION"]%>
<%# (Container.NbChildren != 0 ? "<small><i>(" + Container.NbChildren.ToString() +")</i></small>" "") %><small><i></i></small>
</ItemTemplate>
The databinding falls over; firstly that 'as DataRow' says it was expecting an ')'. And secondly that '!=' identifier expected.
Is this due to the translation from c#, should the databinding be different?
Though I've not programmed in VB.net for long (about 3 years) but I know that AS is not applicable in VB.net you need ctype to cast Container.DataItem like
CType(Container.DataItem, DataRow).
you can also try DirectCast(Container.DataItem, DataRow) but I don't think this will work.
Also for inequality comparison you can use
Not Container.DataItem = 0
but not !=

Resources