Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Wednesday, March 28, 2012

Update UpdatePanel contents from a web method async call back

Hi,

I have several asp label controls contained in an UpdatePanel.

An asp button control has code behind that calls a web service method using an AsyncCallBack.

When the callback occurs, I need to show the results by setting the text property on the label controls but I cant get the label controls to update.

Does anyone know how to get this working??

Thanks,

Hi, not much use to you I'm afraid but I have a very similar problem. My callback event is from a remoting object rather than a web service and I need to update a gridview rather than text boxes.The callbacks fire at irregular intervals so I can't use a timer to generate a partial postback.

Thanks


Well, you can't really force a client refresh based on a server-side event, unfortunately. The best you can do is use a timer of some sort, despite the fact that the response is irregular. Now, something to realize is that the updatepanel sends all the same form data that you'd normally send for a full postback, so that's a fairly heavy way to do it when you're not sure if you need to or not.

What I'd do instead is have that AsyncCallBack's server-side 'on complete' handler update a variable at the appropriate scope (there's any number of choices to make there as to where to place that variable scope-wise, and what info it should contain; but those decisions are domain specific to your app). Anyway, do that and then set up a simple web service that provides a read-only view of that variable. Personally, I'd use a 'last updated' kind of thing, and have that in the update panel as well, that way you can compare the two times in the next step.

On the client side, create a simple script that fires at a set interval (again, whatever time is appropriate) using setTimeout or the Sys.Preview.Timer object (the latter being a lot easier to use, imo). That javascript function fires off a request to the web service you set up, and in its oncomplete handler, you check the response. If that variable's value indicates that a refresh is needed, then you have the javascript function initiate the updatepanel's asynch postback to refresh all the data.

Now, all that said, I probably would do the whole thing w/ web services myself, but I'm assuming that you need some of the major server-side features that the updatepanel technique allows you to use.

Hope that helps,

Paul

Updated to latest release - profile now broken

I just upgraded my web application to the latest release of Ajax and now the app hangs on the login. I paused the code and it is hanging on getting a profile property. I even tried creating an entierly new membership database and it still does the same thing. The Website Configuration Tool still connects to the membership database, so I know its not a problem with the users or roles. Any help would be greatly appreciated.

MORE INFO -

When I pause the app, it always stops on one of two lines:

The first is in a generated code file -

ReturnCType(Me.GetPropertyValue("LastName"),String)

This is what lead me to believe it is a profile issue - this generated code file has all of my profile properties in it. When I set a watch on Me.getPropertyValue("LastName"), its value is "Cannot evaluate expression because we are stopped in a place where garbage collection is impossible...etc"

If I start running and then pause again, it stops on a line that begins:

IfNotMy.User.IsInRole("Administration")

So, naturally I set a watch on My.User - which yields a value of "error: cannot obtain value"

I have NO IDEA what to do next? Anybody?

We upgraded to the latest version of the toolkit a few days ago, and now are seeing a lot of things either not working, or working sometimes and sometimes not. I almost suspect there is a problem in this version, but I cannot find the old version to go back to...

TIA,

Bill


Figured it out...had an error infinite loop going. Had nothing to do with membership.

Monday, March 26, 2012

UpdatePanel & Opening a new window when returning from code-behind

Hi there,

Here's the OnClick event code for a button inside an UpdatePanel:

protected void btnReport_Click(object sender, EventArgs e)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "viewRepo", "<script>window.open('RepoViewer.aspx','viewReport')</script>");
}

As you can see, after returning from code-behind I want to open a new browser window with a given web form. Well, this works correctly without an UpdatePanel, or when EnablePartialRendering is set to false.

If EnablePartialRendering is set to true, a new window does not open.

Any workarounds?

-Benton

I'm having the same issue.

Rob


Hi Benton,

I'd the same problem, but I solve it, use've just to remove the tag scrip from your code (belive, it works!!!)

I used before this:

