Wednesday, March 28, 2012

postback happens even when validators show error

Hi,

I am using updatepanel in my code. I give a picture of a part of my code.

Now i have a text box with some validators on it ( required field validator and regular expression validator).

I have a save button which saves the content of the text box .

The textbox is withing the update panel and the save button is outside the update panel.

Now when a wrong iput is entered , on tab out the validator shows the error messgae but on clicking th ebutton , a post back happens. in general case where a update panel is not used the button postback event doesnt happen until the validators return true.

Could you help me on this.

Regards,

Sama

any resolution to this problem yet?

this really needs to be fixed


I also have come across this problem. I have three validators on the footer row of a gridview which is in an UpdatePanel. I use the footer for insertion of new records. When I click 'Insert', the validators fire ok and I get the red asterisks and all but it still posts back. When I take the whole thing out of the UpdatePanel it works as it's supposed to, preventing the postback if no data is entered.

I am using the latest version of Atlas.

Has anyone a solution to this and is it going to be fixed in a future ctp?

Regards,

Andy.


I just investigated further and found the following strage behaviour:

When my page first loads, the gridview is populated with data. The footer is not visible on the gridview as I set ShowFooter() to false by default. There is a button at the bottom of the page "Add Item". This posts back and sets the ShowFooter() to true so that the insert line appears. In this scenario, when the user leaves the new text fields blank, the validator fires but the page still posts back - WRONG.

If I show the footer by default when the page loads, the validators fire correctly and prevent the postback - CORRECT.

Can anyone shed any light on this, I don't want to have my insert line shown by default.

Andy.


bump...

Postback in FF

Hi All,

I have used ajaxcontrol toolkit in my application.
I have also implemented autosuggest list using classic XMLHTTP.
when I type search keyword in textbox it populates list , from list when I select record and hit enter key entire page is postback.

Please help me for same.

Hi Mukseshzala,

Based on your description, I think you should better use AutomComplelte control + WebService. Just like ths. You can get the whole source code from Ajax ControlToolkit Control.

Mukeshzala:

when I type search keyword in textbox it populates list , from list when I select record and hit enter key entire page is postback.

Please add this to your page , the onItemSelected function will be fired when click on the items.

<script type="text/javascript" language="javascript">
function pageLoad(){
$find("AutoCompleteEx").add_itemSelected(onItemSelected);
}
function onItemSelected(sender,eventArgs){
alert(sender.get_element().id);
}
</script>

I hope this help.

Best regards,

Jonathan

PostBack is happening even after using Update Panel and Script Manager

Hi,

I have a ASP.NET web application. I have a gridview and using a RowDataBound andRaisePostBackEventevent for getting the GridView details in the controls below like textboxes, dropdown etc. Now i am using Ajax Extensions controls like Update Panel and Script manager to avoid a postback happening when the GridView row is clicked. Even after implementing them postback is happening. Please see the code bits and let me know if i am missing somewhere.

UI

<asp

:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering="true"></asp:ScriptManager>

<

asp:UpdatePanelid="UpdatePanel1"runat="server"UpdateMode="Conditional">

<contenttemplate>

<asp:GridViewID="GridView1"runat="server"OnRowDataBound="GridView1_RowDataBound"CssClass="sampletable"AlternatingRowStyle-CssClass="d1"ShowHeader="true"ShowFooter="false"AllowPaging="true"AllowSorting="true"AutoGenerateColumns="false"DataKeyNames="ProjectID"Width="100%"PageSize="5"><Columns>

<asp:BoundFieldVisible="false"HeaderText="Project ID"DataField="ProjectID"SortExpression="ProjectID"/><asp:BoundFieldHeaderText="Project Name"DataField="ProjectName"SortExpression="ProjectName"/><asp:BoundFieldHeaderText="Site Name"DataField="SiteName"SortExpression="SiteName"/></Columns></asp:GridView><asp:LabelID="Label1"runat="server"Text="Label"></asp:Label><asp:TextBoxID="TextBox1"runat="server"></asp:TextBox><asp:ButtonID="Button1"runat="server"Text="Button"/>

</

contenttemplate>

<

Triggers>

<

asp:AsyncPostBackTriggerControlID="GridView1"EventName="RowDataBound"/>

</

Triggers>

</

asp:UpdatePanel>

And theCode behind for RowDatabound event is

protected

void GridView1_RowDataBound(object sender,GridViewRowEventArgs e)

