Showing posts with label updatepanel. Show all posts
Showing posts with label updatepanel. Show all posts

Wednesday, March 28, 2012

Page.ClientScript.RegisterStartupScript in updatepanel problem with Beta1.0 ??

Open a new window fails!!! (but with CTP OK!)

protected override void OnClick(EventArgs e)
{
if (grid != null && grid.DataKeyNames.Length > 0)
{
int[] selected = grid.GetSelectedIndexes();
if (selected.Length > 0)
{
grid.SelectedIndex = selected[0];
DataKey dataKey = grid.SelectedDataKey;
if (dataKey != null)
{
string separator1;
if (DialogNavigateUrl.ToString().IndexOf("?") != -1)
{
separator1 = "&";
}
else
{
separator1 = "?";
}
StringBuilder sb = new StringBuilder();
string separator2 = string.Empty;
IDictionaryEnumerator enumerator = dataKey.Values.GetEnumerator();
while (enumerator.MoveNext())
{
sb.Append(separator2);
sb.Append(enumerator.Key);
sb.Append("=");
sb.Append(enumerator.Value);
separator2 = "&";
}
string format;
format = "window.open('{0}{5}{6}{7}Parent={4}',null,'height={1},width={2},status=1,toolbar=0,menubar=0,location={3},resizable=1,scrollbars=1');";
string script =
String.Format(CultureInfo.CurrentCulture, format, DialogNavigateUrl.ToString().Replace("~/", ""), DialogHeight.Value, DialogWidth.Value,
Convert.ToByte(DialogLocation), this.ClientID, separator1, sb.ToString(), separator2);
Type type = this.GetType();
if (!Page.ClientScript.IsStartupScriptRegistered("clientScript"))
{
Page.ClientScript.RegisterStartupScript(type, "clientScript", script, true);
}
}
}
}
base.OnClick(e);
}

For the control to work inside an UpdatePanel you need to call the new static registration APIs on the ScriptManager class. They have basically the same parameters as the Page.ClientScript methods but the new first parameter is the control doing the registration (usually "this").

Thanks,

Eilon


More info about script registration in my recent post:http://forums.asp.net/thread/1440058.aspx

Thanks,

Eilon

Page_Load and ajax

I have a simple question. when I use an UpdatePanel control, it is not supposed to refresh the page entirely, only a part of the page.

But why it calls Page_Load event ?

Here's the example used :

<!-- <Snippet2> -->
<%@dotnet.itags.org. 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">
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Search_Click(object sender, EventArgs e)
{
SqlDataSource1.SelectParameters["SearchTerm"].DefaultValue =
Server.HtmlEncode(SearchField.Text);
Label1.Text = "Searching for '" +
Server.HtmlEncode(SearchField.Text) + "'";
}

protected void ExampleProductSearch_Click(object sender, EventArgs e)
{
SqlDataSource1.SelectParameters["SearchTerm"].DefaultValue =
Server.HtmlEncode(ExampleProductSearch.Text);
Label1.Text = "Searching for '" +
Server.HtmlEncode(ExampleProductSearch.Text) + "'";
SearchField.Text = ExampleProductSearch.Text;
}
</script
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>UpdatePanel Trigger Example</title>
<style type="text/css">
body {
font-family: Lucida Sans Unicode;
font-size: 10pt;
}
button {
font-family: tahoma;
font-size: 8pt;
}
</style>
</head>
<body>
<form id="form1" runat="server"
defaultbutton="SearchButton" defaultfocus="SearchField">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />

Search for products in the Northwind database. For example,
find products with
<asp:LinkButton ID="ExampleProductSearch" Text="Louisiana" runat="server" OnClick="ExampleProductSearch_Click">
</asp:LinkButton> in the title. <br /><br />
<asp:TextBox ID="SearchField" runat="server"></asp:TextBox>
<asp:Button ID="SearchButton" Text="Submit" OnClick="Search_Click"
runat="server" />

<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional"
runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="SearchButton" />
</Triggers>
<ContentTemplate>

<asp:Label ID="Label1" runat="server"/>
<br />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" DataSourceID="SqlDataSource1">
<EmptyDataTemplate>
No results to display.
</EmptyDataTemplate>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Data Source=.\SQLEXPRESS;AttachDbFilename='H:\Program Files\Microsoft ASP.NET\ASP.NET AJAX Sample Applications\v1.0.61025\Contacts\App_Data\Contacts.mdf';Integrated Security=True;User Instance=True"
SelectCommand="SELECT [Location] FROM
Contacts WHERE ([FirstName] LIKE
'%' + @dotnet.itags.org.SearchTerm + '%')">
<SelectParameters>
<asp:Parameter Name="SearchTerm" Type="String" />
</SelectParameters>
</asp:SqlDataSource>

</ContentTemplate>
</asp:UpdatePanel>

</div>
</form>
</body>
</html>
<!-- </Snippet2> -->

Here's some background info:
http://ajax.asp.net/docs/Overview/intro/partialpagerendering/updatepanelOverview.aspx (see third section on How UpdatePanel's Work)

Basically, during an async postback, the full server page life cycle is executed to the point of rendering similar to a "regular" postback. At the render phase for an async postback the framework determines that only the content of UpdatePanels need to be refreshed.

If you want to not run code during an async postback, use the ScriptManager.IsInAsyncPostBack to check if you are in async postback and then take action.

http://ajax.asp.net/docs/mref/db2bbeac-e762-e1ac-ca74-1a3e6ab76979.aspx

PageError event of scriptmanager not firing

I have a content page that has a master page. I have an updatepanel and a scriptmanger in my content page. I defined a handler for OnPageError for the scriptmanager and defined a error template for the scriptmanager but when I set the e.errormessage in the OnPageError event, but if I set a break point in the event, the break point is never reached and the error message in the template still displays 'unknown error' Any ideas?

if I put a button on the page and in the click event of the button i manually throw and error.

thrownewException("error button clicked");

the event fires and works fine.

but if I put some invalid characters like '<img src' inside a textbox and then click the button (removing the throw) then the OnPageError isn't fired

pageLoaded event

I have created an ASP.NET custom server control that is updated using AJAX via an UpdatePanel using the Tick event of a Timer control as the asyc trigger. I need to execute javascript each time a partial postback returns so I am using the pageLoaded event. This works perfectly in IE7 but doesn't fire in Firefox 2.0.0.3 or Opera 9. On other browsers it never fires the pageLoaded event, but it does the AJAX updating and other javascript works. I am registering the client code during my control's render method.. I have also tried using the endRequest event. Please help. Why won't it work on other browsers.

