Showing posts with label aspx. Show all posts
Showing posts with label aspx. Show all posts

Monday, March 26, 2012

Multiview inside updatepanel, Firefox error on refresh

Hi, I got this piece of code:

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="true"%><%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server">  <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>     <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex=0> <asp:View ID="View1" runat="server"> aaa<asp:Button ID="Button1" CommandName="NextView" runat="server" Text="Next" /></asp:View> <asp:View ID="View2" runat="server"> bbb<asp:Button ID="Button2" CommandName="PrevView" runat="server" Text="Prev" /> bbb<asp:Button ID="Button4" CommandName="NextView" runat="server" Text="Next" /></asp:View> <asp:View ID="View3" runat="server"> ccc<asp:Button ID="Button3" CommandName="PrevView" runat="server" Text="Prev" /></asp:View> </asp:MultiView> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

So basically it's just a multiview inside an updatepanel. It works when used properly, but in FireFox (not in IE and Opera), I get a little error. Say on the first view, I press next. Then I refresh the browser. Unlike when there's no update panel, the view resets to the first view. [This is not the MAIN problem, but help here would also be welcome].

Now, after the refresh if I press next, I get this error in FireFox(again, not in IE or Opera):

The state information is invalid for this page and might be corrupted.

Could someone give me a fix for this problem? I'd also like to know if it's possibe to retain the view on refresh instead of it resetting to the first one.

Thanks.

I copied your multiview and ran it, it works fine for me under FireFox 2.0.0.1

The only different is that my scriptmanager containsEnablePartialRendering="true"

Try it again or create a new Ajax WebSite for testing ... Good Luck.


Hi,

Thanks for the reply. However, I just can't get it to work. I created new ajax enabled sites (both on file system and IIS, thinking maybe it's an IIS setting), didn't help. I'm running 2.0.0.1 of FF - the same as you.

Could you try

www.funkybears.com/test.aspx

On the first page, hit next. Then use the refresh button of firefox. Click next after the page loads. I'm getting the error right then.

Also, if I don't use an update panel, if I hit refresh, the currently selected view shows up. With the updatepanel, it always returns to the first view. Is there a way to counter this?

Thanks.


Bump :)
I tried your URL, it works fine under both browser IE7 and FF.

Must have a <head runat="server"> Error

When i use<atlas:ScriptManager> tag in .aspx or .ascx pages without <head runat =server> , i get the following error. Is this a bug or as designed?

Server Error in '/AtlasWebSite' Application.

Must have a <head runat="server">

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.InvalidOperationException: Must have a <head runat="server"
Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[InvalidOperationException: Must have a <head runat="server">] Microsoft.Web.UI.ScriptManager.OnPreRender(EventArgs e) +262 System.Web.UI.Control.PreRenderRecursiveInternal() +77 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360



Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42

As designed, you need that runat attribute.
I got this too (which is easily fixed by making the head runat="server") but is this a requirement on any page using Atlas?

LordHits wrote:

but is this a requirement on any page using Atlas?

Hi,

no it isn't. If you're using Themes in ASP.NET 2.0 it's required to have that attribute.

Grz, Kris.


But i am not using any themes in my website which is fairly simple ASP.NET 2.0 impelementation. Infact i am using Atlas in .ascx control and .ascx control is loaded first then the page, as a result scripmanager is unable to see the <head runat=server> tag and generates this error.

Any clue?


XIII wrote:

Hi,

no it isn't. If you're using Themes in ASP.NET 2.0 it's required to have that attribute.

Grz, Kris.

Ok, but i'm not using themes and I still go that message. I don't know if it matters, but my scriptmanager control resides in a content page as opposed to the master page.


Hi,

I had the same problem. An .aspx page with a placeholder, loading an ascx control in code behind.

I replace the <head> section in my aspx page with<headid="headSection"runat="server">, and now it works.

As the ascx control had an updatepanel, i had to do the loadcontrol in the page-init method.

Hope that will solve your pb.

Gilles


hello guys.

i believe that the head element must be a server element since it's one of the sections that is sent back from the server to the client during a partial postback (ie, it's contents are parsed and send on every partial postback response).


Hi,

If you are using Master pages.. then have to make sure that <head runat="server"> is there in the master page.

regards,

ukv

My .aspx lost his format when I change a property on design mode

Hello,

I've just updated my project to the new ajax beta 1.

Everything looks fine, but when I make some change on my pages in design mode, the aspx source code lost completly the previous format.

Somebody could help me.

Thanks,

Rodrigo Sendin

Hello Ajax Guys,

I think my problem is related with an issue posted by "tschlarm" today (Beta 1 issues). I am working with Master Pages and I used to work in Design mode. After beta 1 I am having problems with the format of the aspx source code. (the source code format is totally changed when I work in Design)