{

try

{

if (!((e.Row.RowType ==DataControlRowType.Pager) || (e.Row.RowType ==DataControlRowType.Header) || (e.Row.RowType ==DataControlRowType.Footer)))

{

System.Web.UI.

ClientScriptManager cs = Page.ClientScript;//Assign Row Index. This row index used in finding the ID of the clicked rowint intRowIndex = e.Row.RowIndex;

e.Row.Attributes.Add(

"onClick", cs.GetPostBackEventReference(this, intRowIndex.ToString().Trim()));

e.Row.Attributes.Add(

"onKeyDown","if( event.keyCode == 13 ) " + cs.GetPostBackEventReference(this,"KEYDOWN" +"$" + e.Row.DataItemIndex.ToString().Trim()));

}

}

catch (System.Exception ex)

{

//OnError(ex);

}

}

The code looks good, did you try a easy test to see if the postback is hidden?

http://alpascual.com/blog/al/archive/2006/12/21/Code-Snip-_2200_AJAX-Timer_2200_.aspx

Try the sample below and let me know if you see the postback


Thanks for the Quick Response.

But i could not get exactly what you want to convey.

regards,

Parimal


Ok, wrap a asp:button around an updatepanel and let me know if you see the postback

Hi,

The button is working fine without any post back. The Post back is happening when Grid Row is clicked as it call the RaisePostBack event to get the Row details. That event is coded as we have not used any command template in Grid.

regards,

Parimal


OnRowDatabound would not make sense for an async trigger. The user clicking the row and getting a postback via the javascript you added to the onclick is not the same. If you take out the trigger and just add ChildrenAsTriggers="true" to the UpdatePanel it would probably work as you expect.

One other thing - in this code:

"onClick", cs.GetPostBackEventReference(this, intRowIndex.ToString().Trim()));

e.Row.Attributes.Add(

"onKeyDown","if( event.keyCode == 13 ) " + cs.GetPostBackEventReference(this,"KEYDOWN" +"$" + e.Row.DataItemIndex.ToString().Trim()));

Change "this" to GridView1. You want to create a postback for your gridview, not the whole page. Since you're creating a custom postback you'll also need to register for event validation, or disable event validation in your page.


Thanks for the response. But still post back is happening. I will explain in details

1. I have a Gridview RowDataBound event which fires when Data is bounded to Grid.

2. I have aRaisePostBackEvent which fires when the row in the Grid is selected and this causes the Post Back event.

3. Aslo my UserControl is implementingIPostBackEventHandler interface.

Thanks in Advance,

Parimal

Postback inside of AJAX Rounded Corners Extender problem

Hello everyone. I have learned alot through this site and finally joined because I can't seem to find a fix for my problem and I was hoping that you guys could help me out.

I have a DropDownList with a SqlDataSource inside a panel with an AJAX rounder corners extender. It seems that the page shows itself without the extenders applied but then flashes and shows the extenders applied to the controls.

If I take the DropDownList and SqlDataSource out of the panel I know longer get the screen flash, but the extenders do take a second to show on the controls.

What is the fix for the Screen flash? And, If possible, how can I delay the display of the controls so that the AJAX extenders are applied before showing the controls?

Thanks for your help!

Rusty

Try putting Panel in a UpdatePanel

Thanks for the suggestion, but putting the Panel in an Update Panel didn't work. The screen still flashes. Here is my code with the update panel.

<

divid="master_page"><asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><cc1:RoundedCornersExtenderID="RoundedCornersExtender2"runat="server"TargetControlID="Panel2"Radius="10"></cc1:RoundedCornersExtender><asp:PanelID="Panel2"runat="server"Height="1000"Width="100%"BackColor="ForestGreen"><asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"SelectCommand=""></asp:SqlDataSource><asp:DropDownListID="InfoDDLB"runat="server"AutoPostBack="True"DataSourceID="SqlDataSource1"DataTextField="Name"DataValueField="ID"OnTextChanged="GetInfo"Width="100"><asp:ListItemSelected="True"Value="0">Select Something...</asp:ListItem></asp:DropDownList></asp:Panel></ContentTemplate></asp:UpdatePanel><asp:contentplaceholderid="ContentPlaceHolder1"runat="server"></asp:contentplaceholder></div>
Anything else I can try?

1. When I put your code in UpdatePanel there wasno flash when I changed value in DropDownList.

2. The RoundedCornersExtender should have ajaxtoolkit prefix, unless you have changed tag attribute in your web.config file

3. Depending on how much data you are fetching in the dropdown list, it will take longer to apply rounded corners effect.

The simple reason is javascript executed by rounded corner starts executing after you panel is completely loaded and size (height and width) is determined. Also, the more javascript/ajax calls you use the slower it gets, as javascript gets slower and slower as size increases.

PS: You can turn off debugging in web.config file by setting <compilation debug="false">. This will speed up Ajax scripts as they don't make any debug calls. And you won't see a delay.