Below is the rendered HTML:<!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><title>Untitled Page</title><meta content="text/html;charset=iso-8859-1" http-equiv="content-type" /><meta content="NO-CACHE" http-equiv="PRAGMA" /><meta content="NO-CACHE" http-equiv="CACHE-CONTROL" /><meta content="0" http-equiv="EXPIRES" /><style type='text/css'> a.info:active{z-index:0; position:relative; background-color:#FFF647} a.info label{display: none} a.info:active label{ display:inline; position:absolute; white-space:normal; text-wrap:normal; word-wrap:break-word; left:label.parent.width; top:label.parent.height; width:250px; border:1px solid #91907C; background-color:#EAE7C6; z-index:-1; } </style> </head><body> <form name="form1" method="post" action="Default.aspx" id="form1"><div><input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /><input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /><input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTEwMzQxMTA4OTkPZBYCAgMPZBYCAgEPZBYCAgIPZBYCZg9kFgJmDxYGHgtjZWxscGFkZGluZwUBMB4LY2VsbHNwYWNpbmcFATAeBXN0eWxlBSlwYWRkaW5nOjVweDt6LWluZGV4OjIwO3Bvc2l0aW9uOmFic29sdXRlO2RkMUSTfpjSwghJETl9/Jgkha9oZaA=" /></div><script type="text/javascript"><!--var theForm = document.forms['form1'];if (!theForm) { theForm = document.form1;}function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); }}// --></script><script src="/WebResource.axd?d=9DvoInn8tlftzCiBPvQagg2&t=632974035101093750" type="text/javascript"></script><script src="/ScriptResource.axd?d=WAnysv6JNp-Tgl_8AndGJnGXdfOUUPdccvGwkhkSJu2uP8RLi_go1jCrdTe0jCpJF0u8GYhfCflHcjQdOJTaXMeB6qn3C9aitPrPuScmgSM1&t=633063657262888841" type="text/javascript"></script><script src="/ScriptResource.axd?d=WAnysv6JNp-Tgl_8AndGJnGXdfOUUPdccvGwkhkSJu2uP8RLi_go1jCrdTe0jCpJF0u8GYhfCflHcjQdOJTaXOmCYkHGf_k8diSD9UcMEoc1&t=633063657262888841" type="text/javascript"></script><script src="/ScriptResource.axd?d=WAnysv6JNp-Tgl_8AndGJnGXdfOUUPdccvGwkhkSJu2uP8RLi_go1jCrdTe0jCpJF0u8GYhfCflHcjQdOJTaXLsHgXZk2LxHv8oSN-rIGKs1&t=633063657262888841" type="text/javascript"></script> <span id="events" style="font-size:Small;"><span id="events_timer1" style="visibility:hidden;display:none;"></span><input name="events$ctl00" type="hidden" id="events_ctl00" /><div id="events_UpdatePanel1"><table cellpadding="0" cellspacing="0" style="padding:5px;z-index:20;position:absolute;"><tr><td rowspan="2" style="border-bottom-style:None;border-bottom-color:#91907C;border-bottom-width:thin;padding-bottom:5px;padding-top:5px;"><img src="../images/greenshd.gif" alt="The IT Road Show.........................." /></td><td style="padding-left:5px;">Tuesday 24 Apr</td><td style="padding-left:15px;">3:30 pm</td></tr><tr><td colspan="2" style="border-bottom-style:None;border-bottom-color:#91907C;border-bottom-width:thin;padding-left:5px;padding-bottom:5px;"><a href="http://www.nova100.com.au" id="events_3160" EventsEventDatesId="3160" LabelId="events_label_0_3160" onfocus="document.getElementById('events_ctl00').value = this.LabelId" onblur="document.getElementById('events_ctl00').value = ''" class="info">The IT Road Show.......................... </a></td></tr><tr><td rowspan="2" style="border-bottom-style:None;border-bottom-color:#91907C;border-bottom-width:thin;padding-bottom:5px;padding-top:5px;"><img src="../images/AKMAL_OVER.gif" alt="The Akmal Show" /></td><td style="padding-left:5px;">Tuesday 24 Apr</td><td style="padding-left:15px;">4:00 pm</td></tr><tr><td colspan="2" style="border-bottom-style:None;border-bottom-color:#91907C;border-bottom-width:thin;padding-left:5px;padding-bottom:5px;"><a href="#" id="events_2749" EventsEventDatesId="2749" LabelId="events_label_1_2749" onfocus="document.getElementById('events_ctl00').value = this.LabelId" onblur="document.getElementById('events_ctl00').value = ''" class="info">The Akmal Show <label id="events_label_1_2749" style="text-decoration:none;">The Akmal Show with Kate Richie Weekdays 4pm-6pm.Akmal was born in Egypt - then moved to Australia. Akmal's mum doesn't think he's that funny - now the rest of Australia think he's ha haa hilarious.</label></a></td></tr><tr><td rowspan="2" style="border-bottom-style:None;border-bottom-color:#91907C;border-bottom-width:thin;padding-bottom:5px;padding-top:5px;"><img src="../images/greenshd.gif" alt="The IT Road Show.........................." /></td><td style="padding-left:5px;">Wednesday 25 Apr</td><td style="padding-left:15px;">3:30 pm</td></tr><tr><td colspan="2" style="border-bottom-style:None;border-bottom-color:#91907C;border-bottom-width:thin;padding-left:5px;padding-bottom:5px;"><a href="http://www.nova100.com.au" id="events_3161" EventsEventDatesId="3161" LabelId="events_label_2_3161" onfocus="document.getElementById('events_ctl00').value = this.LabelId" onblur="document.getElementById('events_ctl00').value = ''" class="info">The IT Road Show.......................... </a></td></tr><tr><td rowspan="2" style="border-bottom-style:None;border-bottom-color:#91907C;border-bottom-width:thin;padding-bottom:5px;padding-top:5px;"><img src="../images/AKMAL_OVER.gif" alt="The Akmal Show" /></td><td style="padding-left:5px;">Wednesday 25 Apr</td><td style="padding-left:15px;">4:00 pm</td></tr><tr><td colspan="2" style="border-bottom-style:None;border-bottom-color:#91907C;border-bottom-width:thin;padding-left:5px;padding-bottom:5px;"><a href="#" id="events_2750" EventsEventDatesId="2750" LabelId="events_label_3_2750" onfocus="document.getElementById('events_ctl00').value = this.LabelId" onblur="document.getElementById('events_ctl00').value = ''" class="info">The Akmal Show <label id="events_label_3_2750" style="text-decoration:none;">The Akmal Show with Kate Richie Weekdays 4pm-6pm.Akmal was born in Egypt - then moved to Australia. Akmal's mum doesn't think he's that funny - now the rest of Australia think he's ha haa hilarious.</label></a></td></tr><tr><td rowspan="2" style="padding-bottom:5px;padding-top:5px;"><img src="../images/redshd.gif" alt="test add 25" /></td><td style="padding-left:5px;">Thursday 26 Apr</td><td style="padding-left:15px;">2:29 pm</td></tr><tr><td colspan="2" style="padding-left:5px;padding-bottom:5px;"><a href="k" id="events_136" EventsEventDatesId="136" LabelId="events_label_4_136" onfocus="document.getElementById('events_ctl00').value = this.LabelId" onblur="document.getElementById('events_ctl00').value = ''" class="info">test add 25 </a></td></tr></table></div></span> <script type="text/javascript">//<![CDATA[Sys.WebForms.PageRequestManager._initialize('ctl06', document.getElementById('form1'));Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tevents$UpdatePanel1'], ['events','events$timer1'], [], 90);//]]></script><script type="text/javascript"><!--Sys.Application.add_init(function() { $create(Sys.UI._Timer, {"enabled":true,"interval":1000,"uniqueID":"events$timer1"}, null, null, $get("events_timer1"));}); Type.registerNamespace('EventsManager'); var prm = Sys.WebForms.PageRequestManager.getInstance(); if (prm != null) { prm.add_endRequest(pageLoadedHandler); } function window.onload() { } function pageLoadedHandler(sender, args) { var hidden = document.getElementById('events_ctl00'); if (hidden != null) { var labelId = hidden.value; if (labelId.length > 0) { var lbl = document.getElementById(labelId); if (lbl != null) { lbl.parentElement.setActive(); } } } } Sys.Application.initialize();// --></script></form> </body></html>

Below is my code for the Render method when I used the endRequest event:

protected override void Render(HtmlTextWriter writer) {base.Render(writer);//Add script and register it. Page.ClientScript.RegisterStartupScript(typeof(EventsManager),"script", @dotnet.itags.org." Type.registerNamespace('EventsManager'); var prm = Sys.WebForms.PageRequestManager.getInstance(); if (prm != null) { prm.add_endRequest(pageLoadedHandler); } function window.onload() { } function pageLoadedHandler(sender, args) { var hidden = document.getElementById('" + ClickedLinkLabelId.ClientID + @dotnet.itags.org."'); if (hidden != null) { var labelId = hidden.value; if (labelId.length > 0) { var lbl = document.getElementById(labelId); if (lbl != null) { lbl.parentElement.setActive(); } } } } ",true); }

Hi,

Can you show me a stripped version of your control and a sample page using it?

It will be easier for us to trouble shooting. Thanks.


Hi Raymond,

I really appreciate your offer of help, but I just figured out what the problem was.

My javascript code below was causing a problem for all the code in my script block on all browsers apart from IE.

Problem code:

function window.onload()
{

}

When I changed it to the code below, it worked in all browsers.

Correct code:

window.onload = function()
{
document.getElementById('" + TimeZoneOffset.ClientID + @."').value = -(new Date().getTimezoneOffset());
}

Thanks again.

Monday, March 26, 2012

PageMethods vs UpdatePanel

Hi,

I am a big fan of using 'Update Panels'. Not because of the only simplicity but also bcoz of my belief on the AJAX framework.

Also Scott G has kept on introdcueicng lots of new features in UpdatePanel in Orcas/S 2008


But,still lots of architects do say that, PageMethods[http://metasapiens.com/PageMethods/Tutorial/VS2005/] are moreefficient than Update Panels.
Here is the link - ASP.NET AJAX UpdatePanels are dangerous.

http://encosia.com/2007/07/11/why-aspnet-ajax-updatepanels-are-dangerous/

Afterreading the page, I am quite suspicious on Update Panel and now thinkthat really PageMethods saves perfomance overhead.But at the same time,simply by going thru few pages, accepting the same seems to be quiteimpractical.

Please let me know, is really PageMethods are moreefficient than UpdatePanel. If yes, then please list me the things thatcannot be done using PageMethods, which can be done by UpdatePanel.

Regards,

Arun

take a look at the video byJoe Stagner

How Do I: Choose Between Methods of AJAX Page Updates?

http://www.asp.net/learn/ajax-videos/video-160.aspx

It will show you the big diference...

And the response by the WebMethod, give you the freedom to manipulate and interact with the HTML elements (UI) way you want ..

PageRequestManagerParseErrorException

Hello. I'm have the problem with UpdatePanel. When the user does click on de button I call a method

Button1_Click

This method call other page in modo modal where the user type a password. If this password is ok I'll try to use

UpdatePanell2.Update() but I can′t call the page2 in modo modal because appear this error.

Read this to avoid this issue:

http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx

PageRequestManagerParserErrorException in Firefox 2

Hi,

My website is using Ajax with UpdatePanel which is working well in IE 7. However, I keep getting the PageRequestManagerParserErrorException when I am testing it in Firefox 2. I am currently using the AJAX Beta 2. I also check to make sure there is no Response.Write while the page is postback. But the error keep poping up in Firefox. Does any know a solution for this?


Many thanks.


hello. can you biuld a simple demo page that reproduces this?

Mine does the same thing. I have Release Canidate. If I refresh the page the error goes away. If you hold your mouse over a button that has a hover event it flashes and you have to click at just the right time. The cursor blinks in the field that has focus as well andt he tab key didn't work. Not sure if I can figure what part to post but I will let you know what I find out.

Good luck

Saturday, March 24, 2012

PageRequestManagerServerErrorException when using UrlMappings

Hi,

I think I found a bug and I would like some help about a workaround.

I have a page with DropDownList inside an UpdatePanel. The page path is /physicalfolder/physicalpage.aspx

 
1 <form id="form1" runat="server">2 <asp:ScriptManager ID="ScriptManager1" runat="server" />3 <asp:UpdatePanel ID="PanelRecherche" runat="server" Visible="true" UpdateMode="Conditional">4 <ContentTemplate>5 <table><tr> <td>6 <asp:DropDownList ID="dropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dropDownList1_SelectedIndexChanged"/>7 </td></tr> </table>8 </ContentTemplate>9 </asp:UpdatePanel>10 <button type="submit">Go</button>11 </form>

In the code behind I do nothing except adding items to the DropDownList

1protected void Page_Load(object sender, EventArgs e)2 {3if (!Page.IsPostBack && !ScriptManager1.IsInAsyncPostBack)4 {5 dropDownList1.Items.Add("1");6 dropDownList1.Items.Add("2");7 }8 }910protected void dropDownList1_SelectedIndexChanged(object sender, EventArgs e)11 {1213 }

And finally in the web.config file I've set some UrlMappings

1<urlMappings>2 <add url="~/virtualfolder/virtualpage.aspx" mappedUrl="~/physicalfolder/physicalpage.aspx"/>3</urlMappings>

The problem is the following: when usinghttp://localhost/mysite/physicalfolder/physicalpage.aspx everything works fine, I can play as much as I want with the DropdownList.

If I use the vrtual pathhttp://localhost/mysite/virtualfolder/virtualpage.aspx only the first postback works fine, after that I get an error :

--------
Microsoft Internet Explorer
--------
Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 404
--------
OK
--------

If I look at the http requests:

    To access the page the first timehttp://localhost/mysite/virtualfolder/virtualpage.aspxOn First index change http://localhost/mysite/physicalfolder/physicalpage.aspxOn next index changes http://localhost/mysite/virtualfolder/physicalpage.aspx

Funny thing is that if I use the submit button before doing something else, it works like a charm.

Any ideas ? I can't remove UrlMapping and I need AjaxCrying


Ok, found it by my self, I was using wrong search patern.

Added this code right after closing form:

1 <script type="text/javascript">2 Sys.Application.add_load(function()3 {4 var form = Sys.WebForms.PageRequestManager.getInstance()._form;5 form._initialAction = form.action = window.location.href;6 });7 </script>

PageRequestManagerServerErrorException: 404 ??

I have a error when I use Server.Transfer and ASP.NET AJAX.

STEPS:

1- navigate to a page containing a UpdatePanel using SERVER.TRANSFER
2- (first) async call works fine

3 - click again to make second async call and somehow the page path becomes
invalid; the page name is correct but the path seems to belong to the
referer!! (Consequently a 404 server response is returned by the server. see
attached error message )

Anyone help-me?

Server.Transfer really doesn't work well with ASP.NET AJAX. A few people have done some complicated stuff to get it to work, but I recommend just avoiding it altogether if possible. Search around here on the forums, and you can probably find some older discussions of this.

Pages lifecycle with UpdatePanel.

It seems to me that I read an article says when I use an UpdatePanel not all events are rising.

Help me find the list of the events that are rising with UpdatePanel.

Thank you in advance,

Igor

Hi,

when an UpdatePanel performs a partial postback, the whole page lifecycle is executed, thus all the server-side events are being raised.


Garbin:

when an UpdatePanel performs a partial postback, the whole page lifecycle is executed, thus all the server-side events are being raised.

Thank you.


Garbin:

when an UpdatePanel performs a partial postback, the whole page lifecycle is executed, thus all the server-side events are being raised.

Thank you.


Luckily the ASP.NET team put a funky ittle feature into Atlas which will let you detect if you're in a Partial render or not.

Here's some code I put together to show this in action and how you can use it: -

1<%@. Page Language="C#" AutoEventWireup="true" CodeFile="PostBackType.aspx.cs" Inherits="PostBackType" %>23<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">4<html xmlns="http://www.w3.org/1999/xhtml">5<head runat="server">6 <title>Untitled Page</title>7</head>8<body>9 <form id="form1" runat="server">10 <atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />11 <div>12 <asp:Button ID="MyNormalButton" runat="server" Text="Cause Normal Postback" />13 <atlas:UpdatePanel ID="Panel1" runat="server">14 <ContentTemplate>15 <asp:Button ID="MyButton" runat="server" Text="Cause Partial Render Postback" />16 <h1 id="MyMessage" runat="server"></h1>17 </ContentTemplate>18 </atlas:UpdatePanel>19 </div>20 </form>2122 <script type="text/xml-script">23 <page xmlns:script="http://schemas.microsoft.com/xml-script/2005">24 <references>25 </references>26 <components>27 </components>28 </page>29 </script>30</body>31</html>

Then the C#

1using System;2using System.Data;3using System.Configuration;4using System.Web;5using System.Web.Security;6using System.Web.UI;7using System.Web.UI.WebControls;8using System.Web.UI.WebControls.WebParts;9using System.Web.UI.HtmlControls;10using Performance;111213public partialclass PostBackType : System.Web.UI.Page14{15protected void Page_Load(object sender, EventArgs e)16 {17 SetMessage();18 }1920private void SetMessage()21 {22switch (GetPostBackType())23 {24case PostBack.NotPostBack:25 MyMessage.InnerText = ("Not a Postback");26break;27case PostBack.NormalPostBack:28 MyMessage.InnerText = ("Normal Postback");29break;30case PostBack.PartialRenderPostBack:31 MyMessage.InnerText = ("Partial Render");32break;33 }34 }3536private PostBack GetPostBackType()37 {38if (!Page.IsPostBack)39 {40return PostBack.NotPostBack;41 }42else if ((Page.IsPostBack) && (!ScriptManager1.IsInPartialRenderingMode))43 {44return PostBack.NormalPostBack;45 }46else if ((Page.IsPostBack) && (ScriptManager1.IsInPartialRenderingMode))47 {48return PostBack.PartialRenderPostBack;49 }50else51 {52throw new System.NotSupportedException("This kind of Postback is not currently catered for");53 }54 }55}

NICE!!Thanks for the excellent illustration.

and for those of you doing this from a usercontrol, the code would change a little to something like this:

Dim

tempControl2As System.Web.UI.ScriptManager

tempControl2 =

CType(Page.FindControl("ScriptManager1"), System.Web.UI.ScriptManager)IfNot tempControl2.IsInAsyncPostBackThen

Paging a GridView with CSS Friendly Adapters causes a total postback with AJAX Beta1

Hello,

I have upgraded an existing project (Atlas CTP) to the Atlas Beta1 and encountered a problem with a GridView inside an UpdatePanel. I am using theCSS Friendly ASP.NET 2.0 Control Adapters for the GridView and paging the results causes a total postback instead of partial. Here's my code:

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> private System.Collections.Generic.List<string> GetList() { System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>(); for (int i = 0; i < 100; i++) { list.Add("item " + i.ToString()); } return list; } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ResultsGrid.DataSource = GetList(); ResultsGrid.DataBind(); } } protected void ResultsGrid_PageIndexChanging(object sender, GridViewPageEventArgs e) { ResultsGrid.PageIndex = e.NewPageIndex; ResultsGrid.DataSource = GetList(); ResultsGrid.DataBind(); }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head id="Head1" runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div> <asp:UpdatePanel ID="Updaty" runat="server"> <ContentTemplate> <asp:GridView id="ResultsGrid" runat="server" PageSize="10" AllowPaging="true" OnPageIndexChanging="ResultsGrid_PageIndexChanging" /> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>

Using the Atlas CTP the same code caused a partial postback when paging the GridView. Any ideas?

Regards,
Darin

One way around this is to add a trigger to the UpdatePanel for the PageIndexChanging event.

<Triggers>
<asp:AsyncPostBackTrigger ControlID="ResultsGrid" EventName="PageIndexChanging" />
</Triggers>

I tried this and it seem to then update the panel incrementally as expected.


I posted a fix here...http://forums.asp.net/thread/1442598.aspx

Paging a GridView in an UpdatePanel

Has anyone been able to implement paging for a GridView inside an UpdatePanel?

I get a JavaScript error everytime I click on the page number: "Object Required".

Enclosing the GridView control inside an UpdatePanel worked fine for me, including the paging.

Have you tried stepping through your code with VisualStudio? This works really good for me when debugging atlas. Also if your gridview is bound to a SqlDataSource you can enable PagingAndSortingCallbacks, and that has the same effect.


hello.

can you show us your code?

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

<atlas:UpdatePanelID="EmpOrders"runat="server"Mode="Conditional">

<Triggers><atlas:ControlEventTriggerControlID="Button1"EventName="Click"/></Triggers>

<ContentTemplate>

<asp:ButtonID="Button1"runat="server"Font-Italic="True"OnClick="Button1_Click1"Text="Search"/><br/>

<asp:GridViewID="GridView1"runat="server"CellPadding="4"ForeColor="#333333"GridLines="None"PageSize="15"AllowPaging="True"AutoGenerateColumns="False"OnPageIndexChanging="GridView1_PageIndexChanging"AllowSorting="True">

<Columns>

<asp:BoundFieldDataField="ShipName"HeaderText="Ship Name"SortExpression="ShipName"/>

<asp:BoundFieldDataField="ShipCountry"HeaderText="Country"SortExpression="Country"/>

<asp:BoundFieldDataField="Freight"HeaderText="Freight"SortExpression="Freight"/>

</Columns>

</asp:GridView>

</ContentTemplate>

</atlas:UpdatePanel>

Codebehind:

protectedvoid GridView1_PageIndexChanging(object sender,GridViewPageEventArgs e)

{

GridView1.PageIndex = e.NewPageIndex;

BindGrid();

}


hello.

well, it looks ok to me.

there's one thing i don't understand: you've added a trigger to the panel and configured it against a button which is also placed inside the panel...

i've built a small page that is working ok here (i've built a struct to simulate the info that is passed as source of the grid). see if it works with your current configuration:

