while hitting ESC key twice when on a page containing an update panel with a any control inside, say textbox or listbox im getting a System.ArgumentException: Invalid postback or callback argument. I have checked in remaining browsers its working fine but in Internet Explorer 8 its creating above said problem.
the possible solution i found, is making EnableEventValidation="false" either at page level or webconfig or disabling escape key. i dont want to go with 2 former solutions as either my site security will compromise and i dont want my escape key to disable.
Any Suggestions/Ideas appreciated.
Code :
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"
EnablePageMethods="true">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanelHeader" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div id="Search">
<table style="empty-cells: hide;" width="100%" cellpadding="0" cellspacing="0" class="controlsTable">
<tr>
<td class="td4Caption">
Some Text
</td>
<td class="tdpadding">
<asp:TextBox ID="txtbox" ClientIDMode="Static" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:ImageButton SkinID="Export" AlternateText="Generate Report" ToolTip="Generate Report"
ID="ibtnGenerateReport" ValidationGroup="Generate" runat="server" OnClick="ibtnGenerateReport_Click" />
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
•Another thing you can try is: EnablePartialRendering="false" to asp:ScriptManager
Make sure your site is rendering with the proper compatibility by using "edge":
< meta http-equiv="X-UA-Compatible" content="edge" />
If nothing above works, please try controlling the exception handler like this:
http://encosia.com/how-to-improve-aspnet-ajax-error-handling/
Related
I have a very simple application. I am trying to upload the file using File upload control of ASP.net. Below is my entire .cs code and .aspx code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace TestFileUpload1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void uploadFile_Click(object sender, EventArgs e)
{
if (UploadImages.HasFiles)
{
foreach (HttpPostedFile uploadedFile in UploadImages.PostedFiles)
{
uploadedFile.SaveAs(System.IO.Path.Combine(Server.MapPath("~/Images/"), uploadedFile.FileName));
//listofuploadedfiles.Text += String.Format("{0}<br />", uploadedFile.FileName);
}
}
}
}
}
My .aspx code:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TestFileUpload1.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test web site</title>
<script src="Scripts/jquery-1.11.0.js"></script>
<script src="Scripts/jquery.mobile-1.4.5.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div>
<asp:FileUpload runat="server" ID="UploadImages" AllowMultiple="true" />
<asp:Button runat="server" ID="uploadedFile" Text="Upload" OnClick="uploadFile_Click" />
<asp:Label ID="listofuploadedfiles" runat="server" />
</div>
</div>
</form>
</body>
</html>
whenever I try to upload a file, I get "False" for UploadImages.HasFiles.
Above is full working example.
As soon as I remove one of these script tags :
<script src="Scripts/jquery-1.11.0.js"></script>
<script src="Scripts/jquery.mobile-1.4.5.js"></script>
my code starts working and I get "true" for UploadImages.HasFiles when I try to upload a file.
I am using .net framework 4.7.2
I need to keep these two script tags in my code because of the GUI and this is an old application where these tags are used in all the pages.
I also tried to wrap the control in a update panel and that didn't work either. below is the changed .aspx page. although, I want my original code to work. I don't want to use ajax, but I just tried to use it because it is suggested as one of the solution
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TestFileUpload1.WebForm1" %>
<%--<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp"%>--%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test web site</title>
<script src="Scripts/jquery-1.11.0.js"></script>
<script src="Scripts/jquery.mobile-1.4.5.js"></script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FileUpload runat="server" ID="UploadImages" AllowMultiple="true" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="uploadedFile" />
</Triggers>
</asp:UpdatePanel>
<asp:Button runat="server" ID="uploadedFile" Text="Upload" OnClick="uploadFile_Click" />
<asp:Label ID="listofuploadedfiles" runat="server" />
</div>
</div>
</form>
</body>
</html>
below is the image of false value that I am getting in code behind:
Any help will be highly appreciated.
All I had to do is put data-ajax ="false" in form tag and that fixed the issue.
<form id="form1" runat="server" data-ajax ="false">
Use a update panel and wrap your controls inside it. Then add the button controlID as a trigger (be sure its a PostBackTrigger) to the update panel. To test be sure to put a break point on the uploadFile_Click event so you can step through and see the values..
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:PostBackTrigger ControlID="btnSignaureOfRequestor" />
</Triggers>
<ContentTemplate>
<table>
<tr> <td class="tdText" colspan="4">
<asp:FileUpload ID="fileUpload" runat="server" Width="50%" />
</td>
</tr>
<tr>
<td> <asp:Button ID="btnSignaureOfRequestor" runat="server" Text="Submit Request" Visible="true" OnClientClick="return confirm('Are you sure you want to continue?');" OnClick="btnSignaureOfRequestor_Click" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
Try the below, removed allow multiple and add update mode conditional (see confirm case/syntax of these changes as I'm just writing it in notepad)
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" updateMode="Conditional">
<ContentTemplate>
<asp:FileUpload runat="server" ID="UploadImages" />
<asp:Button runat="server" ID="uploadedFile" Text="Upload" OnClick="uploadFile_Click" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="uploadedFile" />
</Triggers>
</asp:UpdatePanel>
<asp:Label ID="listofuploadedfiles" runat="server" />
</div>
</div>
While I am working with ajax calender it showing error like "Error Creating Control - Calendarextender3Unknown server tag 'ajax:CalendarExtender' ". May i know why it is like this ?
<%# Register Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit"
tagPrefix="ajax"
%>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit"
TagPrefix="ajax" %>
<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<font size="4"><b> EMPLOYEE RESIGNATION</font></b>
</div>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<table class="ui-accordion" align="center">
<tr>
<td align="left" class="style2">
Delete Date</td>
<td >
<asp:TextBox ID="txtDate" runat="server" />
<ajax:CalendarExtender ID="Calendarextender3"
TargetControlID ="txtdate" Format="dd/MM/yyyy" runat="server">
</ajax:CalendarExtender>
</td>
</tr>
</table>
</fieldset>
</form>
</asp:Content>
Please help me...
Myself found answer for this question. Download ajax toolkit dll and add this into toolbox.
then select toolkitscriptmanager and ajax calanderextender from toolbox. sample code below
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>
<tr>
<td align="left" class="style2">
<asp:Label ID="lb3" runat="server" Text="Delete Date"></asp:Label>
</td>
<asp:TextBox ID="txtto1" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" TargetControlID
="txtfrom1" Format="dd/MM/yyyy" runat="server">
</ajaxToolkit:CalendarExtender>
</td>
</tr>
</form>
I was working with this simple web page and happened to put some 's to correct the styling of my page and suddenly when got back to programming in the .cs file, things are strange. All the code is showing a similar error msg:
Error 2 The name 'TextBox1' does not exist in the current context d:\ADO_NETprojects\mywebsite\Default2.aspx.cs
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" `enter code here`Inherits="Default2" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div runat="server">
<div>
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True"
onselectedindexchanged="ListBox1_SelectedIndexChanged" Width="179px" style="margin-left:100px; margin-bottom:20px;">
</asp:ListBox>
</div>
<hr/>
<div>
ListBoxItems
<asp:TextBox ID="TextBox1" runat="server" style="margin-left:20px; margin-top:20px;"></asp:TextBox>
</div>
<div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
style="height: 26px; margin-left:100px; margin-top:15px;" Text="ListsBoxItems" />
</div>
<hr/>
<div>
DeleteItems:
<asp:TextBox ID="TextBox2" runat="server" style="margin-top:10px; margin- left:25px;"></asp:TextBox>
</div>
<hr/>
<div>
<asp:DropDownList ID="DropDownList1" runat="server"
style="margin-top:20px; margin-left:100px; width:200px;"
AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
</div>
<div>
DropDownList:
<asp:TextBox ID="TextBox3" runat="server" style="margin-left:2px; margin-top:15px;"
AutoPostBack="True"></asp:TextBox>
</div>
<hr/>
</div>
</form>
</body>
</html>
right-click on the aspx file, then choose "convert to web application" and then, the designer.cs file is regenerated
I have been attempting this all morning with no results. I can't seem to figure out what I'm doing wrong. I have checked out the two links (among many other unhelpful links) and have yet to solve my issue. This is a WebUserControl...
Receiving the following error:
Control 'HeadContent_CareersViewPosting_txtFirstName' of type
'TextBox' must be placed inside a form tag with runat=server.
Already attempted the suggestions here, here and here and no results. Still received the exact same message. Some new suggestions would be greatly appreciated!
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Careers View Posting.ascx.cs" Inherits="ascxStagingApplication.Careers.Careers_View_Posting" %>
<asp:Panel ID="pnlResume" runat="server">
<table ID="tblMain" runat="server">
<tr>
<td>
<asp:Label ID="lblFirstName" runat="server" Text="* First Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblLastName" runat="server" Text="* Last Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblEmail" runat="server" Text="* Email"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblResume" runat="server" Text="* Resume"></asp:Label>
</td>
<td>
<asp:FileUpload ID="fupResume" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit"/>
</td>
</tr>
</table>
</asp:Panel>
The user control is currently being placed onto a dummy webpage for testing. Here is the 'dummy' page code.
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Page Careers View Posting.aspx.cs" Inherits="ascxStagingApplication.Careers.Page_Careers_View_Posting" %>
<%# Register Src="~/Careers/Careers View Posting.ascx" TagPrefix="uc1" TagName="CareersViewPosting" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<uc1:CareersViewPosting runat="server" id="CareersViewPosting" />
</asp:Content>
In ASPNet webforms - everything needs to run within a form tag.
All server controls must appear within a <form> tag, and the <form> tag must contain the runat="server" attribute. The runat="server" attribute indicates that the form should be processed on the server. It also indicates that the enclosed controls can be accessed by server scripts:
<form runat="server">
...HTML + server controls
</form>
In your dummy page try the following to allow the server controls to run.
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Page Careers View Posting.aspx.cs" Inherits="ascxStagingApplication.Careers.Page_Careers_View_Posting" %>
<%# Register Src="~/Careers/Careers View Posting.ascx" TagPrefix="uc1" TagName="CareersViewPosting" %>
<form runat="server">
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<uc1:CareersViewPosting runat="server" id="CareersViewPosting" />
</asp:Content>
</form>
Also - check that your ~/Site.Master file contains the <form runat="server"> if not -a s it would be fairly typical for that to be the place to have your all enclosing form tag.
You could read more here: http://www.w3schools.com/aspnet/aspnet_forms.asp
If you put right of runat="server" but still error, please try this code.
public override void VerifyRenderingInServerForm(Control control)
{
/* Confirms that an HtmlForm control is rendered for the specified ASP.NET
server control at run time. */
}
cr. from Rohit Rao
sorry for my bad skill English.
All server controls must appear within a <form> tag, and the <form> tag must contain the runat="server" attribute.
All the Asp.net controls are server controls,so these should be placed within form tag with runat="server" attribute, like this
<form runat="server">
place server controls here...
</form>
>Button bt = new Button();
>bt.ID = "dd";
>bt.Text = "Click Me";
>this.Form.Controls.Add(bt);
you can add
<form runnat="server">
// add content placeholder
</form>
I have created a user control for visitor to subscription of newsletter.
UserControl is withing the update-panel and is added to the main master-page.
Problem with the control is that Subscribe button is not firing for some reason
User control markup:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table cellpadding="0" cellspacing="0" class="PrayerTimeWrapper">
<tr>
<td align="center">
<table cellpadding="0" cellspacing="0" class="PrayerTimeInnerWrapper" border="0">
<tr>
<td valign="top">
<div class="dHeading"><asp:Label ID="lblTitle" runat="server" Text="JOIN US"></asp:Label></div>
<div class="dName">
<asp:TextBox ID="txtName" CssClass="txtSubscribe" runat="server" Text="NAME" onfocus="if(this.value=='NAME')this.value='';" onblur="if(this.value=='')this.value='NAME';"></asp:TextBox>
</div>
<div class="dEmail">
<asp:TextBox ID="txtEmail" CssClass="txtSubscribe" runat="server" Text="YOUR EMAIL" onfocus="if(this.value=='YOUR EMAIL')this.value='';" onblur="if(this.value=='')this.value='YOUR EMAIL';"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEmailSub" runat="server" ErrorMessage="*"
ControlToValidate="txtEmail" ValidationGroup="SubEmail" ></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revEmailSub" runat="server"
ErrorMessage="*" ControlToValidate="txtEmail" ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"
ValidationGroup="SubEmail" ></asp:RegularExpressionValidator>
</div>
<div class="dSubmit">
<asp:Button ID="btnSubscribe" CssClass="btnSubscribe" runat="server" Text="Subscribe" onclick="btnSubscribe_Click" />
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
User control code-behind:
protected void btnSubscribe_Click(object sender, EventArgs e)
{
Response.Write("Test");
}
Markup of the page which is using master-page:
<%# Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="PrayerTiming.aspx.cs" Inherits="PrayerTiming" %>
<%# Register Src="~/en/UserControls/ucSubscribe.ascx" TagName="Subscribe" TagPrefix="uc"%>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
<div align="center" id="table"></div>
<uc:Subscribe id="ucSB" runat="server" UpdateMode="Conditional" />
</asp:Content>
I am doing something wrong somewhere but i am not sure what. I would appreciate help on this.
Using Resonse.Write during an asynch resquest can altere the data used to update proprely the controls within the update panel.
so instead of Response.Write("Test") use a Label.Text = "Test"
Set the ValidationGroup for the btnSubscribe button also
<asp:Button ID="btnSubscribe"
CssClass="btnSubscribe" runat="server"
Text="Subscribe"
onclick="btnSubscribe_Click"
ValidationGroup="SubEmail" />
UPDATE
From what I've seen in the comments and in the other answers, the only reason why the button didn't post the content to the server is because it didn't subscribe to that validation group. The ValidationGroup is used to separate certain views (group of controls) in a page so they use their own validation. For example a forgot password section and a login section would have two different validation groups so when a certain button is clicked only its section is validated.
I did this update, because I truly think that the accepted answer is more a debuging advice than an actually answer. A future SO reader might jump to use this guideline instead of seeing the problem.
Try puting UpdatePanel in form tag with runat="server"...