I´ve modifed my web.config in order to change the tagPrefix of ajax controls (from asp to ajax), and the problem has stoped. My web.config was changed to:

<addtagPrefix="ajax"namespace="Microsoft.Web.UI"assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

<addtagPrefix="ajax"namespace="Microsoft.Web.UI.Controls"assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

<addtagPrefix="ajax"namespace="Microsoft.Web.Preview.UI"assembly="Microsoft.Web.Preview"/>

<addtagPrefix="ajax"namespace="Microsoft.Web.Preview.UI.Controls"assembly="Microsoft.Web.Preview"/>

Thanks,
Rodrigo Sendin

My Custom Control Extender no longer works

I have a control extender that disabled a button when clicked to prevent multiple clicks. It worked well on my test.aspx page but when I moved it over to my big project, I get this error:

"Sys.ArgumentException: Value must not be null for Controls and Behaviors.Parameter name: element"

The page I moved it on contains a MasterPage with a home.aspx, and within that there is a .ascx and in there is where my button + control extender are found. Here is the code.

.cs:

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

[assembly: System.Web.UI.WebResource("OneClickExtender.OneClick.js","text/javascript")]

namespace OneClickExtender
{
[TargetControlType(typeof(Button))]
[TargetControlType(typeof(ImageButton))]
public class OneClick : ExtenderControl
{
private string _submitScript = null;
protected override IEnumerable<ScriptDescriptor> GetScriptDescriptors(Control targetControl)
{
ScriptBehaviorDescriptor behavior = new ScriptBehaviorDescriptor("OneClickExtender.OneClickBehavior",targetControl.ID);
behavior.AddProperty("submitScript", _submitScript);

yield return behavior;

}

protected override IEnumerable<ScriptReference> GetScriptReferences()
{
ScriptReference sr = new ScriptReference();
sr.Name = "OneClickExtender.OneClick.js";
sr.Assembly = "OneClickExtender";

yield return sr;
}

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Control target = new Control();
target = FindControl(this.TargetControlID);
if (target != null)
_submitScript = Page.ClientScript.GetPostBackEventReference(target, string.Empty);
}
}
}

.js:


Type.registerNamespace('OneClickExtender');

OneClickExtender.OneClickBehavior = function(element) {
OneClickExtender.OneClickBehavior.initializeBase(this, [element]);
var _clickDelegate = null;
var _onSubmitScript = null;


}

OneClickExtender.OneClickBehavior.prototype = {
initialize : function() {
OneClickExtender.OneClickBehavior.callBaseMethod(this, 'initialize');
var e = this.get_element();
this._clickDelegate = Function.createDelegate(this,this._onClickDelegate);
$addHandler(e,"click",this._clickDelegate);
},

_onClickDelegate : function() {
this.get_element().disabled = true;
eval(this._onSubmitScript);
},

get_submitScript : function() {
return this._onSubmitScript;
},

set_submitScript : function(value) {
this._onSubmitScript = value;
},

dispose: function() {
$clearHandlers(this.get_element ());
OneClickExtender.OneClickBehavior.callBaseMethod(this, "dispose");
}
}

OneClickExtender.OneClickBehavior.registerClass("OneClickExtender.OneClickBehavior", Sys.UI.Behavior);

--

Any ideas?

hello.

instead of using targetcontrol.id i think that you should use targetcontrol.clientid.


This fixed it. However, because I am using asp:RequiredFieldValidator, my button gets disabled and never re-enables itself. I would have to make sure all fields were valid first. I will look into this right now.

Saturday, March 24, 2012

my javascript method not working with update panel

Hi All,

The gridview (inside a user control) i am using in my screen (.aspx page) have a Checkbox column in the end. When i click the checkbox in the header all the checkboxes are selected. (A long javascript code has been written for that in the user control)

Now I have applied a scriptmanager and update Panel on this user control, and since then the javascript which selects all the checkboxes is not working properly.

I would like to know what i can do to resolve this javascript issue. And also would like to know why using the basic tools of ASP.NET AJAX control is stopping my own javascript from firing.

Please Note: On leaving a validation on page, the page postback and shows the validation. After this the javascript of Gridview works fine.

I have tried searching on google, but was not able to find any satisfactory explanation to my problem. It would be great if you people can help me.

Thanks,

Shikha

Please post your source code.


Hi,

Thank you for your post!

It is normal when you place inline javascript in an undatepanel/

For more information and solution, seeUpdatePanel and Rendered (Inline)Javascript

It seems that the UpdatePanel essentially replaces the InnerHTML of a DIV with the delta returned from the server. If you try this yourself you will notice that any javascript elements in the html are not fired.