public struct Ship
{
private string _shipName;

public string ShipName
{
get { return _shipName; }
set { _shipName = value; }
}
private string _shipCountry;

public string ShipCountry
{
get { return _shipCountry; }
set { _shipCountry = value; }
}
private string _freight;

public string Freight
{
get { return _freight; }
set { _freight = value; }
}

public Ship( string shipName, string shipCountry, string freight )
{
_shipName = shipName;
_shipCountry = shipCountry;
_freight = freight;
}
}

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!this.IsPostBack )
{
BindGrid();
}
}

void BindGrid()
{
Ship [] shippes = new Ship[]{
new Ship( "1","1","1" ),
new Ship( "2","2","2" ),
new Ship( "3","3","3" )
};

GridView1.DataSource = shippes;
GridView1.DataBind();
}

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{

GridView1.PageIndex = e.NewPageIndex;

BindGrid();

}

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page
</head>
<body>
<form id="form1" runat="server">
<atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"/>
<atlas:UpdatePanel ID="EmpOrders" runat="server" Mode="Conditional">
<Triggers>
<atlas:ControlEventTrigger ControlID="Button1" EventName="Click"/>
</Triggers>
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Font-Italic="True" Text="Search"/><br/>
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" PageSize="2" AllowPaging="True"
AutoGenerateColumns="False" OnPageIndexChanging="GridView1_PageIndexChanging" AllowSorting="True">
<Columns>
<asp:BoundField DataField="ShipName" HeaderText="Ship Name" SortExpression="ShipName"/>
<asp:BoundField DataField="ShipCountry" HeaderText="Country" SortExpression="Country"/>
<asp:BoundField DataField="Freight" HeaderText="Freight" SortExpression="Freight"/>
</Columns>
</asp:GridView>
</ContentTemplate>
</atlas:UpdatePanel>
<%= DateTime.Now.ToString() %>
</form>
</body>
</html>