Sub wOpen(ByVal fWindow As String, ByVal fNameWin As String, ByVal fWidth As Integer, ByVal fHeight As Integer, ByVal fMenu As Boolean, ByVal fResizable As Boolean, ByVal fScroll As Boolean)
Dim strJ As String
strJ = "<script language='text/javascript'>"
strJ &= "window.open('" & fWindow & "', '" & fNameWin & "', "
strJ &= "'width=" & fWidth & ", height=" & fHeight & ", menubar="
If fMenu = True Then
strJ &= "yes"
Else
strJ &= "no"
End If
strJ &= ", resizable="
If fResizable = True Then
strJ &= "yes"
Else
strJ &= "no"
End If
strJ &= ", scrollbars="
If fScroll = True Then
strJ &= "yes"
Else
strJ &= "no"
End If
strJ &= "')<"
strJ &= "/script>"
'Page.RegisterClientScriptBlock("wOpen", strJ)
'Me.ClientScript.RegisterStartupScript(Me.Page.GetType(), "wOpen", strJ, True)
Me.ClientScript.RegisterStartupScript(Me.GetType(), "wOpen", strJ, True)
End Sub

And now I'm using:
Sub xOpen(ByVal fWindow As String, ByVal fNameWin As String, ByVal fWidth As Integer, ByVal fHeight As Integer, ByVal fMenu As Boolean, ByVal fResizable As Boolean, ByVal fScroll As Boolean)
Dim strJ As String
strJ = "window.open('" & fWindow & "', '" & fNameWin & "', "
strJ &= "'width=" & fWidth & ", height=" & fHeight & ", menubar="
If fMenu = True Then
strJ &= "yes"
Else
strJ &= "no"
End If
strJ &= ", resizable="
If fResizable = True Then
strJ &= "yes"
Else
strJ &= "no"
End If
strJ &= ", scrollbars="
If fScroll = True Then
strJ &= "yes"
Else
strJ &= "no"
End If
strJ &= "')"
Me.ClientScript.RegisterStartupScript(Me.GetType(), "xOpen", strJ, True)
End Sub

Note that I just remove the javascript tag, and it works very well.

jb.alessandro:

Hi Benton,

I'd the same problem, but I solve it, use've just to remove the tag scrip from your code (belive, it works!!!)


Note that I just remove the javascript tag, and it works very well.

Hi JB,

I am having the same problem. I hope there is a way to fix it with my case. Below is my script. Thanks

Response.Write(

"<script>window.open('../MailCenter/mailMain.aspx?tomemid=" +Convert.ToInt32(ViewState["MemID"]) +"','_blank');</script>");

How is it possible to remove the tags in this case? I tried but it didn't work.

blumonde

UpdatePanel : Inject Javascript in literal

Hi all !

I've unsuccesfully tried to display an alertbox in Javascript when pushing a button. When the event is fired I inject JS code in a literal by codebehind. That works fine as long as my button is not in an UpdatePanel.

In the .aspx :

 <asp:ScriptManager EnablePartialRendering="true" ID="AtlasSM" runat="server" /> <asp:UpdatePanel ID="AtlasUpdate1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> <asp:Literal ID="Literal1" runat="server" EnableViewState="False" Mode="Transform"></asp:Literal> </ContentTemplate> <Triggers> <asp:AsyncPostbackTrigger ControlID="Button1" EventName="Click" /> </Triggers> </asp:UpdatePanel>
In the .cs :
protected void Button1_Click(object sender, EventArgs e) { LiteralOpenFax.Text ="<SCRIPT language='javascript' type='text/javascript'>alert('test');</SCRIPT>"; }

Any suggestions? Thanks!

Dindin:


LiteralOpenFax.Text ="<SCRIPT language='javascript' type='text/javascript'>alert('test');</SCRIPT>";

Oops, it's Literal1.Text ="<SCRIPT language='javascript' type='text/javascript'>alert('test');</SCRIPT>";, not LiteralOpenFax ;)
But doesn't work anymore


Hi,

you should use the RegisterClientScript or RegisterStartupScript methods of the ScriptManager control to inject Javascript in the page during a partial postback.


