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

Wednesday, March 28, 2012

AJAX Bug?

I have a page with an upper UpdatePanel that has 3 collapsible panel's and a lower UpdatePanel that has 2 gridviews in it. What happens is you select a list of employees and different training items in the upper UpdatePanel and a cross-tab grid is displayed in the lower UpdatePanel. Once the data is loaded into the cross-tab, it goes through every cell to update the text data to a graphical view of the data. So instead of 0 you would see a blank checkbox, and instead of 2 you would see a checked checkbox. The gridview columns are created dynamically based on what training selections were made. There can be as many as 400 training items at once and a couple hundred employees as well, so you can imagine how big the cross-tab grid can become if everything is selected. This page worked GREAT before I implemented ajax on it(I have my reasons), but now with AJAX in the page the cross-tab will only show if only a small number of employees or trainig items are selected. If you try to select every training item and every employee the whole program crashes in a very nasty way. Imagine losing the whole IE menu bars and start button, quickstart buttons, etc. The WHOLE screen becomes a jumbled mess. Any suggestions? Is this a bug or am I just trying to access too much data through AJAX?

JavaScript just flat out sucks with large amounts of data when looping.

You are probably causing JavaScript to have to loop through 1000's of form elements to figure out what is selected and build a string of that data to be posted. The freezing is the browser eating your CPU trying to crunch all of that data.

Eric


Thanks for the reply. I am starting to understand that this is the reason. Can you think of any workarounds? The only reason AJAX is being used on the page is to get the browser back button to work correctly so that the user can't click back and have someone's employee trained status revert to the previous state. Is there another way around this? Thanks.
hi.
i'm not sure if you're using updatepanels or are you wroking directly with javascript?
Here is a good post on JavaScript performance recommendations:http://blogs.msdn.com/ie/archive/2006/08/28/728654.aspx
Using Ajax
using Ajax.net with Update Panels.

Ajax Beta 1, UpdatePanel and Viewstate issue

Hi all,

I have found what could be a possible bug in the beta 1 regarding the use of the UpdatePanel with postback events.

If we use the update panel and inside it there is a control like a linkbutton that raise a postback, then the event is generated on the server and everything is going on correctly.

In my scenario I have a base page class that overrides the Viewstate load and save methods to compress and decompress it.A simply code that work fine without ajax and with the atlas ctp.(the code put the compressed viewstate content in another hidden field and let the original __VIEWSTATE empty).

With beta1 I've found that with a viewstate compression, this cause the postback events not raised with the right postback value.This happens for example when we click for the second time to the link button, when the viewstate has to be regenerated from the previous click.

I don't know what happens but I think that something has changed in the way the beta1 and UpdatePanel look at the viewstate.

Anyone has had the same issue ?

I just had this problem occur to me this afternoon. Upgraded to the new beta 2 from Atlas and the controls inside my update panels that stored values in ViewState started behaving funny. I too was inheriting from a base class that compressed and cached ViewState. As soon as I took this out and went back to System.Web.UI.Page, the controls worked fine again. This really sucks as we were able to trim so much bloat out of the page by compressing the ViewState. It would be wonderful if MS would consider this.

Forza Milan!


Colt45, to get his scenario working, you would need to explicitly register the hidden field that stores the compressed value of viewstate with ScriptManager, so that the framework would know that it needs to send the updated value for this to the client during an async post-back. I am guessing that you currently use Page.ClientScript.RegisterHiddenField(...) to render your compressed view state. Change this to ScriptManager.RegisterHiddenField(...)

This should fix your issue.

Hope that helps!


Thank you very much, kashif

It works well now...


Sorry...my previous post was wrong...it doesn't work!

I' ve used the ScriptManager.RegisterHiddenField as you suggest but nothing changed.

I need a solution because the viewstate compression is a usefull feature that I don't want to give up, as like as I don't with Ajax...


It did not work for me either.