Are you doing custom paging? I'm asking because normally, the GridView control takes care of this automatically (as well the binding -- unlike in DataGrid) so that you don't even have to handle the event. This is assuming that your datasource can handle paging (DataSet does I believe).


hello guys, and yes, i think that he is using the asp.net 1.X binding instead of using the new data source controls...

Yes I′m handling the binding as with .NET v1.x


hello again.

Can you run the sample page i've presented in a previous post?

Luis, your example works fine. The only difference between your code and mine is that you use a Struct as your datagrid's datasource and I use a DataSet.

What do you think?


hello.

well, i think that using a dataset shouldn't make any difference. can you build a sample page that uses a dummy dataset to reproduce the problem and post it here?
I have the same problem using an SQLDatasource. Is it possible that it only work with dataset because with dataset you can generate XML. Maybe with SqlDatasource it doesn't generate Xml so Atlas on gridview with SqlDatasource will no work ?
Luis, I′m working on the dummy page. In the meantime, I noticed that having

EnablePartialRendering="true"

won't let me fire the paging, deleting etc. events

Do you have it set to true?


hello.

yes i have. i've introduced < in my previous post and i think that now you should be able to see everything.

Paging and Sorting in GridView April CTP

Hi,

This start happing only after I upgraded to April release, with March release there was no problem.