All javascript registered on the server-side (if you are using .NET) with the ScriptManager is put into a separate section of the returned delta. The atlas runtime obviously then loads these scripts into the document manually.

What if the returned HTML has Javascript tags already rendered in it? Nothing.:(
Such was our predicament and we had no control over the HTML that would be returned to the UpdatePanel (ReportViewer Control). Could we manually load the javascript ourselves when the UpdatePanel returns the payload? As it turns, we could.

You can create script elements on the fly and they get evaluated as you do. Atlas has the ScriptLoader object that will do it for you if your JavaScript is an external reference. Tweaking this idea we got a solution that found all the new Script elements and added them to the document.

If you have further questions,let me know.

Best Regards,

Need async post back from 1 user ctrl to another user ctrl in same master page.

Hi,

I have 3-4 web user ctrl in a Master page. Now this Master Page is being hosted by a page: ViewProductCategories.aspx. Among the userctrls on the MasterPage, I have got an ImageButton (asp:ImageButton) in one of the userctrl (ProductCtrl.ascx). Instances of ProductCtrl.ascx is being loaded dynamically on the ViewProductCategories.aspx dependng on the number of product under a category. So I have to dynamically assign the event handler for the image button click. What I want is: On the click of the asp:ImageButton (AddToCart) there should be a AsyncPostBack that only refreshes the CartCtrl.ascx which is another user ctrl on the same MasterPage, but not the other userctrls on the same master page. Situation is complex. Please let me know if any more info is needed.

Thanks,

Subhadip

Hi

You can check out this link for solution:AsyncPostBackTrigger from another user control

Please check out these linka for more information:

Trigger PostBack to an UpdatePanel from a separate UserControl?

Can I specify a UserControl custom event as a Trigger for update panel on Parent page?

Bubble Event from UserControl

Best Regards

Need Help - UserControl Completely disappears

I'm developing an ASP.NET Ajax application in VS2005. The problem is describe bellow

Scenario
=============
I have a ASPX page with a UpdatePanel( say it is UpdatePanel_ 1) and a Button(say it is UpdatePanel_ 1_Button). Under the UpdatePanel_ 1 I have a Panel(say it is BodyPanel_1) to load different control as require.

On UpdatePanel_ 1_Button click event, it will load different UserControl in the BodyPanel_1 and then call UpdatePanel_ 1.Update() method.

Now say I have a UserControl( say it is UserControl_ 1) have a TextBox and a Button(say it is UserControl_ 1_Button). On click on the Button(UserControl_ 1_Button), add a simple text(say - "You Click Me") in the UserControl_ 1's TextBox.

Issue
==========
If I load the UserControl(UserControl_ 1) in PageLoad event it works fine.

But when I load the UserControl_ 1 on the page UpdatePanel_ 1_Button click event, it load the UserControl_ 1 but in that UserControl when I click on the UserControl' s ( The UserControl_ 1_Button ) Button the UserControl Completely disappears ( The UserControl_ 1 get vanish from the page ).

In the design mode I can drag the user control (UserControl_ 1) and at run time can do visible and invisible but it's not the solution as I like to load different controls in the same page base on some logic.

Following is my Button Click event function.
protected void UpdatePanel_ 1_Button_Click(object sender, EventArgs e)
{
//get the panel
Panel bodyPanel = (Panel)this. Page.FindControl ("BodyPanel_1");
//load the usercontrol
Control myControl = this.LoadControl( "UserControl_ 1");
myControl.ID = "45646546";
//add the usercontrol
bodyPanel.Controls. Add(myControl) ;
//update the UpdatePanel
UpdatePanel_ 1.Update();
}

The above function loads the UserControl( The UserControl_ 1), but when you click on the Button(UserControl_ 1_Button) under the UserControl, it disappears. But when I load the same UserControl in the Page Load every thing works fine.

I understand that when I load the UserControl dynamically at run time it's not register the UserControl' s events.

Please let me know your suggestion.

Thanks

Hi,

It's necessary to add the control in Page_load everytime. Please read this FAQ:

1. Why do I have to recreate dynamic controls every time? /Why dynamic controls are disappeared on PostBack?


Whenever a request comes, a new instance of the page that isbeing requested is created to serve the request even it's a PostBack. Allcontrols on the page are reinitialized, and there state can be restored fromthe ViewState in a later phase.

The dynamic controls have to be recreated again and added tothe control hierarchy. Otherwise, they won't exist in the page.

Please be careful with when to create dynamic controls. Inorder to keep their state, they have to be created before the LoadViewStatephase. Page_Init as well as Page_Load methods are options available.

For more information about this topic, please refer to thisarticle:

Creating Dynamic Data Entry User Interfaces[http://msdn2.microsoft.com/en-us/library/aa479330.aspx ]

Hope this helps.