Most of the problems I see are occuring in GridViews with paging and/or sorting. For example, I have a sorting routine that sorts ASC the first time the header is clicked and then DESC if it is clicked again. The value is stored in ViewState. The first time I click the header, the columns sorts ASC as expected. At this point, "ASC" is stored in ViewState so that when the header is clicked again, I can check this value and then sort by the reverse ("DESC"). However, the grid sorts ASC with every click because the new value is not persisting.

Paging also causes problems. The page data will refresh on the screen correctly between pages 1, 2, 3 etc. However, if I click a button in the 3rd row on the 3rd page that is supposed to update that customer record, it will actually retrieve the customer record that is on the 3rd row of the 1st page. In other words, Ajax always thinks the grid is on the 1st page even though the data on the screen reflects the 3rd page.

If I turn off compressing/caching ViewState, it works fine.
If I leave compression/caching enabled, but turn of Ajax, it works fine.
But together, the marriage fails.


protected override void SavePageStateToPersistenceMedium(Object pViewState)
{
Pair pair1;
System.Web.UI.PageStatePersister pageStatePersister1 = this.PageStatePersister;
Object ViewState;
if (pViewState is Pair)
{
pair1 = ((Pair)pViewState);
pageStatePersister1.ControlState = pair1.First;
ViewState = pair1.Second;
}
else
{
ViewState = pViewState;
}

LosFormatter mFormat = new LosFormatter();
StringWriter mWriter = new StringWriter();

mFormat.Serialize(mWriter, ViewState);
String mViewStateStr = mWriter.ToString();

byte[] pBytes = System.Convert.FromBase64String(mViewStateStr);

pBytes = Compress(pBytes);

String vStateStr = System.Convert.ToBase64String(pBytes);

pageStatePersister1.ViewState = vStateStr;

pageStatePersister1.Save();

//ClientScript.RegisterHiddenField("__MSPVSTATE", vStateStr);

}

protected override Object LoadPageStateFromPersistenceMedium()
{
System.Web.UI.PageStatePersister pageStatePersister1 = this.PageStatePersister;
//try
//{
pageStatePersister1.Load();
//}
//catch
//{
// return null;
//}

String vState = pageStatePersister1.ViewState.ToString();

byte[] pBytes = System.Convert.FromBase64String(vState);

pBytes = DeCompress(pBytes);

LosFormatter mFormat = new LosFormatter();

Object ViewState = mFormat.Deserialize(System.Convert.ToBase64String(pBytes));

return new Pair(pageStatePersister1.ControlState, ViewState);
}


Using ScriptManager.RegisterHiddenField(...) works fine in Beta 2 as long as you set the first argument as an update panel. The update panel can be empty, and should have its UpdateMode set to Always. UsingFiddler you should be able to see your new viewstate hidden field change appropriately.

Whether this is any better or worse than the code in the previous post, I don't know.

Andy

1protected override object LoadPageStateFromPersistenceMedium()2{3string viewState = Request.Form["__VSTATE"];4byte[] bytes = Convert.FromBase64String(viewState);5bytes = Compressor.Decompress(bytes);6LosFormatter formatter =new LosFormatter();7return formatter.Deserialize(Convert.ToBase64String(bytes));8}9protected override void SavePageStateToPersistenceMedium(object viewState)10{11LosFormatter formatter =new LosFormatter();12StringWriter writer =new StringWriter();13formatter.Serialize(writer, viewState);14string viewStateString = writer.ToString();15byte[] bytes = Convert.FromBase64String(viewStateString);16bytes = Compressor.Compress(bytes);17ScriptManager.RegisterHiddenField(this.updVS,"__VSTATE", Convert.ToBase64String(bytes));18}

Hi,

I to am experiencing this problem, i'm using Ajax RC1. I would take the option to use the scriptmanager but i have 2 major problems with this solution, i have a master page that contains the scriptmanager, and i want to apply this to all my existing pages. How can i reference the scriptmanager on the master page from the base class? If at all possible?


Kind regards,

Pedro Costa


Useshunzimm solution above. A slightly modified version of it worked well for me. I have ScriptManager on my master page and it works fine.


This might perhaps be due to changes in the ajax framework, but I've found that you do not need a update panel for ScriptManager.RegisterHiddenField() to work. I just used this as the first param and everything seems okay so far.