I'm using updatepanel and gridview and have a ObjectDataSource which get some QueryStringParameter from the Request. When I'm trying to sort the gridview I'm getting a javascript error saying "Value cannot be null. Parameter name: error.

When trying to debug it I found that when sorting, the request URL got changed, and for example if the URL was :http://mySite.com/Default.aspx?kw=123&from=4/18/2006&to=4/19/2006

It got changed to :http://mySite.com/Default.aspx?kw=123&from=4/18/2006&to=4/19/2006Default.aspx?kw=123&from=4/18/2006&to=4/19/2006

Any thoughts?

Thanks

L

Hi,

I found the cause of the problem.

When ever there is a parameter in the URL that has \ like: &to=4\1\2006&..

Atlas April CTP is going crazy... and can't handle that. I have changed my date format to 4_1_2006 etc. and it's working, but still it's kind of a big deal.

Can any one confirm it's a known bug?

Thanks

Lior

Paging and UpdatePanel

Hi,

If you look at this page you see an example of paging within an update panel which works well

http://mattberseth2.com/resizeable_gridview_columns/


The difference I have is I also have ajaxToolkit:HoverMenuExtender on my first column which popups 'Edit Details' text which takes you to a new page...

without any triggers on the updatepanel, my paging now works as the above example.. but when I use my hover menu and click on 'Edit Detail' I get the following error..


Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. Details: Error parsing near '

to fix this error I use the following trigger on the updatepanel

<Triggers>
<asp:PostBackTrigger ControlID="GridView1" />
</Triggers>

now when I click on Edit Details it takes me to the new page as intended... but when I click on my paging buttons it doesnt work within the update panel it causes full page reload..

any ideas to get these two working together would be appreciated...


I have newver try that, I actually just added the GridView inside an UpdatePanel and seem to work really well


Hi,

Generally, I think implement it as Albert suggested should work.

