I have a multiline textbox within an updatePanel. where a user can enter any notes he requires. If he enters an email address inside angular brackets then when submitting or cancelling I get a PageRequestManagerServerErrorException of 500.
If he enters an email address in these notes as myaddress.xxx.ca without the brackets, then there is no error.
The textbox should allow him to enter anything he wants too, it is really just for his notes.
I have tried to the RequestValidation = "false" in the page directive but this does not work.
Any suggestions would be appreciated.
Bryan
I assume you are using at least .Net 4.0? I did a small example according to your question and noted the same behaviour. Fortunatelly I found a quick solution (even here on Stackoverflow - Allow html in asp.net textboxes).
aspx
<%# Page Language="C#" AutoEventWireup="true" ValidateRequest="false" CodeFile="commonQuestions.aspx.cs" Inherits="commonQuestions" %>
.....
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server" Height="81px" TextMode="MultiLine" Width="264px"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Send" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
codeBehind
protected void Button1_Click(object sender, EventArgs e)
{
// do something
Debug.WriteLine("Text: " + TextBox1.Text);
}
add to web.config
<httpRuntime requestValidationMode="2.0" />
And here we got a pretty good explanation from MS, refering to changes in ASP.Net 4
As a result, request validation errors might now occur for requests
that previously did not trigger errors. To revert to the behavior of
the ASP.NET 2.0 request validation feature, add the setting (see above)
in the Web.config file:
Related
"Only one instance of a ScriptManager can be added to the page." this error appear when I added the script Manager to the password strength of AJAX toolkit.
i added the password strength beside the password field of my createuserwizard.
why this error would appear when this is the only scriptmanager that i had in my website?
here is the code:
<asp:TextBox runat="server" ID="Password" TextMode="Password" MaxLength="20" />
<asp:ScriptManager ID="ScriptManager2" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:PasswordStrength ID="Password_PasswordStrength" runat="server"
Enabled="True" TargetControlID="Password" DisplayPosition="RightSide"
StrengthIndicatorType="BarIndicator"
BarBorderCssClass="barBorder"
BarIndicatorCssClass="barInternal">
</asp:PasswordStrength>
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator10" ControlToValidate="Password"
ErrorMessage="Password is required." />
</ContentTemplate> </asp:UpdatePanel>
</td>
</tr>
Just remove this ScriptManager and it will work fine.
<asp:ScriptManager ID="ScriptManager2" runat="server">
</asp:ScriptManager>
You have definitely added a ScriptManager somewhere else in your Page or MasterPage.
ScriptManager Control Overview
Only one instance of the ScriptManager control can be added to the
page. The page can include the control directly, or indirectly inside
a nested component such as a user control, content page for a master
page, or nested master page. If a page already contains a
ScriptManager control, but a nested or parent component needs
additional features of the ScriptManager control, the component can
include a ScriptManagerProxy control. For example, the
ScriptManagerProxy control enables you to add scripts and services
that are specific to nested components.
Maybe your Masterpage has a Scriptmanager too?
Check your whole aspx page hierarchy...
I have used file upload control of asp.net but I am getting empty string while saving.my code-
<asp:FileUpload ID="fuProductLogo" runat="server" CssClass="file paddBottom5px" />
.cs code is-
if (fuProductLogo.PostedFile != null && fuProductLogo.PostedFile.ContentLength > 0)
{
...
}
but the .PstedFile and .CountLength is coming zero but the same code is working fine in another page.Please help.
There are several things to check here:
as #williem said, remove updatepanel from the form if you are using it
add enctype="application/x-www-form-urlencoded" in the form tag
Please remember to update your post after your code modifications and checks.
If the FileUpload is in an UpdatePanel it will be cleared on each ajax-postback. You can use multiple UpdatePanels around the FileUpload control and keep the FileUpload out of them. Also make sure that the button that triggers the actual upload does a real postback, not an asyncpostback. Do this by adding the button to the PostbackTrigger of it's UpdatePanel or by taking it out of the UpdatePanel.
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox2" runat="server" />
<asp:Button ID="Submit" runat="server" Text="Submit" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Submit" />
</Triggers>
</asp:UpdatePanel>
You can also use an AsyncFileUpload control from the Asp.net Ajax Toolkit, it works inside an UpdatePanel but it is a little harder to get this to work.
I recently upgrade this configuration:
ASP.NET 2.0
AjaxControlToolkit, 1.0.20229.0
System.Web.Extensions, Version=2.0.0.0
To
ASP.NET 3.5
System.Web.Extensions, Version=3.5.0.0
AjaxControlToolkit , Version=3.5.40412.0
I have the following structure:
<asp:ToolkitScriptManager ID="PageScriptManager" runat="server">
</asp:ToolkitScriptManager>
<asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Always">
<ContentTemplate>
<ajaxToolkit:TabContainer
OnActiveTabChanged="TabContainerCarga_ActiveTabChanged"
AutoPostBack="True">
<ajaxToolkit:TabPanel
ID="tabRelatorios"
runat="server"
HeaderText="Relatórios">
<ContentTemplate>
<CustomUserControl:relatorios id="CustomControl" Visible="False" runat="server" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="CustomControl" />
</Triggers>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ... />
<ajaxToolkit:TabPanel ... />
<ajaxToolkit:TabPanel ... />
<ajaxToolkit:TabPanel ... />
All the has the same first structure. At the serverside code, I have:
protected void TabContainerCarga_ActiveTabChanged(object sender, EventArgs e)
{
//handles TabPanels show/hide and fill up forms grids.
}
CustomControl has a grid which has some post-backs to perform operation like adding and removing records. When CustomControl loads it fills two <asp:DataGrid /> components.
<asp:DataGrid /> load a list
with some text box, which the user
may fill out and press a button to
add records.
<asp:DataGrid
/> show any entered information. To history purposes.
The strange known behavior is, it actually fire ActiveTabChanged twice. In the first time, it act like I'm loading the CustomControl state for the first time and them goes do the event.
I can't use some solution I've seen like set isFormLoaded flag or even fire a javascript postBack function.
I think about placing a IsLoaded flag structured in a ViewState inside the control. And restart it after any fired event inside the custom control.
What do you think about this and there is any solution arround?
I couldn't solve this problem because it comes from the internal mechanics of this component. I wouldn't go through that jungle. So I asked a designer to draw cool tabs for me and wrote my own tab control using AJAX and Rest Services style. That's it! The behavior I wanted now I have it and works pretty nice now; controllable and loads less JavaScript code into the client machine. Stop using that shit!
I have user control inside a page with single repeater. The problem is when this control is placed inside repeater check box doesn't fire CheckedChanged event. If this would be a dynamically added control I would check whether CheckedCanged event has a handle assigned in Init() but here the event is specified in ascx so I imagine asp.net is responsible for doing all the assignments in right place. I'm lost here :/
By the way. Placing single checkbox inside repeater doesn't fire to. But I can at least use OnItemCommand there
User Control
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="QuoteContainer.ascx.cs" Inherits="EhdSite.Controls.QuoteContainer" %>
<asp:TableRow runat="server" ID="trQuoteRow">
<asp:CheckBox runat="server" ID="cbxConfirm" AutoPostBack="true" OnCheckedChanged="CbxConfirmCheckedChanged" />
</asp:TableRow>
Page
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager2" runat="server" />
<asp:UpdatePanel runat="server" ID="upQuotes" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:Repeater runat="server" ID="rptQuotes">
<ItemTemplate>
<ehd:QuoteContainer
runat="server"
ID="qcQuote"
RowCssClass="rowStyle"
HighlightedRowCssClass="selectedRowStyle"
Quote="<%# Container.DataItem %>"
OnQuoteSelectedChanged="QuoteSelectedChanged" />
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
It has to do with the event-chain in ASP.Net, this MSDN page helps to understand it.
The .Net framework resolves the ViewState between the Init- and the Load-event. So if the control is not there after the Init-event, it's ViewState will never be loaded and also it's events will never be fired.
This can get quite tricky at times, especially if one dynamically loaded control should affect the loading of another one...
I'm trying to display an update progress loading image whenever my update panel does it's Ajax thing. I've looked around at tutorials and it seems really straightforward but I'm having no luck. Here is pretty much what I have...
<div id="panelWrapper">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:UpdateProgress ID="TaskUpdateProgress" runat="server" DynamicLayout="False" AssociatedUpdatePanelID="UpdatePanel1" DisplayAfter="0">
<ProgressTemplate>
<asp:Image ImageUrl="~/Images/ajax-loader.gif" Width="16px" Height="16px" runat="server" ID="TaskLoadingImage"/>
</ProgressTemplate>
</asp:UpdateProgress>
<div id="UrlDiv" class="URLNotification">
<asp:Label ID="UrlLabel" runat="server" Text="URL:" AssociatedControlID="Url" />
<asp:HyperLink ID="Url" runat="server" Text="Click "Generate" to create the URL." />
</div>
<br />
<asp:CheckBoxList runat="server" ID="IncludeItems" TextAlign="Right">
<asp:ListItem Selected="True">Include 1</asp:ListItem>
<asp:ListItem Selected="True">Include 2</asp:ListItem>
</asp:CheckBoxList>
<br />
<div id="buttons" style="display:inline;">
<asp:Button ID="Generate" runat="server" OnClicked="Generate_Clicked" Text="Generate" />
<asp:Button ID="Add" runat="server" OnClientClick="add();" Text="Add"/>
</div>
</ContentTemplate>
</asp:UpdatePanel>
I also have some absolute positioning styling in a stylesheet. I've tried a bunch of variations of what you see here and have not found much good information as to what may be the issue. Any ideas? If you need anything else, let me know.
EDIT: The only new information I've found is that...
"In the following scenarios, the UpdateProgress control will not display automatically:
The UpdateProgress control is associated with a specific update panel, but the asynchronous postback results from a control that is not inside that update panel.
The UpdateProgress control is not associated with any UpdatePanel control, and the asynchronous postback does not result from a control that is not inside an UpdatePanel and is not a trigger. For example, the update is performed in code."
I'm pretty confident neither of these fit into my case. All that is happening is the button (which is inside the update panel) is clicked calling some code behind which set's the URL text to be reloaded for the update panel.
I have also the same problem with the UpdateProgressPanel.
I found out that when you have placed an UpdateProgressPanel and associated it to an UpdatePanel, any postback from that UpdatePanel will cause the UpdateProgressPanel to show.
Another trick to do is to remove the AssociatedUpdatePanel parameter if you have a single UpdatePanel on the page, this will cause the UpdateProgressPanel to show every Async PostBack that happens.
UpdateProgressPanel can be placed anywhere in the code, except those areas that have predefined tags on it. It can be placed inside or outside the UpdatePanel and it will show if you have properly placed its CSS, Associated it to an UpdatePanel or just place it there and it will show up if an async postback result happens.
Don't put the update progress control inside the update panel control
Make sure the UpdateProgress 'DisplayAfter' is set up to 1000 (1 sec)
I guess I figured out what was going on. The issue wasn't with anything I was doing wrong with the UpdateProgress or Panel. It was that I had other stuff loading in the background that was apparently holding up the UpdatePanel's Ajaxyness.
So basically what happened was that the loading icon wouldn't show up on the initial page load. I realized this because I actually waited till after everything on the page was completely loaded to fire off the button. Sure enough the loader showed up.
I assumed that the update panel refresh would at least be requested the instant the click event was heard so the loader icon would immediately show during the time other stuff is loading. This doesn't appear to be the case though...
I was having really hard time after converting my project from VS2008 to VS2010. The UpdateProgress stopped working suddenly, which was fine in VS2008. Spending a whole afternoon to search the answer and experimenting this and that, finally I found what went wrong from Scott Gu's posting.
It was an automatically generated web.config entry 'xhtmlConformance mode="Legacy"'.
After disabling this, it started to work again. May be not the case for you but just for guys struggling with the same problem.
Happy coding
I also had a problem with the UpdateProgress not showing. Turned out the postback to the server was actually so fast it never had time to show. Adding a Thread.Sleep(10000) helped show the problem.
Create a new ASP.NET Ajax-Enabled Web Site and then paste these code in ascs and aspx file. Run it and you can see the update progress. You can use animated gif files too to show the progress...
ascx Page:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>UpdateProgress control</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdateProgress runat="server" id="PageUpdateProgress" AssociatedUpdatePanelID="Panel">
<ProgressTemplate>
Loading...
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel runat="server" id="Panel">
<ContentTemplate>
<asp:Button runat="server" ID="UpdateButton" OnClick="UpdateButton_Click" Text="Update" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="UpdateButton" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</form>
</body>
</html>
aspx Page:
protected void UpdateButton_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(5000);
}