Thanks for this post, fixed my issue too with using scriptmanager. One question I have is does it buy anything to have this viewstate compression code on top of IIS 6 HTTP Compression or does http compression make this code obselete?


I've been trying to use the compression code in my application and I'm finding that it's causing problems with a few gridviews that I'm using. What's happening is that the 'OnRowUpdating' and the 'OnRowCancelingEdit' events are not being fired. I have an 'update' and 'cancel' LinkButton inside an 'EditItemTemplate' tag in a 'TemplateField'. The 'OnRowEditing' and the 'OnRowDeleting' events are being fired, but not the other two. Do you have any idea why this might be happening? Any help would be greatly appreciated.

Monday, March 26, 2012

AJAX asynchronous calls without update panel

Is the UpdatePanel always needed to make Asynchronously calls to the server? I was catching up with the client side capabilities for the framework using the $get and $sys client classes and seem to provide a lot of functionality. Any samples, tutorials where I can go to get some reference. I went through the AJAX framwework documentation but no help.

No, you can also use webservices or pagemethods take a look at these links:

http://www.asp.net/ajax/documentation/live/overview/AsynchronousLayerOverview.aspx

http://www.asp.net/ajax/documentation/live/tutorials/ExposingWebServicesToAJAXTutorial.aspx

http://www.asp.net/ajax/documentation/live/tutorials/ConsumingWebServicesWithAJAXTutorial.aspx

Hope this helps,
Elias.

Saturday, March 24, 2012

Ajax and TargetCOntrolID issue

In Atals, toolkit control can be out side of Updatepanel that includes the target Control. But For AJAX, it reports

An extender can't be in a different UpdatePanel than the control it extends.

or

The TargetControlID of 'PopupControlExtender1' is not valid. A control with ID 'DateTextBox' could not be found

How to solve this issue? It's painful if I need to change all toolkit controls in page for AJAX.

Beta 1 changed how everything worked compared to Atlas. You will need to place the extenders and target control within the same Update Panels (With exception of the ModalPopup - if you use this weeks Release Build on CodePlex)... Yes it will probably be a little more work but whats in the Betas now will be the RTM version so - its either now or then...

ajax and page_PreInit

Can someone please explain this to me.

Ive been trying to add some controls to a placeholder situated within a updatepanel.

According to microsoft i should create all dynamic controls in the page_preinit method. However when i did this the placeholder object was null.

When i moved the placeholder out of the updatepanel everything worked as expected

I moved the placeholder back into the updatepanel and moved the code to the page_preload method and i can now access the placeholder fine.

Im presuming that anything within an updatepanel cannot be access in the page_preiinit method, but can someone explain why.

Thanks in advance

Hi, I am having the same problem. Did you ever get an answer as to why this happens?

Thanks,

Steve

ajax and login

when i try to put login inside updatepanel get error message

in old version (atlas) login work cool if u enabledauthenticationService in web.config

<authenticationServiceenabled="true" />

any one can help please

hello.
are you talking about the asp login control? If so, i think it doesn't depend on the <authenticationService>?element...

ajax and linkbutton problem, it is difficulty ,i cannot resolve it , help me

I use Asp.net Ajax exten1.0 encounter some question,so I need your help

My problem is :

I use two UpdatePanel in one aspx ,we can call left panel ,and right panel

At right panel ,I need to automatism make a server table ,and in every table cell ,I must bind a linkbutton in there , as linkbutton , the linkbutton text data is from database, linkbutton bind it ,and linkbutoon commandArgument are bind data also ,

now , I encounter problem is , when I click linkbutton , but not trigger linkButton _command this Event ,so I cannot get commandArgument value.to diplay at updatepanel1 ,but ,I assurance I register this Event , when the linkbutton automatism make ,sure I use this method

eg:

lnkButton =New LinkButton() ' add Event

AddHandler lnkButton.Command,AddressOf lnkButton_Command

eg : add trigger