If still not, please provide a simple repro that demonstrate the first problem(Sys.WebForms.PageRequestManagerParserErrorException: The messagereceived from the server could not be parsed. Common causes for thiserror are when the response is modified by calls to Response.Write(),response filters, HttpModules, or server trace is enabled. Details:Error parsing near ' ).


Hi,

simple repro.. would be to grab the example from the above link... and add following hovermenu to first column... add pagertemplate below...

paging works fine within the updatepanel

on clicking edit details you get the error as described in the first post...

to fix this error I use the following trigger on the updatepanel

<Triggers>
<asp:PostBackTrigger ControlID="GridView1" />
</Triggers>

but now the paging causes full page post back..

adding thelnkBtnRowEditDetail as a trigger as well dosent work as that gives a control id cant be found error.

 <asp:TemplateField ShowHeader="False"> <ItemTemplate> <asp:Panel CssClass="popupMenu" ID="PopupMenuCustomerName" runat="server"> <div class="popupMenuButtons"> <asp:LinkButton ID="lnkBtnRowEdit" SkinID="SmallTextPopUp" runat="server" CommandName="Edit" Text="Edit
</asp:LinkButton> <asp:LinkButton ID="lnkBtnRowEditDetail" SkinID="SmallTextPopUp" runat="server" CommandName="EditDetail" Text="Edit Detail"></asp:LinkButton> </div> </asp:Panel> <asp:Panel ID="PanelCustomerName" runat="server"> <asp:ImageButton ID="ImgButton" runat="server" AlternateText="Edit" ImageUrl="~/images/icon_edit.gif" CausesValidation="false" CommandName="" /> </asp:Panel> <ajaxToolkit:HoverMenuExtender ID="hme3" runat="Server" HoverCssClass="popupHover" PopupControlID="PopupMenuCustomerName" PopupPosition="Left" TargetControlID="PanelCustomerName" PopDelay="15"> </ajaxToolkit:HoverMenuExtender> </ItemTemplate> <EditItemTemplate> <asp:Panel CssClass="popupMenu" ID="PopupMenuCustomerName" runat="server"> <div class="popupMenuButtons"> <asp:LinkButton ID="lnkBtnRowUpdate" SkinID="SmallTextPopUp" runat="server" CommandName="Update" Text="Update"></asp:LinkButton><br /> <asp:LinkButton ID="lnkBtnRowCancel" SkinID="SmallTextPopUp" runat="server" CommandName="Cancel" Text="Cancel"></asp:LinkButton> </div> </asp:Panel> <asp:Panel ID="PanelCustomerName" runat="server"> <asp:ImageButton ID="ImgButton" runat="server" AlternateText="Update/Cancel" ImageUrl="~/images/icon_edit.gif" CausesValidation="false" CommandName="" /> </asp:Panel> <ajaxToolkit:HoverMenuExtender ID="hme3" runat="Server" HoverCssClass="popupHover" PopupControlID="PopupMenuCustomerName" PopupPosition="Left" TargetControlID="PanelCustomerName" PopDelay="15"> </ajaxToolkit:HoverMenuExtender> </EditItemTemplate> </asp:TemplateField>

 <PagerTemplate> <div class="item"> <div class="item_left"> <asp:Label ID="lblPageTxt" runat="server" SkinID="PageSmallText" EnableViewState="false" Text="Page" ></asp:Label> <asp:DropDownList ID="PageDropDownList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="PageDropDownList_SelectedIndexChanged" /> <asp:Label ID="lblOfTxt" runat="server" SkinID="PageSmallText" EnableViewState="false" Text="of"></asp:Label> <asp:Label ID="lbTotalPages" runat="server" SkinID="PageSmallText"></asp:Label> </div> <div class="item_right"> <asp:ImageButton ID="imgbtnFirst" runat="server" CommandName="Page" CommandArgument="First" ImageUrl="~/images/arrow_up.gif"></asp:ImageButton> <asp:ImageButton ID="imgbtnPrev" runat="server" CommandName="Page" CommandArgument="Prev" ImageUrl="~/images/arrow_left.gif"></asp:ImageButton> <asp:ImageButton ID="imgbtnNext" runat="server" CommandName="Page" CommandArgument="Next" ImageUrl="~/images/arrow_right.gif"></asp:ImageButton> <asp:ImageButton ID="imgbtnLast" runat="server" CommandName="Page" CommandArgument="Last" ImageUrl="~/images/arrow_down.gif"></asp:ImageButton> </div> <div class="clear"></div> </div> </PagerTemplate>

not using the hovermenu isnt really an option... as this functionality is consistent with the rest of the site... unless you have another idea for reproducing this functionality

first column of our gridviews are a basic icon image... with a hover menu that has 'Edit' which edits gridview inline 'Edit Details' which goes to a new page ... they also have 'Clone' which provides a modal popup and 'Create Link'/'Remove Link' and other such functionlaity... which is available from the gridview using the hovermenu.



Would you mind showing a repro that I can run directly?


Hi Paul

I looked at the example at

http://mattberseth2.com/resizeable_gridview_columns/

and it looks great.
Can you share your code?

Thanks

Shalom


there is example code on that link... http://mattberseth2.com/resizeable_gridview_columns/

Panel close button with AJAX

Hello All,

I want to use this wonderful AJAX Framework to something very simple:

Inside an UpdatePanel I have a Panel. Now just below the Panel I want to place a button or link that when clicked will hide the Panel and do this client side (without requiring a post back). I know how to do this with a postback and a method that sets Panel.Visible = false, but I don't want to call the server for this, just hide the Panel client side.

So I ask to the MS AJAX experts out there: what is the easy and elegant way of doing this with MS AJAX Framework and/or AJAX Control Toolkit.

Thank you!

David

Use this JS for the button/link click: $get('PanelClientID').style.display = 'none';


Hi Neutrino,

My understanding of what your want is to make your panel which is indside an UpdatePanel without any postbacks. If I have misunderstood, please feel free to let me know.

You can use $get(Panel's ClientID).style.display = 'none'. Here is the 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></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px"><%=DateTime.Now.ToString()%> </asp:Panel> <asp:Button ID="Button1" runat="server" Text="Button"OnClientClick="return hidePanel()"/> </ContentTemplate> </asp:UpdatePanel> <script type="text/javascript" language="javascript">function hidePanel(){ $get("<%= Panel1.ClientID%>").style.display='none'; return false; } </script> </form></body></html>

Note: Please pay special attention to the part of "Bold". IfOnClientClick don't return false, a postback will be occured in this case.

Best regards,

Jonathan


Thanks to both. Great simple solution.

Panel Default Button Event Doesnt Fire On Second Submit

I have one UpdatePanel surrounding a asp panel. Inside the panel I have one repeater, two buttons, and two labels. Inside the repeater's ItemTemplate I have an ImageButton and TextBox.

Here is the ASP Code:

1<asp:UpdatePanel ID="AdvancedSearchUpdatePanel" runat="server" UpdateMode="conditional" RenderMode="block" ChildrenAsTriggers="true">2 <ContentTemplate>3 <asp:Panel ID="AdvancedSearchPanel" runat="server" DefaultButton="SubmitSearchButton">4 <asp:Repeater ID="AdvancedSearchRepeater" runat="server">5 <HeaderTemplate>6 <table class="searchButton">7 <tr>8 <td colspan="100%">9 <asp:Label ID="KeywordLabel" runat="server" Text="Search By Keyword" Width="100%" Font-Bold="true"/>10 </td>11 </tr>12 </HeaderTemplate>13 <ItemTemplate>14 <tr>15 <td colspan="100%">16 <table cellpadding="0" cellspacing="0" style="padding-right:5px">17 <tr>18 <td>20 <asp:ImageButton ID="DeleteCriteriaButton" runat="server" ImageUrl="~/Resources/Images/close.gif" AlternateText="Click to Delete" OnClick="DeleteCriteriaButton_Click" />21 </td>22 <td>23 <asp:TextBox ID="KeywordTextBox" runat="server" Text='<%# Container.DataItem%>' CssClass="keywordSearch" Width="123px" OnTextChanged="KeywordTextBox_TextChanged" />24 </td>25 </tr>26 </table>27 </td>28 </tr>29 </ItemTemplate>30 <FooterTemplate>31 </table>32 </FooterTemplate>33 </asp:Repeater>34 <table class="searchButton">35 <tr>36 <td>37 <asp:Button ID="AddAnotherSearchButton" Text="Add Criteria" runat="server" OnClick="AddAnotherSearchButton_Click" />38 </td>39 <td>40 <asp:Button ID="SubmitSearchButton" Text="Submit Search" runat="server" OnClick="SubmitSearchButton_Click" />41 </td>42 </tr>43 <tr>44 <td colspan="100">45 <asp:Label ID="ReadableSqlString" runat="server" />46 </td>47 </tr>48 <tr>49 <td colspan="100">50 <asp:Label ID="ErrorLabel" runat="server" ForeColor="red"/>51 </td>52 </tr>53 </table>54 </asp:Panel>55 </ContentTemplate>56</asp:UpdatePanel>
My problem is that the default button for the panel is the SubmitSearchButton. 
On the first press of the enter key everything works as it should. 
On the second press of the enter key the DeleteCriteriaButton's (ImageButton) event gets fired because it is the first button in the panel. 
The only way I have seen to get around this is to put a button before the ImageButton that has a width of zero and have its event call the SubmitSearchButton event and everything works as should. 
Does anyone know a cleaner way around this problem or a reason this is happening. 
 
Thanks in advance.
There is a free component that allows you to assign a button to the "enter-pressed" client side event of input controls. If you type some text in textbox and press Enter, the form will postback, and the serverside click event of your button is fired.You don't need to write any code You only need to use control's "DefaultButton" property. It you are a beginner programmer this could be a life saver. More about MetaBuilders DefaultButtons Control you can find athttp://www.metabuilders.com/Tools/DefaultButtons.aspx
Wish this can help you.
You can specify a default button through javascript when pressing enter key.Try to take a look at this reading for details -http://www.beansoftware.com/ASP.NET-Tutorials/Accept-Enter-Key.aspx
Here are some sample codes for your reference.
TextBox1.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('"+Button1.UniqueID+"').click();return false;}} else {return true}; ");
Wish the above can help you.

