ASP.NET trying to compile commented lines of code. Why? - asp.net

I have code like this on some aspx page in my Web Application:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"/>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div>
<asp:Label ID="lbl1" runat="server" Text="Laber1" />
<asp:Button ID="btn1" runat="server" Text="Button1" onclick="btn1_Click" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
<!--
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"/>
<asp:TextBox ID="txtAjaxToolkit" runat="server" />
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtAjaxToolkit" />
-->
</asp:Content>
When I compile the project and go to this page in the browser, I get this exception:
[InvalidOperationException: На страницу можно добавить только один экземпляр ScriptManager.]
(translate: "There only one instance of ScriptManager allowed on this page").
Why do I get this message if second script manager (ToolkitScriptManager) is located in comments?
I am using ASP.NET 4 and ASP.NET Ajax Control Toolkit.
P.S: Sorry for my english.

Use server side comment syntax.
<%---
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"/>
<asp:TextBox ID="txtAjaxToolkit" runat="server" />
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtAjaxToolkit" />
---%>

You've used HTML comments, but the markup engine doesn't care about that - it'll still try to generate the content of that HTML comment. After all, you might want something like a timestamp in a comment.
You want a server-side comment, like this;
<%--
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"/>
<asp:TextBox ID="txtAjaxToolkit" runat="server" />
<asp:CalendarExtender ID="CalendarExtender1" runat="server"
TargetControlID="txtAjaxToolkit" />
--%>
It's all a matter of working out what's going to figure out that something is a comment - the HTML <!-- comment --> is aimed at a browser; the `<%-- comment --%> is aimed at the ASPX processor.

Related

validators does not work after adding update panel .net

<asp:TextBox ID="f5" runat="server" CssClass="location" value="" placeholder="Enter Email ID:"
name="location"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ValidationGroup="rqrd" ControlToValidate="f5"
ErrorMessage="Required Field cannot be empty"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ValidationGroup="rqrd" ValidationExpression="^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$" ControlToValidate="f5" ErrorMessage="Invalid Email-id"></asp:RegularExpressionValidator>
<asp:ScriptManager ID="scriptmanager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="PnlUsrDetails" runat="server">
<ContentTemplate>
<div class="location-block">
<div class="form-block location">
Username:</div>`enter code here`
<div class="form-block airport_codes">
</div>
<asp:TextBox ID="f6" runat="server" CssClass="location" AutoPostBack="true" OnTextChanged="f6_TextChanged" value="" placeholder="Enter Username:"
name="location">
</asp:TextBox>
<div id="checkusername" runat="server" Visible="false">
<asp:Label ID="lblStatus" runat="server"></asp:Label>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
This is my code the update panel part works perfectly but the other validators have stopped working
p.s. i use visual studio 2012 and i installed ajax control toolkit yesterday only from the manage nuGet packages ...
Thanking You in Advance
Put the ScriptManager above the TextBox and the RequiredFieldValidator.
the script manager tag actually asynchronously loads a part of the page but does not reload the java scripts (and thus the required field validators) associated with it. and thus it won't work. So avoid using script manager of c#.net. use normal ajax and jquery functions

One form tag on page in ASP.NET Issue

I am getting this error when trying to run my project on localhost
Exception Details: System.Web.HttpException: A page can have only one server-side Form tag
This is my ASP.NET form
<form id="consultationform" runat="server">
<%-- Consultation --%>
<%-- Name --%>
<asp:Label ID="namelabel" runat="server" Text="Name"></asp:Label>
<asp:TextBox ID="namebox" runat="server"></asp:TextBox><br />
<%-- email --%>
<asp:Label ID="emaillabel" runat="server" Text="Email"></asp:Label>
<asp:TextBox ID="emailbox" runat="server"></asp:TextBox><br />
<%-- restaurant --%>
<asp:Label ID="restaurantlabel" runat="server" Text="Restaurant"></asp:Label>
<asp:TextBox ID="restaurantbox" runat="server"></asp:TextBox><br />
<%-- Address --%>
<asp:Label ID="addresslabel" runat="server" Text="Address"></asp:Label>
<asp:TextBox ID="addressbox1" runat="server"></asp:TextBox><br />
<asp:TextBox ID="addressbox2" runat="server"></asp:TextBox><br />
<asp:TextBox ID="addressbox3" runat="server"></asp:TextBox><br />
<%-- County --%>
<asp:Label ID="countylabel" runat="server" Text="County"></asp:Label>
<asp:DropDownList ID="countrydropdown" runat="server"
DataSourceID="CountySqlDataSource" DataTextField="CountyName"
DataValueField="CountyName" AppendDataBoundItems="True" AutoPostBack="True">
<asp:ListItem Value="" Text="Select a County"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="CountySqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [CountyName] FROM [Counties]"></asp:SqlDataSource>
<br />
<%-- Telephone --%>
<asp:Label ID="telephonelabel" runat="server" Text="Telephone"></asp:Label>
<asp:TextBox ID="telephonebox" runat="server"></asp:TextBox><br />
<%-- Calendar --%>
<asp:Label ID="datelabel" runat="server" Text="Date (What suits you?)"></asp:Label><asp:Calendar
ID="Calendar1" runat="server"></asp:Calendar><br />
<%-- Additional Info --%>
<asp:Label ID="infolabel" runat="server" Text="Additional Information (That may help us further)"></asp:Label><br />
<asp:TextBox ID="infobox" runat="server"></asp:TextBox><br />
<%-- Menu Upload --%>
<asp:Label ID="menulabel" runat="server" Text="Menu"></asp:Label><asp:FileUpload
ID="FileUpload1" runat="server" /><br />
<%-- Book Button --%>
<asp:Button ID="bookbtn" runat="server" Text="Book Now" />
</form>
I don't understand why it is happening. I only have one form tag on the page. Any help on the matter is much appreciated.
Should note, page renders completely fine if I remove the form tag.
If you are using a masterpage, remove the form from your webform and inside the masterpage form add a content placeholder.
Use that content placeholder within your webforms like you were trying to use the form.
You may need to click the little arrow to the right of the content placeholder in the form in order to enable it.
in your master page, you should have at least:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs"Inherits="WebApplication1.Site1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
you can then remove all other form tags from your project, beacuse the master has one in use.
remember to add content pages properly also, in the body, contentplaceholder.

Timer control triiggers updatepanel in 5 seconds and I get a sys.webforms,PageRequestManagerServerErrorException

<%# Control Language="C#" AutoEventWireup="true" CodeBehind="ChatUserControl.ascx.cs"
Inherits="MetamorphismApp.ChatUserControl" %>
<asp:Timer ID="timer1" runat="server" OnTick="timer1_Tick" Interval="5000">
</asp:Timer>
<div id="divChatWindow" class="clChatWindow">
<div>
<asp:Label runat="server" Text='<%# Eval("username") %>' class="divHeader" ID="lblChatFriend"></asp:Label>
<asp:Image ID="imgFriend" runat="server" CssClass="classFriendImage" />
<asp:LinkButton ID="lbClose" runat="server" CommandName="Close" CssClass="lbClose"
OnClick="lbClose_Click">Close</asp:LinkButton></div>
<div class="chatText" id="idChatText" runat="server">
<asp:UpdatePanel ID="UpdatePanel" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer1" EventName="Tick" />
<asp:AsyncPostBackTrigger ControlID="btnSendChat" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Repeater runat="server" ID="rpChatMessages">
<ItemTemplate>
<asp:Image ID="imageForFriend" runat="server" CssClass="clFriendsImage" ImageUrl='<%# "HttpImageHandler.jpg?username=" + DataBinder.Eval(Container.DataItem,"fromusername").ToString() %>' />
<asp:Label ID="chatMessage" runat="server" Text='<%# Eval("Message") %>'></asp:Label>
<br>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<asp:TextBox ID="txtChatMessage" runat="server" Width="142px" CssClass="clChatMessage" EnableViewState="true"
TextMode="MultiLine"></asp:TextBox>
<asp:LinkButton ID="btnSendChat" runat="server" CommandName="Insert" CommandArgument='<%# Eval("username") %>'
OnClick="btnSendChat_Click" CssClass="btnSendChat">Send</asp:LinkButton>
</div>
I want to use updatepanel triggered by a timer control and after 5 seconds I get a sys.webforms error. I dont wanna populate my repeater using a webservice to be called via jquery and binding the data to the repeater. I want to use the updatepanel for data population. I have read several articles to avoid this error but havent found a solution yet. If I change asyncpostback trigger to postbacktrigger the page does a postback which I dont want to happen. I want to use updatepanel to solve this issue. What should I do?
It looks like you forgot to put ScriptManager control on your page.
I am getting error 503 status code. To my surprise if you are facing this error issue on the server then this issue is a server's issue and not your coding issue. Status 503 indicates that the server cannot fulfill the request and it gives this error. Try contacting your hosting provider.

UpdatePanel does not have a public property named 'TextBox'.

I'm looking to update the contents of a panel using an asp:updatepanel.
I get an error on the page saying: DotNetNuke.Services.Exceptions.ModuleLoadException: Type 'System.Web.UI.UpdatePanel' does not have a public property named 'TextBox'.
See code below:
<asp:ScriptManager runat="server" ID="ScriptManager" />
<asp:UpdatePanel runat="server" ID="brandAddingContainer" Visible="false">
<ContentTemplate>
<asp:LinkButton runat="server" ID="brandAddingPrompt">
<img src="/images/add.gif" alt="Add New Brand" onclick="addNewBrand_clicked"/> Add New Brand
</asp:LinkButton>
<asp:Panel ID="sendNewBrand" runat="server">
<asp:TextBox runat="server" ID="newBrandName"></asp:TextBox>
<asp:Button runat="server" ID="sendBrandName" Text="Add Brand" OnClick="sendNewBrand_clicked" />
<asp:Label runat="server" ID="insertionFeedback" Visible="false" />
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="brandAddingPrompt" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
Using ScriptManager in module controls is not advisable, I would suggest to remove ScriptManager from your module code and use Enable Prtial Rendering checkbox in module control definition.
What version of .net framework and dnn are you using? try installing ajax extensions installed?
there is also a an entire section in adef web server site here that can be helpful.

"Preview Area" in UpdatePanel not Refreshing

Greetings!
I have a "code builder" page where users select various radio buttons and it generate HTML markup (mostly SCRIPT tags) that they can use on their page to display some data. There is also a "preview" area so they can see the results before they copy/paste the code in their site. The form exists in a FormView control and is wrapped by an UpdatePanel like so:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FormView ID="FormView1" runat="server" DataSourceId="XmlDataSource1">
<ItemTemplate>
<div id="configArea">
<ul>
<li>
<%# XPath("Steps/Step1/ServerStatus") %><br />
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="OneA" Checked="true" AutoPostBack="true" Text='<%# XPath("Steps/Step1/YesOption") %>' />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="OneA" AutoPostBack="true" Text='<%# XPath("Steps/Step1/NoOption") %>' />
</li>
<li>
<%# XPath("Steps/Step1/Uptime") %><br />
<asp:RadioButton ID="RadioButton3" runat="server" GroupName="OneB" Checked="true" AutoPostBack="true" Text='<%# XPath("Steps/Step1/YesOption") %>' />
<asp:RadioButton ID="RadioButton4" runat="server" GroupName="OneB" AutoPostBack="true" Text='<%# XPath("Steps/Step1/NoOption") %>' />
</li>
<li>
<%# XPath("Steps/Step1/IPAddress") %><br />
<asp:RadioButton ID="RadioButton5" runat="server" GroupName="OneC" Checked="true" AutoPostBack="true" Text='<%# XPath("Steps/Step1/YesOption") %>' />
<asp:RadioButton ID="RadioButton6" runat="server" GroupName="OneC" AutoPostBack="true" Text='<%# XPath("Steps/Step1/NoOption") %>' />
</li>
</ul>
</div>
<div id="copyCode">
<%# XPath("Steps/Step2/CopyPasteCode") %><br />
<asp:TextBox ID="Textbox1" runat="server" TextMode="MultiLine" Width="300" Height="300" />
</div>
<div id="previewArea">
<%# XPath("Steps/Step3/PreviewTitle") %><br />
<asp:Literal ID="Literal1" runat="server" />
</div>
</ItemTemplate>
</asp:FormView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" XPath="Root/Data" />
It successfully generates the code in the copycode TextBox (TextBox1), which may look something like this:
<script src="http://example.com/src/Constants.js"></script>
<script>
showIPAddress = 0;
DisplayServerStatus();
</script>
At the same time, I update the "preview" area's Literal control (Literal1) with the text from the copycode TextBox (TextBox1). The preview is displayed perfectly when not inside an UpdatePanel, but does not work when it is (and I'd prefer to use an UpdatePanel to prevent page refreshing). I do the update of the "preview" area and copycode text during the PreRender event:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
UpdateCodeSnippetAndPreviewArea();
}
Any ideas why the preview doesn't update when it's in an UpdatePanel?
The reason it is not updating when using an UpdatePanel is that the ASP .NET AJAX framework does not process any inline javascript returned by the server. Look at using the ScriptManager.RegisterStartUpScript method on the server side to register execution of inline javascript. Essentially you could use this method to initiate execution of custom javascript once the panel is updated. In your case, your custom javascript would need to interpret the preview script appropriately (i.e. detect script tags, register them dynamically then execute the given functions).
Hope this helps!
Rohland

Resources