Dim trigger As AsyncPostBackTrigger = New AsyncPostBackTrigger() trigger.ControlID = lnkButton.ID UpdatePanel2.Triggers.Add(trigger) I Add tirggers but , in html source I cannot find like these code , Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('form1'));Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tUpdatePanel1','tUpdatePanel2'], ['btnConfrim','CalendarSelect','k0_0_0_0','k0_0_0_1','k0_0_0_2','k0_0_0_3','k0_0_1_0','k0_0_1_1','k0_0_1_2','k0_0_1_3','k0_0_2_0','k0_0_2_1','k0_0_2_2','k0_0_2_3','k0_0_3_0','k0_0_3_1','k0_0_3_2','k0_0_3_3','k0_1_0_0','k0_1_0_1','k0_1_0_2','k0_1_0_3','k0_1_1_0','k0_1_1_1','k0_1_1_2','k0_1_1_3','k0_1_2_0','k0_1_2_1','k0_1_2_2','k0_1_2_3','k0_1_3_0','k0_1_3_1','k0_1_3_2','k0_1_3_3','k0_2_0_0','k0_2_0_1','k0_2_0_2','k0_2_0_3','k0_2_1_0','k0_2_1_1','k0_2_1_2','k0_2_1_3','k0_2_2_0','k0_2_2_1','k0_2_2_2','k0_2_2_3',This 'k0_2_0_3' is linkbutton ID , That is why , thank you for your help

Your English is a bit shaky, so it was difficult to decipher exactly what is going on. However, one thing for sure that you are doing wrong is that you cannot create triggers programmatically. That is stated in the UpdatePanel Class page. If you simply use the ChildrenAsTriggers property set to true which is default, then when a link is clicked it will trigger the UpdatePanel update. However the issue of the command argument not available can be a bit more complex. It depends on the order of events and that is too complex to anayze without a simplified version of your code posted here. (Use the code editor button above to paste it a bit more neatly).

An example of why this might be necessary is that the order of page events can be affected by what is done during the page life cycle. For example I have seen the order of 2 events reverse simply by doing a FindControl or not in a method. There are muliple points in the life cycle where a control can Bind for instance and it may in fact Bind multiple times without you knowing it. That's just the way it works.

I would suggest that you add a Trace to all relevant events and check the order of events as that can sometimes give you insight. I have a very complex GridView run in Ajax, and without Trace events, I never would have been able to figure out what was wrong during edit with 2 way binding templates, column re-ordering, multi-column sorting, paging, etc all of which occur with Ajax.


sorry , my english is very poor.

my code is :

Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.Load createTable()End Sub'Public Sub createTable()For iAs Integer = 0To 5Dim rowAs TableRow =New TableRow()For jAs Integer = 0To 6Dim cellAs TableCell =New TableCell() cell.Controls.Add(CreatePerSolt(i, j)) row.Controls.Add(cell)Next tabShecule.Controls.Add(row)Next End Sub Public Function CreatePerSolt(ByVal iAs Integer,ByVal jAs Integer)As TableDim tabAs Table =New Table tab.ID = i &"_" &"_" & jFor kAs Integer = 0To 3Dim rowAs TableRow =New TableRow()For hAs Integer = 0To 3Dim cellAs TableCell =New TableCell() lnkButton =New LinkButton() lnkButton.Text ="k" & i &"_" & j &"_" & k &"_" & h lnkButton.ID ="k" & i &"_" & j &"_" & k &"_" & h lnkButton.CommandArgument ="k" & i &"_" & j &"_" & k &"_" & hAddHandler lnkButton.Command,AddressOf lnkButton_CommandDim triggerAs AsyncPostBackTrigger =New AsyncPostBackTrigger() trigger.ControlID = lnkButton.ID trigger.EventName ="Click" UpdatePanel2.Triggers.Add(trigger) cell.Controls.Add(lnkButton) row.Controls.Add(cell)Next tab.Controls.Add(row)Next Return tabEnd Function Protected Sub lnkButton_Command(ByVal senderAs Object,ByVal eAs System.Web.UI.WebControls.CommandEventArgs)Handles lnkButton.Command Label18.Text = e.CommandArgument.ToString()End Sub