2. I have the following entry in my web.config file for the AJAX controls:

<

addtagPrefix="cc1"namespace="AjaxControlToolkit"assembly="AjaxControlToolkit"/>

3. I am not fetching anything into the dropdown list.

I also turned off the debugger.

I have done further investigation and it turns out that I don't need the SqlDataSource tied to the DropDownList to get the flash. The only control that makes the screen flash is this DropDownList. When replaced with a textbox or button there is no flash. The first Example below shows the flash when the page is loaded and the "Push Me" Butotn is clicked. The second example has the DropDownList outside of the Panel and doesn't have a flash when the page loads or the "Push Me" button is clicked.

EXAMPLE 1: (SCREEN FLASH - OnPage load and 'Push Me' Button Clicked)

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" id="ScriptManager1" />
<div align="right" style="margin-right: 10px">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<cc1:DropShadowExtender ID="DropShadowExtender1" Opacity=".5" Radius="2" TargetControlID="Panel5" runat="server" Rounded="True">
</cc1:DropShadowExtender>
<asp:Panel backcolor="orange" id="Panel5" runat="server" Height="100px" Width="200px">
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Push Me" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

EXAMPLE 2: (NO SCREEN FLASH - OnPage load and 'Push Me' Button Clicked)

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" id="ScriptManager1" />
<div align="right" style="margin-right: 10px">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<cc1:DropShadowExtender ID="DropShadowExtender1" Opacity=".5" Radius="2" TargetControlID="Panel5" runat="server" Rounded="True">
</cc1:DropShadowExtender>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:Panel backcolor="orange" id="Panel5" runat="server" Height="100px" Width="200px">
<asp:Button ID="Button1" runat="server" Text="Push Me" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

Thanks for your help!

Rusty


I tried your code same results both times no flash. Although as I said before, it takes fraction of a second(1/10 or even less) to apply the DropDownExtender (being a javascript). It is not noticable at all.

What browser you are using? I've read many complaints related to AJAX and IE 6. I'm using IE 7.

Please try with other browsers and see you have the same issue.

Let me know. Will be glad to help you out.


Yes, that's what it was. I updated from IE6 to IE7 on one of my computers and tried the page and there is no flashing issues. So, is there a recommendation for a solution for IE6 users when viewing my website?

Your help is greatly appreciated!

-Rusty


for IE 6 you can use filter instead of RoundedExtendedCorners.

<DIV ID="oFilterDIV" STYLE="cursor:hand;height:160px; padding:10px; font:bold 13pt verdana;
filter:progid:DXImageTransform.Microsoft.dropshadow(OffX=5, OffY=5,
Color='gray', Positive='true')" onclick="fnDepress();">
This is the DIV content.</DIV>

More about filters is herehttp://msdn.microsoft.com/library/default.asp?url=/workshop/author/filter/reference/filters/dropshadow.asp

Now on server-side you can check Browser's version (Request.Browser.Version) and then enable/disable RoundedCornerExtender as well as set CSSClass or Style property of the Asp:Panel control to use or not use filters.

Filters are specific to IE. They don't work in FireFox or other browsers.


postback inside modalpopupextender

I want to show a modalpopupextender that contains: a textbox ,A button, gridview, ok button , close button: when the user click on A button the gridview must be populated , I need this behavior inside the modalpopupextender but it seems like modalpopupextender does not support any control that make a postback, How can I manage this??

Best Regards

Joseph

I already have done this what you need to do is,

let say. btnSearch popups your ModalpopupExtender,

when you click in side the control do one thing only in the code behind, of that click event either grid pageindexchange, sortiung, any button click in the last. that is.

ModalPopupExtender1.Show()

it will keep showing the popup until you click close button or call a method.

ModalPopupExtender1.Hide()

It is trial and tested, even I have done more than this in my application.

IF THIS MAKES ANSWER PLEASE CLICK ANSWER ON MY POSTING

Regards,


Hi Killerjocker,

My understanding of your issue is that you want to show some controls include the GridView and generate(update) the content inside it when click on the Button which is associated with the ModalPopupExtender. If I have misunderstood, please feel free to let me know.

In my opnion, I think the easiest way for your situation is adding a UpdatePanel into the Panel which is associated with the ModalPopupExtender and the GridView is put inside the added UpdatePanel. When user click on the Button, the UpdatePanel will be refreshed by sending a asynchronous post and then the shows the ModalPopupExtender. Here is a sample:

<%@. Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server"
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<style>
.modalBackground {
background-color:Gray;
filter:alpha(opacity=70);
opacity:0.7;
}

