Do boolean attributes require quotes in ASP.NET? - asp.net

In ASP.NET markup do boolean attributes require quotes?
<asp:tag name="myTagName" IsEnabled=true />
or
<asp:tag name="myTagName" IsEnabled="true" />

It is most common to use quotes, although the ASP.NET page parser doesn't require nor enforce this.
All 3 buttons below will be disabled, using double quotes, single quotes and no quotes to set the value of the Enabled property.
<asp:Button runat="server" Text="Button1" Enabled="false" />
<asp:Button runat="server" Text="Button2" Enabled='false' />
<asp:Button runat="server" Text="Button3" Enabled=false />
Only when an invalid mixed format is being used like here below,
<asp:Button runat="server" Text="Button4" Enabled="false' />
being a combination of double and single quotes, Visual Studio shows a warning/error feedback, mentioning that the quotation marks must match in case they are being applied.
The message doesn't state that quotation marks must be used.
Validation (ASP.Net): If this attribute value is enclosed in quotation marks, the quotation marks must match.
At runtime the page will then fail with the error below.
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific
parse error details and modify your source file appropriately.
Parser Error Message: The server tag is not well formed.

Yes Because these tags are in XML format and passing data should be in quotes,
XML Syntax
Edit:
In IBM Website they have this example:
Incorrect
<?xml version= “1.0” encoding=“ISO-8859-1”?>
<note date=05/05/05>
<to>Dick</to>
<from>Jane</from>
</note>
Correct
<?xml version= “1.0” encoding=“ISO-8859-1”?>
<note date=”05/05/05”>
<to>Dick</to>
<from>Jane</from>
</note>
source

Related

Trying to pass a parameter in ASP.NET ! Parsing error

I am trying to pass a parameter from a page to another. I am getting parsing errors (Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. )
This is the code :
<a runat="server" href="~/ProductDetails.aspx?IDProduct=<%# Eval("IDProduct") %>">
<asp:Label Font-Size="16px" ForeColor="Red" runat="server">get specifications</asp:Label>
</a>
I am getting errors at IDProduct=<%# Eval("IDProduct") %>!
How should i write it ?
The proper way to handle such cases is to make the whole attribute value generated inside <%# %>. Also note the updated quoting pattern - single quotes around attribute value, and double quotes inside <%# %>.
href='<%# "~/ProductDetails.aspx?IDProduct=" + Eval("IDProduct") %>'
Try to do this
<a runat="server" href="~/ProductDetails.aspx?IDProduct="<%# Eval("IDProduct") %>>

Print a Resources.resx file value within ASP.NET tags

I'm required to print a value of a string which within a resource files (.resx) within asp.net tags
i used the following approaches
for example :
<ext:ComboBox ID="cmbProgram" runat="server" FieldLabel="<%= Resource.StringName %>"
<ext:ComboBox ID="cmbProgram" runat="server" FieldLabel="<%= Response.Write(Resource.StringName) %>"
But both approaches didin't provide the value of the string, but provides the ID. How to get the values within the ASP.NET tags?
Assuming you have Control.ascx:
<ext:Tag runat="server" meta:resourcekey="fooBar" />
Then put Controls.ascx.resx in App_LocalResources containing appropriate strings:
fooBar.PropetyName = "x"

how to validate a filename using asp.net regular expression validator

i have the following code to validate my file name entered using regular expression validator
but even after enter correct file name format, its hitting error saying enter valid filename
<asp:TextBox ID="TxtFileName" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="FileNameRegularExpressionValidator" runat="server"
ErrorMessage="Enter valid FileName"
ControlToValidate="TxtFileName"
ValidationExpression="^(\\[a-z_\-\s0-9\.]+)+\.(txt|gif|pdf|doc|docx|xls|xlsx)$">
</asp:RegularExpressionValidator>
At the moment, your regex requires the filename to start with a backslash. Also, your filenames may only contain the lowercase form of letters. Is that intentional?
Also, you're repeating your repeated group, a surefire recipe to bring your server down to its knees with catastrophic backtracking once someone enters an invalid filename that's more than a few characters long.
Perhaps
ValidationExpression="(?i)^[\w\s0-9.-]+\.(txt|gif|pdf|doc|docx|xls|xlsx)$">
would be more suitable?

Why can't I validate values with the $ symbol in it?

I am using a CompareValidator to check user input on one of my forms but for some reason it will not allow me to enter a dollar sign.
According to MSDN the currency data type in the compare validator allows:
A decimal data type that can contain
currency symbols.
I am using the control below to validate:
<asp:CompareValidator ID="vld_Cash" runat="server" ControlToValidate="CashTextBox" Type="Currency" Operator="DataTypeCheck" ValidationGroup="vld_Update" ErrorMessage="The value entered for 'Cash' must be in a number format. Do NOT include dollar signs. Examples: 500 or 500.00" />
I also added the following to my web.config just to be sure:
<globalization culture="en-US" uiCulture="en-US"/>
But it still says any input with a $ in it is invalid. Am I missing something here?
The last comment in this thread shows why and gives you some ideas:
Currency Validator
An article dedicated to this:
ASP.Net: Validating a TextBox with a Dollar Sign (suggests using a RegularExpressionValidator).

File Upload Validator always show error message

I add asp.net file upload control as follows:
<asp:FileUpload ID="filesFileUpload" runat="server" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ErrorMessage="file types not supported"
ValidationExpression="\.(zip|rar|jpg|gif|png|eps|ai|psd|pdf)$" ControlToValidate="filesFileUpload"></asp:RegularExpressionValidator>
And always when I upload file that match the reg expression it show the error. How can I resolve this?
Your regular expression checks for a single dot, followed by one of the extensions, all the way to the end of the string. You need to match the rest of the the filename (.+ matches one or more characters , ^ mean start of string):
ValidationExpression="^.+\.(zip|rar|jpg|gif|png|eps|ai|psd|pdf)$"
See this handy cheat sheet.

Resources