DefaultButton is working fine for me on a simpler example:

<%@. Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void click(object sender, EventArgs e) { label1.Text = string.Format("{0} pressed at {1}", ((Control)sender).ID, DateTime.Now.ToString()); }</script><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="up1" runat="server"> <ContentTemplate> <asp:Panel ID="panel1" runat="server" DefaultButton="button2"> <asp:TextBox ID="text1" runat="server" /> <asp:Button ID="button1" runat="server" OnClick="click" Text="one" /> <asp:Button ID="button2" runat="server" OnClick="click" Text="two" /> </asp:Panel> <asp:Label ID="label1" runat="server" /> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

This does what you'd expect... every time you type something and press enter, the label displays "button2 pressed at " followed by the current time.

Your sample is considerably more complicated (and hard to reproduce, since I would need to provide a datasource etc.). Could you try simplifying your code to see at what point the issue goes away?


You can't forget that in my code I have repeaters. This might be the problem. My quick fix is to put a button before the delete button and set it to call the submit button's click event. I know this is a hack and I'm working on other issues. Your help is greatly appreciated. FYI, the datasource of the repeater is a List<string>.
I tested your code with a asp:Panel(asp:Repeater) in a asp:UpdatePanel in my PC.My test enviroment isWindows Server 2003 Enterprise,VS.NET 2005 and Ajax RC1.0. I found it?could?work?fine.If?you?click?the?TextBox?and?press?Enter?key in theasp:Panel, the?default?button?of?the?asp:Panel will?be?triggered.If?the?current?focus?was?moved to?the?outside?of?the?asp:Panel?and?press?Enter?key, the?default?button?of?the?asp:Panel?can't?be?triggered.So if you want to pressEnter key in anywhere of the current web form and the default button of theasp:Panel will be triggered, try to focus on aTextBox of theasp:Panel throughjavascript when pressingEnter key in the web form.This should work fine for you.
Sample Code: document.forms[0].elements['txtBox'].focus();
Wish this can help you.
This works in Internet Explorer 7, but not in Fire Fox 2. I'm soooo surprised.

Panel or Multiview inside Updatepanel, whats faster?

So I have multiple gridviews to display on a single page. There are multiple ways to display these one at a time. The first would, of course, be a multiview, the second, a set of panels using the visible attrib to control the views. Normally, a multiview would be a great way to do this, but when one adds an update panel what is best way to build the page when render speed is considered.

The multiview must, of course, sit in one updatepanel, therefore making the page render the entire section of code on each async postback. This would mimic the behavior of putting all the panels in one updatepanel. However, when one puts each panel inside its own updatepanel, it would seem to me that rendering would speed up, since the asyncpostback only has to return HTML related to its own individual gridview.

Anyone have any ideas on this?

Also, sort of related to this:

When all the panels are inside a table cell <td> and right on top of each other, so:

<td>

<asp:updatepanel id="test" runat="server">

<contenttemplate>

<panel id="pnl1" runat="server">

stuff

</panel>

</contenttemplate>

</asp:updatepanel>

<asp:updatepanel id="test2" runat="server">

<contenttemplate>

<panel id="pnl2" runat="server">

stuff

</panel>

</contenttemplate>

</asp:updatepanel>

</td>

When the first panel or pnl1 is rendered visible=false, the second panel pushes down the screen about 30px, yet when I remove the updatepanels, the panel shows up without the 30px push. I have not really investigated this too much, but if someone has seen this type of issue and knows a quick fix, I would be appreciative.

THanks

Jason

I think all in all they will render about the same amount of HTML - and the server side processing should be the same with both. If anything the multi-view will be a bit slower due to the extra-overhead the control might have - but i'm talking miliseconds or smaller.

Remember when a panel has visible=False - nothing inside that panel is rendered to the clients computer.

regarding the push down - have you looked with the developer tools in IE / FireFox to see what block element is pushing it down?


Sounds good. I'll just go w/the multiview then and make life a bit easier, this will solve the 30px push as well so I will mark this as solved.

Panel within Mutliview scrolls when contents of updatepanel updated??

Here is my page:
<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AJAXEnabledWebApplication1._Default" %><!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> <script type="text/javascript">var curCount = 0;var timer;var value = 0;function timedCount(){ try { var elem = document.getElementById('Panel1'); if (value == elem.scrollHeight) { } else if(value < elem.scrollHeight) { value = elem.scrollHeight; elem.scrollTop = value; } timer=setTimeout("timedCount()",100) } catch(err) { timer=setTimeout("timedCount()",100) } }function stopTimer(){ clearTimeout(timer);}</script> </head><body onload="timedCount()" onunload="stopTimer()" bottommargin="0" leftmargin="0" rightmargin="0" topmargin="0"> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div> </div> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> <asp:Button ID="change" runat="server" OnClick="change_Click" Text="change" /> <asp:UpdatePanel ID="UpdatePanel2" runat="server"> <ContentTemplate> <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0"> <asp:View ID="View1" runat="server"> <asp:Panel ID="Panel1" runat="server" Height="166px" ScrollBars="Auto" Width="173px"> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Literal ID="Literal1" runat="server"></asp:Literal>  </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /> </Triggers> </asp:UpdatePanel> </asp:Panel> </asp:View> <asp:View ID="View2" runat="server"> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></asp:View> </asp:MultiView> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="change" EventName="Click" /> </Triggers> </asp:UpdatePanel> <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick1"> </asp:Timer> </form></body></html>
 
 And here is the code behind:
 
protected void Button1_Click(object sender, EventArgs e) { Literal1.Text +="test<br>"; }protected void Timer1_Tick1(object sender, EventArgs e) { Random r =new Random();int j = r.Next(5000);if (j % 7 == 0) Literal1.Text +="test2<br>"; }protected void change_Click(object sender, EventArgs e) {if (MultiView1.ActiveViewIndex == 0) MultiView1.ActiveViewIndex = 1;else MultiView1.ActiveViewIndex = 0; } }
 
 
 the issue is that if I take Panel1 out of the MultiView it works fine: When dynamically updating Literal1, Panel1 correctly scrolls to the bottom and only when there has been a change in scrollHeight.