Hi Garbin, thank you for reply!

Yes, I've used RegisterClientScriptBlock, but that's dont work in a postback.

protected void Page_Load(object sender, System.EventArgs e){if ( ! Page.IsPostBack )Page.RegisterClientScriptBlock("ScriptNotPostBack","<SCRIPT>alert('My script in page load : good');</SCRIPT>");elsePage.RegisterClientScriptBlock("ScriptInPostBack","<SCRIPT>alert('My script after a postback : that does not work');</SCRIPT>");}
Is my code bad?


Like Garbin said, you want RegisterClientScriptBlock on theScriptManagerobject.

So change those to calls to ScriptManager.RegisterClientScriptBlock().


Ok, greate !

Thank you guys

UpdatePanel + Invisible control = Problems

Hi Guys,

I created my own UserControl that only contains the following. (The code for a basic DropDownExtender) The control is called ProgEdit

1<cc1:DropDownExtender ID="dde" runat="server" TargetControlID="lblAssigned" DropDownControlID="DropPanel"></cc1:DropDownExtender>
2<asp:Label ID="lblAssigned" runat="server" Text="Label" Style="display: block; width: 300px; padding:2px; padding-right: 50px; font-family: Tahoma; font-size: 11px;" ></asp:Label>
3<asp:Panel id="DropPanel" runat="server" Style="display :none; visibility: hidden;background: url(http://localhost/project/images/ajax-menu-bg.gif) repeat-y 0 0 #FAFAFA; z-index: 1000;">
4 <asp:LinkButton runat="server" ID="lnkName" />
5</asp:Panel>

I've got a seperate page that contains an update panel. The update panel contains a ProgEdit control which is inially invisible.

1<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
2<ContentTemplate>
3 <ds:ProgEdit runat="server" id="progEdit" visible="false" />
4 <asp:Button runat=server ID="btntest" OnClick="VisibleEdit"/>
5</ContentTemplate>
6</asp:UpdatePanel>

The problem: When I click the btnTest the ProgEdit control is set to visible. But the DropDownExtender control doesn't work correctly. (The dropdown image on the side is missing)
Whats wrong?

If I remove the UpdatePanel, the DropDownExtender runs fine.
If I add another ProgEdit anywhere on the page (which isnt set to Visible=false) it runs fine.

Any ideas?

Any ideas?

UpdatePanel + Infragistics Treeview

I am trying to create a very simple UpdatePanel + Treeview page. The data is initally loaded (via code, recursive nodes added in code behind) the tree loads fine.

As soon as I click on a node (and capture the NodeClick event) the Tree view stops working and reports a Javascript error. "Microsoft JScript runtime error: 'undefined' is null or not an object"

Has anyone seen this before? Do the Infragistic controls not work with Atlas?

Thanks in advance.

