Showing posts with label ive. Show all posts
Showing posts with label ive. Show all posts

Wednesday, March 28, 2012

AJAX Update Panel Problems

Hi,

I'm converting an existing site to use the AJAX toolkit. So far the only problems I've had have been the usual teething problems when learning a new technology. Now though, I'm having a problem with using one of my existing classes from code invoked from a control in an update panel. It's always worked fine until using the update panel. I've pasted the code below (i got it off the web by the way). If i call it from a control outside of an update panel i have no problems.

The error message i'm getting is as follows:

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 'leteWeek"));
});
|<script language='ja'.

Any help/pointers would be much appreciated.

publicclassMessageBox

{

privatestaticHashtable m_executingPages =newHashtable();

private MessageBox(){}

publicstaticvoid Show(string sMessage )

{

// If this is the first time a page has called this method then

if( !m_executingPages.Contains(HttpContext.Current.Handler ) )

{

// Attempt to cast HttpHandler as a Page.

Page executingPage =HttpContext.Current.HandlerasPage;if( executingPage !=null )

{

// Create a Queue to hold one or more messages.

Queue messageQueue =newQueue();

// Add our message to the Queue

messageQueue.Enqueue( sMessage );

// Add our message queue to the hash table. Use our page reference

// (IHttpHandler) as the key.

m_executingPages.Add(HttpContext.Current.Handler, messageQueue );

// Wire up Unload event so that we can inject

// some JavaScript for the alerts.

executingPage.Unload +=newEventHandler( ExecutingPage_Unload );

}

}

else

{

// If were here then the method has allready been

// called from the executing Page.

// We have allready created a message queue and stored a

// reference to it in our hastable.

Queue queue = (Queue) m_executingPages[HttpContext.Current.Handler ];

// Add our message to the Queue

queue.Enqueue( sMessage );

}

}

// Our page has finished rendering so lets output the

// JavaScript to produce the alert's

privatestaticvoid ExecutingPage_Unload(object sender,EventArgs e)

{

// Get our message queue from the hashtable

Queue queue = (Queue) m_executingPages[HttpContext.Current.Handler ];if( queue !=null )

{

StringBuilder sb =newStringBuilder();

// How many messages have been registered?

int iMsgCount = queue.Count;

// Use StringBuilder to build up our client slide JavaScript.

sb.Append("<script language='javascript'>" );

// Loop round registered messages

string sMsg;while( iMsgCount-- > 0 )

{

sMsg = (string) queue.Dequeue();

sMsg = sMsg.Replace("\n","\\n" );

sMsg = sMsg.Replace("\"","'" );

sb.Append(@dotnet.itags.org."alert( """ + sMsg +@dotnet.itags.org.""" );" );

}

// Close our JS

sb.Append(@dotnet.itags.org."</script>" );

// Were done, so remove our page reference from the hashtable

m_executingPages.Remove(HttpContext.Current.Handler );

// Write the JavaScript to the end of the response stream.

HttpContext.Current.Response.Write( sb.ToString() );

}

}

Hi,

you can't use Response.Write during a partial postback. The reason is that the response sent after a partial postback has a special format (you could useFiddler to see it). If you use Response.Write, you're directly writing to the response stream and corrupting the response's format.

To inject JavaScript during a partial postback, you should use the static RegisterXXX methods of the ScriptManager control.


Thanks for that. I found aa article elsewhere explaining how to use the script manager and I've got that working fine. Thanks for your help.

AJAX Update Panel problem with IE6

On my site I have an asp:dropdownlist next to an asp:image. Ive put both of these within an asp:updatepanel. When the selected item in the dropdownlist is changed the panel updates with a new image depending on the selected item. This all works fine on FireFox and IE7, however on IE6 I get the following error:

Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 12019

As a temporary fix I have removed the updatepanel tag meaning the page now reloads every time and it works fine. However it would be much better if this didn't have to happen. Has anyone seen this error before, and if so how can I stop it from happening. Why does it happen on only IE6?

Thanks,

Curt.

Maybe this can help: http://forums.asp.net/t/1123365.aspx

Two last replies are specially interesting Wink


Thanks for the link bsevo.

I have been testing the site using IE6 on an OS which also has IE7 so maybe thats why its not working? I'll have to try and find an OS which has the 'real' IE6.

Ajax Update panel button disable/enable

I am trying to disable a button after the request begins and then enable when the request ends. I've gotten the disable part to work but it does not enable it. What am i doing wrong? Here is my code.

Thanks.

<formid="form1"runat="server">

<ajaxToolkit:ToolkitScriptManagerrunat="server"ID="ToolkitScriptManager1"EnableScriptGlobalization="true"EnableScriptLocalization="true"></ajaxToolkit:ToolkitScriptManager>

<scripttype="text/javascript">

Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(HideButton);

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(ShowButton);

function ShowButton()

{

$get("Button1").disabled ="false";

}

function HideButton()

{

$get("Button1").disabled ="true";

}

</script>

<div>

<ajax:UpdatePanelID="UpdatePanel1"runat="server">

<ContentTemplate>

<asp:ButtonID="Button1"runat="server"Text="Button"OnClick="Button1_Click"/>

<asp:LabelID="lblTest"runat="server"></asp:Label>

</ContentTemplate>

</ajax:UpdatePanel>

<ajax:UpdateProgressID="UpdateProgress1"runat="server"AssociatedUpdatePanelID="UpdatePanel1">

<ProgressTemplate>

processing.....

</ProgressTemplate>

</ajax:UpdateProgress>

</div>

</form>

Hi Azminer,

My understanding of your issue is that the button you disabled when beginRequest event is fired cannot be enabled when the partial-update finished. If I ahve misunderstood you , please feel free to let me know.

I think your problem is caused by this sentence ($get("Button1").disabled ="false") that you have assigned a string value to a bool variable. Here is my sample:

<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(HideButton);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(ShowButton);
function ShowButton(){
$get("<%=Button1.ClientID %>").disabled = false;
}
function HideButton(){
$get("<%=Button1.ClientID %>").disabled = true;
}
</script>

By the way, in your situation, you can get the same result without doing anything in endRequest event since the elements inside the UpdatePanel has been refreshed.

Best Regards,

Jonathan


Thanks Jonathan!

Monday, March 26, 2012

ajax toolkit tags

hi, i was just wondering because as i've seen in the examples in this forum, when adding an ajax toolkit, in the source code, you can see <ajaxToolkit:SomeToolkit> if i am not mistaken. but when i try to drag a toolkit to the page, or add a toolkit, the tag is different, like <cc1:SomeToolkit>. this puts me to confusion and i am worried that if i upload this to my host, it will not be recognized by the host and i will be obliged to change it manually. what if i have 50 pages that uses 5-8 ajax toolkits? its really a hard work. but this is just an example. maybe you guys can shed light on this. thank you.

Refer to the following link to understand where the tagprefix comes from and their significance

http://www.microsoft.com/mspress/books/sampchap/5728d.aspx#124

As to your worry about different tagprefixes causing problem, it is unfounded.

The declaration at the top of your aspx page e.g.

<%@. Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>

and the control tagprefix need to match.

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

Other than this all your pages could have different tagprefixes.

AJAX Toolkit installation issue

Hi all, I've downloaded the toolkit but I'm not running the full version of web developer. Can anyone tell me how to upload the toolkit into the toolbox? Thanks for any help you can give.Smile

Andy

checkout this link

http://asp.net/AJAX/Control-Toolkit/Live/Walkthrough/Setup.aspx

if you find soln, mark this post as answer


Thanks - that was very useful.Smile


You r most welcome !!!

Ajax toolbox missing in Visual webdeveloper 2005 express

I've just installed the Ajax tool kit but the toolbox is missing from the toolsbox panel. I have the Ajax website in the templates but no toolbox and suspect there is no intellisence either. Does anyone know haw to sort this out Ajax toolbox missing in Visual webdeveloper 2005 express

regards

jim

Hi Jim,

The AJAX Control Toolkit won't show up automatically in the toolbox - you have to add it yourself. Check out theSetup Your Environment walkthrough for details on how to add them. Intellisense also works fine.

Thanks,
Ted

Wednesday, March 21, 2012

AJAX TabPanels and user defined controls

Hi,

I've built a control in which I implement the behaviour described in this video:How Do I: Trigger an UpdatePanel Refresh from a DropDownList Control? Basically, I want to update the nodes of a TreeView when I change the item in a DropDownList.

This works great except if I load the control dynamically into a tab panel...In this case, the first SelectedIndexChanged event doesn't trigger anything and all of the following events trigger a full page postback...

So, to sum this up:

    User control statically defined in a page -> OKUser control statically defined in a tab panel -> OK (it works when I put the code of the control inside the tab panel)User control dynamically loaded into a placeholder -> OK (using PlaceHolder1.Controls.Add(Page.LoadControl("WebUserControl.ascx"));)User control dynamically loaded into a tab panel -> NOT OK! (using both TabPanel1.Controls.Add(Page.LoadControl("WebUserControl.ascx")); and TabPanel1.ContentTemplate = Page.LoadTemplate("WebUserControl.ascx");)

I can't put the code of the control inside the tab panel statically (point 2 in the previous list) because the tab panels are being generated dynamically also...

Anyone has suggestions to solve this, please??

When are you adding these dynamically created controls? It sould be during the Page_Init event and not later (such as during the Page_Load).


I'm not adding the controls in the Page_Init as I can't do that...when my page first loads it has only a DropDownList with a list of options.

Then, when the selected option is changed, there is a postback (as the DropDownList has AutoPostBack = "True") and only then the tabs are created and the user control is loaded.

The user defined control is being rendered and is visible, but its behaviour is strange...


If you dynamically add your contorls into an updatepanel, the issue comes.

There are few good articles written byScott Mitchell on dynamically loading Controls which you will find in the following links:

Dynamic Controls in ASP.NETWorking with Dynamically Created ControlsDynamic Web Controls, Postbacks, and View State

Ajax TabControl and validation are incompatible - any way to resolve

Hi -

I've found out that the buttons in my tab panels no longer post back when I add validation on the input form. Is there a way around this? Has anyone solved this?

Thanks for ANY help or idea how to tackle ...

Oliver

Each tab have their own buttons? if this is a case use ValidationGroup. e.g: in tab1 assign to ValidationGroup property in your validation controls and button controls to say tab1, in tab2 assign a validationgroup property of say tab2 and so on.


the content of each tab are in a user control ... I thought that would take care of it, ... thanks for the pointer

AJAX tab control postback of dropdown event in VB

I've read so many posts my head is spinning! So, I'm struggling w/ the autopost back of a dropdown from within a AJAX tab control.
Does anyone have a simple example? Here's my code.

<asp:ScriptManagerID="ScriptManager1"runat="server">
</asp:ScriptManager>
<asp:SqlDataSourceID="SqlEvents"runat="server"ConnectionString="<%$ ConnectionStrings:LLB_Con %>"
SelectCommand="SELECT [T], [X] FROM [Events] ORDER BY [startdate] desc"></asp:SqlDataSource>
<ajaxToolkit:TabContainerID="tabAdmin"runat="server"ActiveTabIndex="1"Height="512px"Width="1121px">
<ajaxToolkit:TabPanelID="TabPanel1"runat="server"HeaderText="Manage Data">
<ContentTemplate><br/>
<asp:HyperLinkID="hlEventFormat"runat="server"NavigateUrl="~/Admin/Event_Format.aspx"Text="Manage Event Format"/>
</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanelID="tpProcessing"runat="server"HeaderText="Event Processing">
<ContentTemplate><br/> <br/><br/>
<asp:DropDownListID="ddEvents"runat="server"
DataSourceID="SqlEvents"
DataTextField="T"
DataValueField="X"/><asp:HyperLinkID="hlEnter_Event"runat="server"Text="Enter Event Data"NavigateUrl="~/Admin/eventEntry.aspx"/>
</ContentTemplate>
</ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer>

I think you need to add at the DropDownList

AutoPostBack="True"

George