If Panel1 is moved to be inside View1, then Panel1 refreshes every second with the timer1.Tick event. What causes this behavior within the multiview, but not when Panel1 is outside of the Multiview?

after further testing, i have found that if I take the Multiview1 completely out of the UpdatePanel2 it works correctly too.


Each time tick probably causes an async postback. Since all your update panels are not set to have UpdateMode="Conditional", then they update on each async event


Thanks! That worked. One other question, i looked over the docs, but i havent been able to find any information on the cost/efficiency of this property. Is it more efficient to set them to "conditional" ?


I think more appropriate is to ask : What do I need :-) I think it is a.) a matter of convenience, and b.) sort of fool-proofing the facility - many ppl get confused when the thing updates all the time, and then others get confused when it doesnt. With "Always", you get refresh on each and all async postbacks on the page, which may be a waste of client-resources if the content does not need updating (the resources being spent on retrieving the control from viewstate, I guess). With Conditional, you are more in control as to when you get a refresh. Do remember than apart from the triggers , you can cause an UpdatePanel to update from your server-side code by calling the NameOfUpdatePanel.Update method.

Also, it gets a bit tricky conceptually when you have nested UpdatePanels - I m still exploring that confusion myself:)

Btw : if satisfied with the answer plz mark it as answered.


Wednesday, March 21, 2012

ParserErrorException when Edit button on Datagrid pressed

I have a datagrid control wrapped in an UpdatePanel. There are Edit/Delete ImageButton's for each row. The first time I press the Edit butonn (setsEditItemIndex = -1) the ubiquitous Sys.Webforms.PageRequestManagerParserErrorException; The message from the server could not be parsed...

Subsequently, pressing the edit button prooduces the desired results.

Any ideas with this strange behavior are appreciated.

TIA

Hi,

Please refer to this:http://siderite.blogspot.com/2007/02/aspnet-ajax-and-responsewrite-or.html

It gives a full explanation of it. Hope this helps.

NOTE:This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


I also face this kind of problem - 'Sys.WebForms.PageRequestManagerPerserErrorException:'. So far I
understand this happen when there is some unrecongnize html render or event occurs. I'm also not very clear.

But I solve the issue by set the attribute EnableEventValidation="false" in the ASPX page, where I place my
UpdatePanel.

Thanks
I also face this kind of problem - 'Sys.WebForms.PageRequestManagerPerserErrorException:'. So far I
understand this happen when there is some unrecongnize html render or event occurs. I'm also not very clear.

But I solve the issue by set the attribute EnableEventValidation="false" in the ASPX page, where I place my
UpdatePanel.

Thanks

partial postback does not occur but the whole page gets reloaded


Hello coders,

I got a problem with my updatepanel.
I have a dynamic datagrid with a delete button. When i press the delete button
the partial postback occurs. ALL THIS WORKS FINE.

However i also have a Textbox in the same datagrid.
When i change the value in the Textbox a callback is generated.
The partial postback does not occur but the whole page gets reloaded.
This is not what i want.

So what is the diference between these two?

I will post a simplified version of my code:

'------<asp:UpdatePanel ID="udpWinkelwagen" runat="server"> <ContentTemplate> <asp:PlaceHolder ID="phWinkelwagen" runat="server" ></asp:PlaceHolder> </ContentTemplate></asp:UpdatePanel>'------ dgWinkelwagen =New DataGrid dgWinkelwagen.AutoGenerateColumns =False dgWinkelwagen.ShowFooter =True dgWinkelwagen.DataSource = ds.Tables(0) ...'TextField tempCol =New TemplateColumn tempCol.HeaderText = myDB.LeesVeld(myDB.haalViewOp("web_WinkelwagenText","quantity", taal),"Text") tempCol.ItemTemplate =New DynamicItemTemplateTextBox(Me.Page, bestelnr, taal) dgWinkelwagen.Columns.Add(tempCol)'delete button strConrirm = myDB.LeesVeld(myDB.haalViewOp("web_WinkelwagenText","confirmDelete", taal),"omschrijving") tempCol =New TemplateColumn tempCol.ItemStyle.HorizontalAlign = HorizontalAlign.Center tempCol.HeaderText ="" tempCol.ItemTemplate =New DynamicItemTemplateDeleteButton(bestelnr, strConrirm,Me.Page) dgWinkelwagen.Columns.Add(tempCol) dgWinkelwagen.DataBind()' add to placeholder on page phWinkelwagen.Controls.Add(dgWinkelwagen)'------Public Class DynamicItemTemplateTextBoxImplements ITemplateDim ds, dsProcAs DataSetDim myDBAs DB =New DBDim myHulpAs HulpFuncties =New HulpFunctiesDim myOrbisAs OrbisTaskCentre =New OrbisTaskCentreDim myWebshopAs webshopFuncties =New webshopFunctiesDim taalAs String Dim btnSave, txtSave, strAlert, titel, omschrijvingAs String Dim artikel, bestelnr, errorTextAs String Dim myPageAs PageDim aantalAs Double Sub New(ByVal pAs Page,ByVal bestnrAs String,ByVal taalcodeAs String) myPage = p bestelnr = bestnr taal = taalcodeEnd Sub Public Sub InstantiateIn(ByVal containerAs Control)Implements ITemplate.InstantiateInDim txtAantalAs TextBox =New TextBox() txtAantal.AutoPostBack =True txtAantal.Width ="38" txtAantal.MaxLength ="4"AddHandler txtAantal.TextChanged,AddressOf Me.changeValue container.Controls.Add(txtAantal)End Sub Public Sub changeValue(ByVal senderAs Object,ByVal eAs EventArgs)CType(myPage.Master, masterMethods).updateCart()CType(myPage.Page, winkelwagenMethods).updateGrid()End SubEnd Class'------Public Class DynamicItemTemplateDeleteButtonImplements ITemplateDim artnr, txtAantal, btnDelete, strConfirm, omschrijving, strAlertAs String Dim myDbAs DB =New DBDim dsProcAs DataSetDim bestelnrAs Integer Dim mypageAs PageSub New(ByVal _bestelnrAs Integer,ByVal confirmAs String,ByVal _pageAs Page) strConfirm = confirm bestelnr = _bestelnr mypage = _pageEnd Sub Public Sub InstantiateIn(ByVal containerAs Control)Implements ITemplate.InstantiateInDim imgBtnDelAs ImageButton =New ImageButton() imgBtnDel.ImageUrl ="~/images/remove.gif"AddHandler imgBtnDel.Click,AddressOf Me.DeleteArtikel container.Controls.Add(imgBtnDel)End Sub Public Sub DeleteArtikel(ByVal senderAs Object,ByVal eAs ImageClickEventArgs) artnr =CType(CType(sender, ImageButton).Parent.Parent.Controls(1).Controls(0), Label).TextDim parameters1()As String = {bestelnr, artnr} dsProc = myDb.startProcedure("web_winkelwagen_artikel_delete", parameters1)CType(mypage.Master, masterMethods).updateCart()CType(mypage.Page, winkelwagenMethods).updateGrid()End SubEnd Class

hello.

can you builkd a simple demo page that reproduces the app and put it here so that we can simply copy/paste it into vs?