Are you using the Tree's Automatic SmartCallback LoadOnDemand behavior, or Manual LoadOnDemand? I would recommend using the Tree's own AJAX enabled LoadOnDemand functionality, even inside of the UpdatePanel, since you really only need to update the tree. If you still have difficulty, please contact Infragistics Developer Support (http://devcenter.infragistics.com)

Also, if you have a valid Subscription, we are about to release our 2006 Volume 2 Beta. We've made some changes in order to better support Atlas, and it would be great if you could validate whether it fixes your current problems or not.

-Tony

Anthony Lombardo
Infragistics, Inc.
Product Manager | NetAdvantageASP.NET

UpdatePanel + Repeater + LinkButton: Which Event Will Fire?

I have been pulling my hair out for 8 hours now, trying to get this little piece of code to work. Any help would be greatly appreciated!

It is a seemingly simple excercise of having a LinkButton in a Repeater control, nested inside an UpdatePanel. For the life of me, I can't get a command (or click) event to fire!

I have tried adding event code for the repeater control as well as the linkbuttons. When a linkbutton is clicked, the Load event on the page runs, but I can never get a command event to fire.

There are MANY different things I have tried, and for clarity I have removed most of the abberations I have gone through. The code below is a stripped-down version that just shows the basics of what I am trying to do. I would be grateful if someone who has gone through this before could give me some things to try.

Again, I am simply trying to have some server-side code run in response to a LinkButton command that is nested inside a repeater, which is inside an UpdatePanel. It is data bound, as you will notice below (that is the one apsect that seems to work just fine). Thank you!

Here is the code (a little sanitized):

<atlas:UpdatePanel ID="UpdatePanel1" Mode="Conditional" runat="server"><ContentTemplate><table class="choices" border="0"><asp:Repeater ID="Choices" runat="server"><ItemTemplate><tr><td><asp:LinkButton ID="Choice" CssClass="choice" CommandName='<%#Eval("ID")%>' Text='<%#Eval("Name")%>' runat="server" /></td></tr></ItemTemplate><FooterTemplate><tr><td><asp:LinkButton ID="Choice" CssClass="choice" CommandName="0" Text="Nothing" runat="server" /></td></tr></FooterTemplate></asp:Repeater></table></ContentTemplate></atlas:UpdatePanel>

I dont see your triggers section, controling the action that happens on the click of the linkbutton, are you trying to perform a codebehind function?


How do you implement the code that executes when the button is pressed? Instead of a linkButton Click, fetch the ItemCommand event on the repeater.

Check out:

http://sncore.vestris.com/Source/sncore/SnCore.Web/AccountFeedItemImgsView.aspx
http://sncore.vestris.com/Source/sncore/SnCore.Web/AccountFeedItemImgsView.aspx.cs

There's a PagedList (a multicolumn repeater) with a toggle button inside an UpdatePanel.

<atlas:UpdatePanelID='panelShowHide'Mode="Conditional"runat="Server">
<ContentTemplate>
<asp:LinkButtonText='<%# (bool) Eval("Visible") ? "» Hide" : "» Show" %>'ID="linkToggleVisible"runat="server"
Visible='<%# base.SessionManager.IsAdministrator %>'CommandName="Toggle"CommandArgument='<%# Eval("Id") %>'/>
</ContentTemplate>
</atlas:UpdatePanel>

The handling code changes something in the DB, then updates the button only.

publicvoid gridManage_ItemCommand(object sender, DataListCommandEventArgs e)
{
try
{
switch (e.CommandName)
{
case "Toggle":
TransitAccountFeedItemImg img = SyndicationService.GetAccountFeedItemImgById(
SessionManager.Ticket,int.Parse(e.CommandArgument.ToString()));
img.Visible = !img.Visible;
if (!img.Visible) img.Interesting =false;
SyndicationService.CreateOrUpdateAccountFeedItemImg(SessionManager.Ticket, img);
LinkButton lb = (LinkButton)e.Item.FindControl("linkToggleVisible");
lb.Text = img.Visible ? "» Hide" : "» Show";
UpdatePanel up = (UpdatePanel)e.Item.FindControl("panelShowHide");
up.Update();
break;
}
}
catch (Exception ex)
{
ReportException(ex);
}
}

I don't have a running demo, you need to be admin on foodcandy.com to do this :)

Hope this helps,
dB.


Freakyuno:

I dont see your triggers section, controling the action that happens on the click of the linkbutton, are you trying to perform a codebehind function?

I tried both with and without a trigger.

I figure the code doesn't need a trigger section because it is being triggered from a linkbutton within the UpdatePanel.

However, I just want to make sure I made it clear that I did try it.


dblock,

It looks like the major difference between your code and mine is that you seem to put every linkbutton within its own updatepanel, and then the entire list is enclosed within a "wrapper" updatepanel.

Is that right?

I will give it a try and see if that helps. Do you know if it is required?

Thanks for the help.


speednet:

dblock,

It looks like the major difference between your code and mine is that you seem to put every linkbutton within its own updatepanel, and then the entire list is enclosed within a "wrapper" updatepanel.

Is that right?

I will give it a try and see if that helps. Do you know if it is required?

Thanks for the help.

I definitely had this working without having every linkbutton in its own updatepanel (with just the wrapper one). That would update the entire grid. For me the trick has been to catch the grid item command, not the button click.


I just threw this together (as you probably can tell!) and it works for me. I'm using the June CTP if that may have anything to do with it. Here's the ASPX file:

<%@.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="form1"runat="server">
<atlas:ScriptManagerID="ScriptManager1"EnablePartialRendering="true"runat="server"/>
<atlas:UpdatePanelID="UpdatePanel1"Mode="conditional"RenderMode="inline"runat="server">
<ContentTemplate>
<asp:RepeaterID="Repeater1"runat="server"OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<asp:LinkButtonID="LinkButtonTest"runat="server"CommandName='<%# Eval("Name") %>'Text='<%# Eval("Name") %>'></asp:LinkButton><br/>
</ItemTemplate>
</asp:Repeater>
<br/>
<asp:LabelID="Label1"runat="server"></asp:Label>
</ContentTemplate>
</atlas:UpdatePanel>
</form>
</body>
</html>

...and the C# file:

using

System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public

partialclass_Default : System.Web.UI.Page
{
protectedvoid Page_Load(object sender,EventArgs e)
{
List<Test> tests =newList<Test>();

tests.Add(newTest("Apple"));
tests.Add(newTest("Berry"));
tests.Add(newTest("Cherry"));

Repeater1.DataSource = tests;
Repeater1.DataBind();
}

protectedvoid Repeater1_ItemCommand(object source,RepeaterCommandEventArgs e)
{
Label1.Text = e.CommandName;
}
}

public

classTest
{
privatestring _name ="";

publicstring Name
{
get {return _name; }
}

public Test(string name)
{
_name = name;
}
}

Apart from the table tags, this is pretty much the same as you're doing.

(Apologies for the spacing... I'm a spacing freak!)


The inner UpdatePanel did not help. I'll post a complete code sample, without editing out the unnecessary stuff. Maybe someone will know why the Command event is not firing.

<asp:PlaceHolder ID="Content" runat="server"><div class="results"><p class="question"><asp:Literal ID="Question" runat="server" /></p><atlas:UpdatePanel ID="UpdatePanel" Mode="Conditional" runat="server"><ContentTemplate><asp:MultiView ID="Views" runat="server"><asp:View runat="server"><div class="choiceswrapper"><table class="choices" border="0"><asp:Repeater ID="Choices" OnItemCommand="Choices_Click" runat="server"><ItemTemplate><tr><td><atlas:UpdatePanel ID="InnerUpdatePanel" Mode="Conditional" runat="server"><ContentTemplate><asp:LinkButton ID="Choice" CssClass="choice" onmouseover="this.className='choiceon';" onmouseout="this.className='choice';" CommandName='<%#Eval("ID")%>' Text='<%#Eval("Name")%>' runat="server" /></ContentTemplate></atlas:UpdatePanel></td></tr></ItemTemplate><FooterTemplate><tr><td><asp:LinkButton ID="Choice" CssClass="discardoption choice" onmouseover="this.className='discardoption choiceon';" onmouseout="this.className='discardoption choice';" CommandName="0" Text="Discard" runat="server" /></td></tr></FooterTemplate></asp:Repeater></table></div><p class="instructions">After you register your vote the current results will be displayed. Select "Discard Vote" to see the results without voting (your vote is discarded permanently).</p></asp:View><asp:View runat="server"><div class="options"><table><tr><td>Entry 1</td><td> [ <strong>0</strong> ] </td><td><img src="images/bar.gif" width="4" height="11" alt="" /></td></tr></table></div><div class="foot"><div class="center"><strong>You are already logged in.</strong></div></div></asp:View></asp:MultiView></ContentTemplate></atlas:UpdatePanel><div class="tblrowseparator"></div></div></asp:PlaceHolder>

Only the first View in the MultiView is used right now. I kept the extra UpdatePanel in there, from the test I mentioned in my last post. Also, in case anyone is wondering, I tried removing the MultiView from the UpdatePanel, and it still did not work.

The code-behind looks like this:

Sub Choices_Click(ByVal senderAs Object,ByVal eAs System.Web.UI.WebControls.RepeaterCommandEventArgs)Handles Choices.ItemCommandIf (Me.Master.CurrentUser.LoggedInAndActivated)Then'I set a breakpoint on the "If" statement above to see if the code ever entered the event'... Much more code hereEnd IfSetupAndDisplay(Me.Master.CurrentUser.ID)End Sub

Thank you Jason!

Can you take a look at the code I just posted and see if you can see any problems?

I am using the June CTP (which is awesome), so I'm OK there. I was thinking maybe it was the MultiView, but it stll didn't work when I tried removing it.

My ScriptManager is on the Master page (which works fine for another UpdatePanel on the same page).


I'm pretty sure the problem has something to do with the repeater.

I completed removed the repeater, and replaced it with just a single linkbutton in the table, and then wired the code-behind to the linkbutton command (instead of the repeater item command event) and it did execute the code.

Any eagle-eyes see a problem with my repeater code? Should I try a different template control?


Hmm... when I tried your code straight, I got nothing (could be the MultiView for me!). So I removed the MultiView and the inner UpdatePanel (definately not needed) and I was able to get the event to fire.

I'll try adding the the MultiView back in to see if that might be the issue.


Oops... didn't set the ActiveIndex of the MultiView to 0 :|

Anyway, I've added your MultiView code (almost) exactly and I definately getting the Choices_Click event firing. The only things I changed was removing the inner UpdatePanel.

When I re-added the inner UpdatePanel the event did NOT fire. So that's what I believe to be the issue.


Jason,

First of all, thank you very much for taking the time to test out my code - much appreciated!

That inner UpdatePanel was only in there as a test, and I tried testing both with and without it. Didn't work either way.

It is interesting that when I removed the repeater it started to work.

Looking at my code for the 1,000th time today, I'm reasonably sure it is good, valid code. Itshould work. The fact that you successfully tested it on your end would indicate that also.

It is quite possible that something else is interfering with the operation of this code, maybe it's just going to take another day of trial and error to eliminate all the possibilities.

It's also possible that I have some combination of things that is exposing a rare bug. My web site is very complex, so it wouldn't surprise me. I was actually hoping that if I posted the code it might help spark an idea from one of the Atlas developers or contributors.

In any case, if you can think of anything else that may be causing the problem, I would appreciate whatever you could offer. Once I'm able to narrow down the problem, I'll post my solution here.

Thanks again for your help.

-Todd


I believe I have finally nailed down the basic problem, although the exact details are still a little murky.

It turns out that this is one of those very tricky areas in ASP.NET, and not actually and Atlas issue. It has been blogged by Scott Mitchell (of 4guysfromrolla.com) in the past. Here are the relevant links:

http://scottonwriting.net/sowBlog/posts/1263.aspx

http://scottonwriting.net/sowblog/posts/1268.aspx

Although I did not find the exact solution for the ASP.NET issue described in the blog entries, it helped me identify the basic issue so I could code around it.

The solution I came up with works pretty well and is not too kludgy:

1. I put a <asp:HiddenField> tag within the UpdatePanel, and used it to PostBack an ID code (the same ID code that I was originally going to PostBack as a command argument). I included the HiddenField inside the UpdatePanel so that I could reset it to an empty string after each PostBack. If it was outside the UpdatePanel, I would not be able to update it during the partial render.

2. I kept the LinkButtons in the Repeater, but added an OnClientClick event to each one that loads the ID code into the HiddenField. Check out the weird syntax I had to come up with, to overcome all the different quote characters: OnClientClick='<%#String.Format("$({2}{0}{2}).value={2}{1}{2};", HiddenTag.ClientID, Eval("ID"), Chr(39))%>' You may also notice the Atlas shortcut "$()" is used instead of document.getElementById().

3. I stripped out all Repeater and Control Events, and now process everything in the Load event. The Load event looks for a value posted back in the HiddenField, because if the HiddenField contains anything, that means one of the LinkButtons in the repeater must have been clicked. So although the LinkButtons still perform the PostBack (with partial rendering), they are only used to jumpstart the processing in the Load event, and nothing else.

I hope this is helpful to anyone else who encounters the same problem with template controls and PostBacks. It may save you the day-and a half that I have spent on this issue.

Saturday, March 24, 2012

UpdatePanel and Default Button

There is nothing special about my ASP.NET code below. I have a label inside the update panel, and Button1, when pressed, sets the current time to the Label.

The only thing is, Button1 is the form's default button.

It works flawlessly in the development environment. I can press ENTER endlessly and it will work without postbacks. However, in the target environment, I observe very strange behaviors.

* Pleasecheck out the pageI have on my test server. Place your cursor inside one of the text boxes and press ENTER. It works. Now press ENTER again, Then it posts back. Every other time, it posts back.

* In my actual application, again it works in the development environment. But when ENTER is pressed the second time, I get a popup box that says,

Sys.WebForms.PageRequestManagerParserException:the message received from the server could not be parsed. Commoncauses for this error are when the response is modified by calls toResponse.Write(), response filters, HttpModules, or server traceenabled.Details: Error parsing near

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server" defaultbutton="Button1">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
<br />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>

<asp:Button ID="Button2" runat="server" Text="Not Default" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Default" />
</div>
</form>
</body>
</html>

Can you give your server side code.So i can find out your problem's solution.


There is very little to the server side code. Here
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partialclass _Default : System.Web.UI.Page
{

protected void Button1_Click1(object sender, EventArgs e)
{
Label3.Text ="Default button pressed. Time is " + DateTime.Now.ToString();
}
}


I think when hitting enter you are going of Focus on your app. Perhaps at the end of your method you can get focus back on your textbox through javascript or your method.

function focuxtextbox () {

document.getElementById('textbox').focus();

}


vicpal25:

I think when hitting enter you are going of Focus on your app. Perhaps at the end of your method you can get focus back on your textbox through javascript or your method.

Well, losing the focus is not the issue. It posts back every other time when I press ENTER. That it redraws the whole page every other time is a problem. When you just press the button, it works, but not when you press ENTER.


Hum, yeah I was checking out your sample app. Interesting behavior. Have you tried passing the:

UpdateMode="Conditional"

to the udpate panel?


vicpal25:

Hum, yeah I was checking out your sample app. Interesting behavior. Have you tried passing the:

UpdateMode="Conditional"

to the udpate panel?

Yes I did. Same behavior.


hello.

well, the problem is that you're partial postback isn't re-registering the button as the default button. you can see this by using fiddler. i've tried hosting the app on my machine, but iis is working correctly here. can you debug the app on the server and see the value of the _requireFocusScript field during the pre-render event of the page?


Luis Abreu:

can you debug the app on the server and see the value of the _requireFocusScript field during the pre-render event of the page?

I've noted this behavior only on the target machine, not on my development machine. So how would I go about debugging the value of the _requireFocusScript?


hello again.

yes, here on my machine i'm not seeing that behavior too. i only see it when i try to load the page from the server where you've deployed the app

well, you'll have to add a method that handlers the prereder event and then you'll have touse the watch window since you'll have to go through several non public fields:

manager._pageRequestManager._requireFocusScript


Problem resolved. Well, kinda.

A windows update for .NET fromwork 2.0 fixed it. However, it now only works for IE, but not for Firefox. I suspect that is a different issue all together.

UpdatePanel and Dynamically loaded controls (LoadControl)

Ok so this has been doing my head in for nearly 3 hours straight. Everytime I think I found a piece of code that could solve this problem, adapt it and try it... well I always get the same darn result.

Here's the structure
MasterPage
Page
TabContainer + TabPanel (AJAX)
UpdatePanel (in a tabpanel)
UserControl containing a second user control

I keep telling myself I may have gone crazy trying to work with such a structure, but i have to load a different part depending on the current page, but the base stays the same (so thats why I have imbricated usercontrols). I use LoadControl() at pageload to load the correct control.

Now on to the problem: The second user control (mainly consisting of a gridview, so I'll call it the grid control) disappears when I generate a postback from within itselft (like clicking on a link in the button column). If I generate a postback from the parent control, however, it works just fine. I tried a bunch of things, liek using the viewstate to reload the control, to no avail. I thought maybe it was my control structure that would be the problem, so I made a test user control with just a button called click. Same thing happens.

In debug, I realized that the gridcontrol's page_load event was never called when I generated a postback from itself. So i went radical and added an updatepanel around the page content. Seems to fix the issue, but I don't really want the events of that part of the page to be independant from the rest... Cuz some buttons on the parent user control are supposed to cause the data displayed in the gridcontrol to change. And unless I can set triggers from the parent control, which I don't really know how to do if it's possible, well it's not really useful.

I'd appreciate any input on this, I could post my code but I don't really think it'd be that useful, and I hope I've been clear anough.

Thanks for your time

Try registering programmatically the controls from your Grid Control to execute an async postback:

ScriptManager1.RegisterAsyncPostBackControl(control);


Wednesday, March 21, 2012

UpdatePanel and Legacy conformance

I am wondering if support for atlas in<xhtmlConformancemode="Legacy"/>is going to be added? The script code will only substitute out the $ for _

function uniqueIDToClientID(uniqueID){return uniqueID.replace(/\$/g,'_');

Previous versions of ASP.NET used : instead of $

Hi, that's a great catch - I opened a bug to track this issue. I'm not entirely sure if we will support that, since a lot of the things that UpdatePanel does requires XHTML compliance anyway, though we are relaxing some of those restrictions to better support existing applications.

Thanks,

Eilon

UpdatePanel and Server.transfer

I have a gridview inside a updatepanel that, based on the click of a button (commandbutton) postback to server and process the some code (associated with the command event) the page fails to do a Server.transfer("xx.aspx") The code is executed but the page "postback" to the old page not the
"transfer to page". Can't you do an Server.Transfer from a control inside a AtlasPanel ??


hello.

well, i think you won't be able to do that. if you use fiddler, you'll notice that you're getting a pageError element (which doesn't really gives any util info).

though i'm not sure about it, i'd say that you're getting an error from the application itself since the pageerror event of the control isn't being fired.

I'm a little bit puzzled as well. It seems that through this update panel, which is doing a partial rendering of a page, you can't end execution of the main page because of the page's lifecycle. Honestly, that is just a guess. I would be curious to hear from Mike or someone on this.

\=)


Server.Transfer does not make sense when you use updatepanels - the client is expecting fragments of rendering to update an update panel, and not an entire new html document. For buttons that result in Server.Transfer, make sure they aren't set up as triggers for update panels.
i also had encoutner this problem.
does anyone have any solution for this problem?

Hi,

As Nikhil pointed out, doing a Server.Transfer doesn't really make sense in an AJAX callback situation.

Also, it seems according to microsoft unless you're writing an ApplicationController Server.Transfer is probably not a good concept to use at all as it doesn't sit very well with search engines. I guess the only other time one would perhaps use it is if you want to display completely different pages based on certain criteria (like depending on if the user has logged in), but I would think this determination is probably best done in a HttpHandler. I myself usually dynamically load user controls for that though.

Nick


You may as well try Response.Redirect.

Hi,

Response.Redirect have the same (logical) problem.


Hi!

I know that this thread is a bit old, but I had a similar problem with Server.Transfer and UpdatePanels.

I found a working solution athttp://brunokenj.net/blog/index.php/2007/04/09/utilizando-servertransfer-e-aspnet-ajax-10/

Look at the first comment of the blog entry to get the code I am using.

It would be nice If I got some opinions about this solution.