I think you have to try this a different way to start.

http://www.asp.net/AJAX/Documentation/Live/mref/T_System_Web_UI_UpdatePanel.aspx

Please note the following statement:

You can add anUpdatePanel control programmatically, but you cannot add triggers programmatically. To create trigger-like behavior, you can register a control on the page as an asynchronous postback control. You do this by calling theRegisterAsyncPostBackControl(Control) method of theScriptManager control. You can then create an event handler that runs in response to the asynchronous postback, and in the handler, call theUpdate() method of theUpdatePanel control.

However because your table is inside the UpdatePanel, if you have ChildrenAsTriggers default set to true,all the LinkButtons should trigger an update without needing to register them. Just remove the trigger code. Once that is done if you still do not get a CommandArgument, post the UpdatePanel markup so that this can be duplicated.

Wednesday, March 21, 2012

AJAX and gridview

I have a simple gridview in a updatepanel - like so

<

asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="Conditional"><ContentTemplate>

<

asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"AutoGenerateEditButton="True"><Columns><asp:BoundFieldDataField="CategoryName"HeaderText="Category"SortExpression="CategoryName"/></Columns>

</

asp:GridView></ContentTemplate>

</

asp:UpdatePanel>

But the edit and button generated by the gridview doesnt seem to act as any type of trigger - is there a simple example out to show how to use the gridview (or other traditional and databound controls) with the update panel and AJAX?

Okay I have to agree with this blog post

http://www.gridviewgirl.com/GridViewGirl/SqlDataSourceAGoodThing.aspx

All of the examples I have seen in the Atlas stuff seem to depend on the DataObjects - is there a way to use a DAL and binding the gridview in code to use AJAX from microsoft?g

AJAX and DataList Triggers

I have a damned problem

I'm Ajaxizing an old .net 2 page.

I have an UpdatePanel with inside a DataList that has, in EditTemplate, a form with lots of dynamic controls with callbacks and the "submit" button.

My problem is that i need to enable the Back Button in browser after the submit, then i try to add a <PostBackTrigger controlid="submit">, but it cannot see the button.

I did many many tries... is there someone that can help me?!

Tnx to all and sorry for my english ^^'

up ^^'

Ajax and buttons

well, im new to AJAX, but there's something i don't understand. If I put a button and a label inside an updatepanel, create a global int i=1, and onclick I do

i++;

label1.Text= i.ToString();

when I click, this action is only accruing once. afterwards when i click it's still stuck on 2. What am I doing wrong?

ty.

Hi, probably your label1 control isn't in update panel's content template. If you have a button into a UpdatePanel, when you perform click it will update only the content inside UpdatePanel.


Smile

HI

1) Are u add the label in the Update Panel.

2) Try with declare the variable as static int.due to the declaration also the problem occurs..



There is no concept of a "global" variable on an aspx page. It will reinitialize on each postback. You could either save the value to the ViewState or to a Session object.

You could always just look at the value of the label, increment that, and save it back to the label.


Well, i tried with viewstate and that didnt work either. the button and the label are both inside the update panel. the c# code is:

protected void Page_Load(object sender, EventArgs e) { ViewState["i"] = 1; Label1.Text = ViewState["i"].ToString(); }protected void bt_next_Click(object sender, EventArgs e) { ViewState["i"] =int.Parse(ViewState["i"].ToString()) + 1; Label1.Text = ViewState["i"].ToString(); }
when I click the button it increases to 2, but afterwards the next click doesnt change it to 3.


SpriteSODA:

Well, i tried with viewstate and that didnt work either. the button and the label are both inside the update panel. the c# code is:

protected void Page_Load(object sender, EventArgs e) { ViewState["i"] = 1; Label1.Text = ViewState["i"].ToString(); }protected void bt_next_Click(object sender, EventArgs e) { ViewState["i"] =int.Parse(ViewState["i"].ToString()) + 1; Label1.Text = ViewState["i"].ToString(); }
when I click the button it increases to 2, but afterwards the next click doesnt change it to 3.

solved it by checking postback in the page_load :)