This question already has answers here:
Can I place a comment inside a tag in ASP.NET?
(3 answers)
Closed 8 years ago.
I know how to comment any code in the ASP page, but I want to ask is this is allowed in ASP to comment the line within any ASP tag. For example:
<asp:RequiredFieldValidator runat="server" ID="rfv01" ControlToValidate="txtName"
Enabled="False" Display="None" ErrorMessage="Error"
<%--Some Comments--%>
ValidationGroup="TestGroup" />
I know its very basic question, but couldn't find the answer at the moment. Can anybody help me out?
No, it isn't.
You might be able to achieve a similar effect by using a fake attribute/property, but I don't know how well the ASP.NET parser would handle that:
<asp:RequiredFieldValidator runat="server" ID="rfv01" ControlToValidate="txtName"
Enabled="False" Display="None" ErrorMessage="Error"
comments="--Some Comments--"
ValidationGroup="TestGroup" />
No, you cannot. You can't embed <% %> inline constructs in server tags. You can't embed them in non-server tags either. In the first case you'll get a compile-time error, in the latter case a 'runtime-error' inasmuch as it will produce bad markup, so <div <%-- some comment --%>></div> will result in that element not being rendered in Chrome where other browsers might handle it differently.
P.S. My original answer addressed the wrong question, due to my own fault.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
My asp:ImageButton doest not fire onclick event on IE, but is working normally on chrome or firefox.
Don't know if my code is right, but is here:
<asp:ImageButton ID="SaveBtn" runat="server" OnClick="Save_Click"
ToolTip="Save" ImageUrl="images/save.png" />
Using .NET Framework 3.5
Note: IE10
Just install .NET Framework 4.5
IE10 has a bug.
IE10 incorrectly convert coordinates to decimal rather than integer. This causes ImageButton clicks to fail.
You could try some workaround, like:
- change the ImageButton to a LinkButton and put the button image inside of it.
Your code will look like this:
<asp:LinkButton ID="SaveBtn" runat="server" OnClick="Save_Click">
<asp:Image ID="Image1" runat="server" ImageUrl="images/save.png" ToolTip="Save" />
</asp:LinkButton>
Take a look here too.
I want the user to be able to leave comments, a few sentences perhaps. TextBox is to no use, but I see no asp:CommentBox
Any advice on what to use instead?
Thanks
Set property TextMode to MultiLine
As this
<asp:TextBox ID="Text1" runat="server" TextMode="MultiLine" />
You can see more on MSDN http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.textmode.aspx
If the comments part of your project is so important i suggest using third-parties for these such functions
check these 2 sites
Disqus Elevating the discussion, anywhere on the web.
livefyre WE MAKE YOUR SITE SOCIAL.
i know that's not answer to your question, but i think you should at least know they are exist.
I've got the beautiful task at hand to look at some nice legacy asp.net 2 code and implement some new controls.
It's my first attempt at asp.net (the classic one, i've experimented with mvc a bit) so i am not too fond of it.
Right now i am trying to understand why a databinding sometimes works and a similar binding wont work on another page.
<asp:ImageButton ID="SaveAsPDFButton" runat="server"
ImageUrl='<%#GetPdfIconSmallPath() %>'
ToolTip='<%$ Resources:SaveAsPDFButton.Text %>'
CausesValidation="false" />
While the Tooltip gets evaluated and set, the ImageUrl of this control wont be set. The function is not getting executed. I've tried all, even disabling ViewState on it.
On other places, this same code however works just fine, like this small snippet here which does exactly what you might expect it to do:
<asp:HyperLink ID="InvHl" runat="server">
<asp:Image ID="Img1" ImageUrl='<%#GetPdfIconSmallPath() %>' runat="server" />
</asp:HyperLink>
Same thing occurs with the Visible Property of an ASP:Panel i have on other places in this page.
Any ideas on how to get this working appreciated!
We didnt really solve the problem but switched to the newest version of ASP.NET which does not show such a strange behaviour.
If I define the following template inside DetailsView, then upon clicking an Update or Insert button, the page is posted back to the server:
<EditItemTemplate>
<asp:TextBox ID="txtDate" runat="server" Text='<%# Bind("Date") %>'></asp:TextBox>
<asp:CompareValidator ID="valDateType" runat="server" ControlToValidate="txtDate" Type="Date" Operator="DataTypeCheck" Display="Dynamic" >*</asp:CompareValidator>
</EditItemTemplate>
If I remove CompareValidator control from the above code by simply deleting it, then page still gets posted back.But if instead I remove CompareValidator control by enclosing it within <!-- --> tags, then for some reason clicking an Update or Insert button doesn’t cause a postback...instead nothing happens:
<EditItemTemplate>
<asp:TextBox ID="txtDate" runat="server" Text='<%# Bind("Date") %>'></asp:TextBox>
<!-- <asp:CompareValidator ID="valDateType" runat="server" ControlToValidate="txtDate" Type="Date" Operator="DataTypeCheck" Display="Dynamic" >*</asp:CompareValidator> -->
</EditItemTemplate>
</EditItemTemplate>
Any idea why page doesn't get posted back?
thanx
Try using server-side comments:
<%--<asp:CompareValidator ID="valDateType" runat="server" ControlToValidate="txtDate" Type="Date" Operator="DataTypeCheck" Display="Dynamic" >*</asp:CompareValidator>--%>
You can also use the Enabled="False" attribute.
I got bitten by something similar in (someone else's!) JSP last week. The HTML comments don't stop the tag from being parsed; if it generates an HTML comment, you end up with nested HTML comments and all manner of strange things going on.
The only "safe" use of HTML-style comment delimiters in an ASP/JSP is where there is no generated content between them:
<!-- This is safe -->
We know exactly what that will be after the ASP engine has parsed it - it'll look the same. The problem may bite you when you have an ASP tag in there:
<!-- This might not be safe because I have no idea
what <asp:joesCustomTag/> expands to -->
If that tag generates an HTML comment, you'll have an HTML comment in your HTML comment! Let's see what happens when that custom tag is parsed and the HTML gets sent to the browser:
<!-- This might not be safe because I have no idea
what
<!-- Joe's custom tag -->
<p>Joe is 1337</p>
expands to -->
You can see the problem right there - SO's own parser is confused by the nested comments.
It's safest to assume that every tag generates an HTML comment, and that putting it in an HTML comment will bite you. Even if it's your tag, you might add an HTML comment to it later.
The answer, as Paperjam says, is to use the correct server-side comments to comment things out - though, of course, you really shouldn't be leaving commented-out dead things around waiting to bite you. Only use HTML-style comments if you actually want a comment to appear in the HTML source.
I want to develop application that contain number of question with independent radiobuttonlist which contain three option Yes, No, Unsure.
Daily visitors comes on the site & reply to the question. Also to show addition of the Yes, NO & Unsure in front of each question.
Please give me idea how to do such functionalty.
Regards,
Girish
Quickest and easiest way would be to piggy-back on an existing site.
http://www.polldaddy.com/ will allow you to embed polls in your own site
This is a very vague question and probably won't get much of an answer.
What technology do you want to use, .Net, Java. PHP etc, what resources do you have available?
Essentially you need some sort of database to store the questions and answers in and a front end web application built in whatever technology you decide on (as stated .net, Java or PHP are probably the most common).
Create a custom control that uses an Update Panel. Inside the update Panel you will have two PlaceHolders - 1 for your questions and 1 for your results. Hide the results placeholder by default. Once the radiobutton (OnSelectedIndexChanged) is selected, cause a postback and calculate the results. In the same Postback method, hide the Question placeholder and show the results placeholder with the calculated results.
Your page could look like this:
<UpdatePanel ID="upPanel" runat="server">
<ContentTemplate>
<asp:PlaceHolder ID="plcQuestion" runat="server">
Have you ever written asp.net code?
<asp:RadioButtonList ID="radList" AutoPostBack="true" OnSelectedIndexChanged="doStuff">
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
<asp:ListItem>Unsure</asp:ListItem>
</asp:RadioButtonList>
</asp:PLaceholder>
<asp:PlaceHolder ID="plcAnswers" runat="server" Visible="false">
Results:
Yes: <asp:Label ID="lblYesResults" runat="server" />
No: <asp:Label ID="lblNoResults" runat="server" />
Unsure: <asp:Label ID="lblUnsureResults" runat="server" />
</asp:PLaceholder>
</ContentTemplate>
</UpdatePanel>
Then, on your "doStuff" method, just save the results and populate whatever result display you are going for. Hope this helps!