.modalPopup {
background-color:#FFD9D5;
border-width:3px;
border-style:solid;
border-color:Gray;
padding:3px;
width:250px;
}
</style>

</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Button ID="Button2" runat="server" Text="Button" Enabled="false" style="display:none"/>
<asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Height="50px" Width="235px" style="display:none" DefaultButton="Button4">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<%=DateTime.Now.ToString()%>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="Button1" runat="server" Text="Cancel" />
<asp:Button ID="Button4" runat="server" Text="Button" />
</asp:Panel>

<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="Button2" PopupControlID="Panel1" CancelControlID="Button1" DropShadow="true" BackgroundCssClass="modalBackground">
</ajaxToolkit:ModalPopupExtender>
<input id="Button3" type="button" value="Click Me" onclick="showModalPopup()"/>
<script type="text/javascript" language="javascript">
function showModalPopup(){
__doPostBack('<%=UpdatePanel1.UniqueID%>','');
$find("<%= this.ModalPopupExtender1.ClientID%>").show();
}
</script>
</form>
</body>
</html>

I hope this help.

Best regards,

Jonathan

Postback issue

In my page, there are a lots of toolkit controls and gridvidw. Sometime when I postpack partially inside a UpdatePanel, I got the following message in a popup message box:

Invaid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <% Page EnableEventValidation="true" %> in page. For security purposes,this fuature verifies that arguments to postbalc or callback events originate from the server control that orginally rendered them. If the data is valid and expected, use the ClientScriptManager.RegiterForEventValidation method in order to register the postback or callback data for validation.

For example, in gridview with paging, when I click on page numnber, sometimes the above message will come out. It comes out randomly. If I refresh the page, it will fix this issue.

How to solve this issue?

The pics you posted are not visible.

A potentially dangerous Request.Form value was detected from the client (ctl00$ctl00$ctl00$ctlToAdd1$ctl00$ctlHeaderFooter$ctl00$txtPageHeader="<p>DO NOT ATTEMPT TH...").

Description: Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. You can disable request validation by setting validateRequest=false in the Page directive or in the configuration section. However, it is strongly recommended that your application explicitly check all inputs in this case.

Exception Details:System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (ctl00$ctl00$ctl00$ctlToAdd1$ctl00$ctlHeaderFooter$ctl00$txtPageHeader="<p>DO NOT ATTEMPT TH...").

Source Error:

[No relevant source lines]


Source File:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\siteseasytest\b32181f7\172c3a32\App_Web_yzjzpobg.2.cs Line:0

Stack Trace:

[HttpRequestValidationException (0x80004005): A potentially dangerous Request.Form value was detected from the client (ctl00$ctl00$ctl00$ctlToAdd1$ctl00$ctlHeaderFooter$ctl00$txtPageHeader="<p>DO NOT ATTEMPT TH...").]

System.Web.HttpRequest.ValidateString(String s, String valueName, String collectionName) +3219550

System.Web.HttpRequest.ValidateNameValueCollection(NameValueCollection nvc, String collectionName) +108

System.Web.HttpRequest.get_Form() +119

System.Web.HttpRequest.get_HasForm() +57

System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +2025201

System.Web.UI.Page.DeterminePostBackMode() +60

System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6953

System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +154

System.Web.UI.Page.ProcessRequest() +86

System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +18

System.Web.UI.Page.ProcessRequest(HttpContext context) +49

ASP.communitydefault_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\siteseasytest\b32181f7\172c3a32\App_Web_yzjzpobg.2.cs:0

System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +154

System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64


Jason, If you are using code behind to control what gets added to a PlaceHolder for instance...

In ATLAS - we simply issued the

UpdatePanelModal.Update();

Because viewstate would get mucked up. (Article on my blog about this)

In Beta - I find that anytime you issue that command - it causes the error ... I think when mode is conditional - it works but not sure - as I am being forced to use always due to databound controls dissapearing on a modal popup and have not heard any feedback on the issue...

If you are not using code behind to handle - can you post a simple code example that demonstrates the issue?


Jason, I have written down the message text in message box. Forget the pic.


jodywbcb, what's your post for my question?

Postback Multitask progress bar (ajax)

hello

I have a asp.net page that takes several actions uppon a button click.

Suppose this page triggers 3 functions on that button click: (THIS IS JUST AN EXAMPLE)
1) Saves data to local data base
2) Export data do internet data base
3) send emails to 50 users reporting this update

What I want to do is show the user wich action the server is performing at the moment.
basically, it should show (on a Modal PopUP, i figure) all the 3 steps taken.
1) ...saving data...
2) ...exporting data ...
3) ... notifying users ...

does anyone have a solution for this?

thanks

Checkout this threadhttp://forums.asp.net/t/1133013.aspx