Showing posts with label update. Show all posts
Showing posts with label update. Show all posts

Wednesday, March 28, 2012

Why IsPostBack=false? How to repair that?

I'm using Ajax.Net. There is UpdatePanel on the page. It contains GridView. When I press "Edit", "Update" or "Cancel" button in the GridView then UpdatePanel reloads. Also executes code "if (!IsPostBack) { ... }" in Page_Load event on the server - but I don't need it!!! This code must run only once when page is loading for the first time.

protected void Page_Load(object sender, EventArgs e) {if (!IsPostBack) { ...// Here there are bindings for each control. // This code must run only once ...// On every action with GridView (which is placed in the UpdatePanel) // this code executes again and again. // Why? And how to prevent that? } }

1) Why IsPostBack=false (in Page_Load) on any action with GridView?

2) How to prevent that?

when you are clicking the button it's like you are reloading the all page but not the design... If you do not bind again the gridview loses data... Best solution is to cache the datatable that binds the gridview and binding the gridview to that... You can always verify the state of the grid to verify if you do some code...

As I understood, on every asynchronious postback (or mayme it's callback) the page is creating as it is not postback (isPostBack=false).

I think that it is better to use Session instead of Cache because every user has it's own data in the tabe.


cache in client... it's not postback... because the reference it's different... when you have difficulties test without the updatepanel to see if it's another reference of the page or not...

and i know what you're thinking the adress it's the same... it's ASP my friend... works that way.


What means "cache in client"? How? I can cache data only on server.


HttpContext.Current.Cache.Insert(itemString, Obj, HttpCacheability.Public, DateTime.Now.AddHours(expiration), TimeSpan.Zero)



Oh, it's caching on the server side, I thought you means caching data on the client side.

I change a bit my question. So, on each asynchronious postback executes code "if (!IsPostBack) { ... }" in Page_Load. But I want to prevent it. This code must executes only once when page is loading for the first time. How can I know if the page is loading for the first time or it is asynchronious postback? I want something like that: "if (!IsPostBack && !isAsynchroniousPostBack) { ... }"


did you tried with page.callback?


most likely no. what do you mean?


Put if not ispostback and not iscallback...


I wrote "!IsPostBack && !IsCallback && !IsAsync" - IsCallback and IsAsync always =false. IsPostBack in some cases =true and in some cases = false


tell me what are the cases that give true...

you don't have the need to put all of this...

if it doesn't control for you the postback you can put a viewstate that keeps the state of the grid.

just like this:

If not ispostback and viewstate("Should_Enter_Here")

end if

and in the event of the grid put this viewstate equals a true.


What you are looking for isIf (!ScriptManager.GetCurrent(Page).IsInAsyncPostBack).

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


Thanks

Why slow UI with AJAX?

I am working on a page that displays paged ResultSet from a database. I created the page without AJAX update panels. Later I added those to ajaxify my application. The problem is when I change pages in my GridView the time it takes for it show the new results (using Asynchronous postback) is about 4 secs more then a regular postback.

Does any one know why it is slow. I usedfiddler tool to check the response size and Asynchronous postback does come back with less number of bytes but why slow UI update?

Thanks for your help.

The thing that will effect your AJAX postback the greatest is the size of your ViewState.

Comment out your update panels & script manager and then enable tracing for your page.<% @.Page Trace="True" %>The trace information will show you exactly how large your ViewState is for that page. Try paging through your GridView and see if you ViewState size grows as you page. Even if the size doesn't grow, if the initial ViewState size for your page is very large, it will cause long delays between AJAX postbacks. If you do find that your ViewState is huge, or it grows between postbacks, try to figure out which controls you can disable the ViewState for (EnableViewState="False") or what might be causing your ViewState bloat.

Just as an FYI, I have used UpdatePanels with GridViews in many different cases without a problem. I did have to tune the ViewState for some of the pages I made to speed things up, but it can definitely be done and it works great.

-Aaron


I am totally agree withSchnieds , that you have to disable the viewstate wherever it is not necessary..

Do one more thig also..try to set <compilation debug = "false" > in web.config

Hope it will help you.Smile


Thanks for your replies. I tried to turn the viewstate off for the gridview but then my pagging gets all screwed up. I have a dynamic paging option where user can select the number of results displayed per page. When I turn off the viewState it gets set to the default value (which is 14) and the page index gets set to 1.

Any ideas?

P.S.: I do have the <compilation debug="false" />


You probably won't be able to disable the ViewState for your GridView, but you may be able to disable it for other controls on your page and decrease the overall ViewState size.

Turn on tracing as I suggested, figure out what control(s) have a large ViewState and look for the other things I mentioned in my previous post. You should be able to determine what is causing your ViewState bloat very easily with the tracing turned on.

-Aaron

Monday, March 26, 2012

Will Atlas Work With Opera 8.60 for Pocket PC?

myAtlas Update Panels are working fine when i access the page from a standard desktop Opera browser. However the page is posting back when i do the same thing from within the PDA. the PDA is running the latest 'Opera 8.60 for Pocket PC' browser.

can i somehow configure the Atlas or the page so that it will work on the PDA browser? or am i on a hiding to nothing?

thanks

I don't speak for the ASP.Net team; however at this time there is no real 'support' for mobile devices (so yours being opera is not a slant). Currently there is some Opera desktop browser support and they are looking at expanding it. As with all new tools we get to play with - mileage will end up varying - however if you are familiar with Java Script... there may be a means for you to roll your own if its a mission critical scenario... However, personally - I don't think right now the focus is in provding mobilie support as it is more inline to polishing desktop browser experiences... NOt to sy it won't won't happen.. but usually mobile applications don't rely on the jazzability that memory / cpu intensive desktop browsers can utlize...

Will using Update Panel really give any performance improvements compared to non-AJAX site

Hi,

When one uses the Update Panel to remove the browser refresh then will there be any real performance gains as it yet does a full page postback and goes through the complete page life cycle on the server?

Using Update Panel sure makes the end user feel as though the browser refresh has been removed. But is there anything more to it?

Thanks,

- Manoj

Hi,

if you want to know more about this I would like to recommend you to check out this video that was shot on TechEd 2006 Barcelona:http://www.microsoft.com/emea/msdnshowtime/sessionh.aspx?videoid=331.

It shows the good and the bad of the UpdatePanel and how to tweak it.

Grz, Kris.


hello.

and the obvious answer is that it's not there to increase performance :)

Windows live style info panels

Hello,

I just logged on to my windows live email account and noticed that they did an update to the interface.

When the page loaded, there was next to some textfields and buttons a yellow balloon with information about the corresponding field. There was also a link in the balloons to close all the balloons on the page. Does anyone know if this is possbile with the Ajax control toolkit ?

I did not see an extender to do that in the previous version, however yesterday MS just release the new MS AJAX library (Atlas) with more controls, download them maybe you lucky, you can always create it and submit it to MS using their library

Saturday, March 24, 2012

Wizard Control

I am using the Wizard Control in an aspx page inside an Update Panel control. What I want to do is to navigate to this page and set which Wizard Step should be active dynamically. Something like :

if(Request["whichstep"]!=null)

Wizard1.ActiveStepIndex=int.Parse(Request["whichstep"]);

Now this works fine in that the correct Wizard step is shown when the page is loaded. But the problem is that the Wizard gets STUCK on this step. i.e. you can't use the previous/next navigation buttons to move forward or backwards.

Any help would be greatly appreciated (PS. we also tried taking the Update panel out, but the same problem exists).

HN.

can you post your code? where in your code are you checking the wizard activestepindex?

Hi boolie,

Thanks for taking the time.

The code is very simple. The page that is calling the page with the Wizard has button and its click event has Response.Redirect("WizardPage.apsx?step=3");

The page that has the Wizard on it checks on the Page_Load : if(Request["step"]!=null) Wizard1.ActiveStepIndex=Int32.Parse(Request["step"]);

As I mentioned, this works. The wizard shows the correct step. But the problem is that you can't navigate i.e. go backward or forwards using the previous/next buttons.

By the way I tried putting the code in various other events that is raised by the Wizard, they all have the same behaviour!


not sure this will fix the problem, but at least it might help eliminate some things to troubleshoot...

Are you checking for whether or not it's a postback before running the "if(Request["step"]!=null)..."?

something like this:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//code would go here...
}
}

if you haven't tried this, test it and see if you notice any difference. What might be happening is that when you click on "Next" or "Previous" it's causing the page to reload which would cause the Page_Load code to run again which would show you the same step. I could be completely wrong, but at least we'll have one troubleshooting step out of the way. Let me know what happens.



Sorry. But I should have mentioned that I do test the Postback in my last Post and it still gets Stuck. Is this some kind of Bug in the Control do you think? After all they are only panels that get their visibility changed!
I kind of thought you might be checking that already. honestly, i have no idea whether or not it's a bug, but it does seem pretty strange. i'll try some tests on my own and see if i can duplicate the problem and then maybe i can help find a solution
Many Than

Many Thanks.

Looking forward to your findings.

Wizard Control problem

This is an interesting one, although I did have it working earlier, it has since ceased to function.

I have a wizard control in an update panel on a user control on a page which uses a master page. oh, on a second note, a calendar extenders style / theme seems to break if the calendar control is not on the first page displayed in the wizard bar; but thats another story and not my immediate consern.

the problem is, that the next button returns a javascript error " 'null' is null or not an object, line 105 " ... but the odd thing is that it only breaks on the second page, so the first click of the next button works and sends you to the second page, but the second one does not work.

There is some code under the next button;

Protected Sub Wizard1_NextButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.NextButtonClick
If Wizard1.ActiveStepIndex = 1 Then
'some code here
end if
end sub

but it still breaks even if I comment out all the code or change the index from 1 to 2...

Thanks for reading this far, it was a bit of a long post.

Scott

you should go to your Internet Explorer's Internet Options and then go to the Advanced Tab. There you can check out 2 options: "Disable script debugging (IE)" and "Disable script debugging (other)".

Check these out and then debug. Then you can go into more detail about the javascript error.


the only extra i can add to the error message is this

Line: 104
Char: 5
Error: 'null' is null or not an object
Code: 0

I suspect that the javascript error is in the Update Panel, but im not sure...

Sorry.


Hey scott,

since nobody responded with something useful, ill give it a try ...

The error you are getting is very wide. This error can be thrown everytime an object isn't initialised at the moment you try to allocate a value to it.

because the error is so wide it's not easy for us to give a straight to the point answer.

You could try to strip down the problem into a demoProject which replicates the error so its very easy for everyone to follow what's going on.

Another thing you could do is look at the way your wizard runs through its pages. How is it set up? When creating wizards I would go for the multiview with serveral views in it for each wizardPage and then some buttons for the navigation. I made some sort of tabsControl with a multiview in an updatepanel and some navigation and all works fine :p

Good luck!


Thanks for the reply.

It gets weirder every time I look at it. In Mozilla FF it works fine; it seems only IE7 (not tried <6) stops me moving between the pages of the wizard control.

After what you said, a thought did occur to me, it stops on the page after the page containing two ajax calendar controls... but this was the wrong line of enquiry so i copied my script and progressivly removed parts until it started working.

I think this is caused by a common variable in the javascript between "something" and the required field validator control. I am using:

Modal Popup
Calendar Extender
Update Panel
and Required Field Validators

and it works fine when I remove all the validators.

I am a little behind schedule now, but I will try and recreate this on a new project later and if I get the same results with the error, it might be a small bug.

Thanks for the advice btw,

Scott M


I found out how to fix it, apparently its the required field validators use an old API to register their script !? there is a post on here somewhere (which I failed to find) that has a link to a recently compiled version of them which works flawlessly.

Wizard inside of update panel, still getting postbacks

Hi,

I placed a wizard inside of an update panel and when I click on the button for the next step, I still get a postback. I have tried setting the mode to conditional and it still occurs.

I even tried making a new atlas website and putting nothing but the update panel with the wizard inside and it still does not work. Here is the code below. Any idea what I am doing wrong??

<atlas:ScriptManagerID="ScriptManager1"runat="server"/><div><atlas:UpdatePanelID="UpdatePanel1"runat="server"Mode="Conditional"><ContentTemplate><asp:WizardID="Wizard1"runat="server"><WizardSteps><asp:WizardSteprunat="server"Title="Step 1"></asp:WizardStep><asp:WizardSteprunat="server"Title="Step 2"></asp:WizardStep></WizardSteps></asp:Wizard></ContentTemplate></atlas:UpdatePanel>

Hi,

it seems that you are not setting EnablePartialRendering="True" in the ScriptManager control.

Yes you are right. In the sample code I pasted that was the problem (and I feel very stupid). However in my actual code I did remember to set partial rendering to true.

Now, that being said, I think I figured out what was wrong, and hopefully the Atlas guys watching this forum can tell us if I am correct.

A little more background on the page first, it is a content page and the master page has a flash banner on it that I put their using the asp.net 2.0 flash control. On my developoment machine I didn't have the flash file it was pointing to. Instead of throwing an exception when I view the page in my browser it just kept perpetually loading the page.

It occured to me that the update panel may not work properly if the page had never completed loading before a postback was called. All I had to do was copy the flash file from the webserver to my development system and VOILA! The page loads, the update panel works.


Hi,

glad to hear that you solved it :) I'll bookmark this post for future reference.

Wizard with Update Panel

I have a Wizard control with inupdatepanel . I am trying to create dynamic wizard steps in pagepre_init event, but it is giving me an error " object reference not setto an instance of an object" . without updatepanel it's workingproperly.

Thanks in Advance

Do you have a fileupload control in the wizard? If so,see this thread.

hello.

please post a simple page that reproduces this problem.

working with dataset using asp.net ajax 1.0

I have a web service which is returning a dataset ... this dataset will be bound to a data grid inside an update panel.

How can I get that dataset to the data grid IF the web service is being called via java script ?

Am trying to avoid getting back XML as that would mean a lot of DOM parsing and I dont want to use the DOM structure unless abs necessary ?

If the webservice is being called using javascript, I assume it is on the clientside.

But the binding to the data grid will have to be done on the server.

One way to go is to call the webservice on the server and bind the returned dataset to the datagrid.


Hi,

Maybe this article is helpful to you:http://dotnetslackers.com/articles/ajax/ASPNETAjaxGridAndPager.aspx

Best Regards

Wednesday, March 21, 2012

Writing Javascript at Runtime on Update

Ok, I can't seem to find a shred of working advice on this topic. But, here are the basics.

Button inside of an updatepanel. Partial rendering is turned on.

Button gets clicked. Ajax call is made to the server. How do I at this point write javascript to the client's box that will execute, such as an alert.

Can't use Response.Write. Can't use ClientScript.Register... since that requires a full postback, unless I'm missing something. So...I'm not really sure what my other options are, surely someone else has run across this already. If you have any insight please share it with me.

Use EVAL() function of Javascript. It can be used as following,

<SCRIPT language="Javascript">

function Popup()

{

ExecJavascript("alert('Hi All');");

}

function ExecJavascript(var jscript);

{

eval(jscript);

}

</SCRIPT>


Use ScriptManager.RegisterStartupScript. Here's a working 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"> private void button_click(object sender, EventArgs e) { ScriptManager.RegisterStartupScript(up1, up1.GetType(), "myscript", "alert('Alert sent from server!')", true); }</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" UpdateMode="Conditional"> <ContentTemplate> <asp:Button ID="button1" runat="server" Text="Click Me" OnClick="button_click" /> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

hello.

or, if you don't need to return anything from the server, you can also hande the endrequest event of the client pagerequestmanager object which is available in all the pages that have updatepanels.

<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest( endRequest );

function endRequest( sender, e ) {
//put your code here.
}
</script


Perhaps I was not clear.

madesh, Your code is only from javascript to javascript. That isn't the issue.

Steve Marx, You don't have partial rendering enabled. You will find that enabling that will prevent your button from registering that script block because doing that requires a full post back.

Luis Abreu, I do need to send info back from the server.

Let me restate the problem. You're on the server, there isn't any javascript already on the client. You need to write some JS to the client, from a partial postback. ie, they just pressed the button, but it was through AJAX which means no script registering through the ClientScript object. So, during this partial post back, what are my options for sending a script block to the client?


Crap miss-read that Steve, I haven't tried it with the script manager, ill give that a shot when i get home. Why can't we edit posts?...


Excellent. Thanks Steve it worked. The trick is, you can't use Page as the control to register the script with. You have to use an existing control on the page, any will do. Even the update panel (up1). Thanks.

ZeroDegrez:

madesh, Your code is only from javascript to javascript. That isn't the issue.

Let me restate the problem. You're on the server, there isn't any javascript already on the client. You need to write some JS to the client, from a partial postback. ie, they just pressed the button, but it was through AJAX which means no script registering through the ClientScript object. So, during this partial post back, what are my options for sending a script block to the client?

As you stated that it is a AJAX call and Javascript gets generated on server side. EVAL can help you. Return your server generated Javascript to Client side as a string(Output of your AJAX call). Execute that Javascript on Client side using EVAL function.

This way you can execute the javascript returned by your AJAX call on client side.

<SCRIPT language="Javascript">

function AJAXcall()

{

var JScript={Put your AJAX call here};

ExecJScript(JScript);

}

function ExecJScript(var JScript)

{

eval(JScript);

}

</SCRIPT>

wysiwyg in atlas

Has anyone found a wysiwyg editor that will work inside an update panel yet?The FCKEditor (http://www.fckeditor.net/) seems to work. Though its not the fastest loading.

newbie2006:

The FCKEditor (http://www.fckeditor.net/) seems to work. Though its not the fastest loading.

Hy!

I'm developing an Chat engine based on Atlas and I'm using FCK editor. I can't change the properties of FCKeditor inside the UpdatePanel. I want to clean the Message after Send Button Click. The code is the follow:

protected void Send_Click(object sender, EventArgs e){// Update Chat Panel ... //Clean up the editor FCKeditor1.Value ="";}

And the code in the ASPX is:

<atlas:UpdatePanelID="panelMessage"runat="server"Mode="Conditional"><ContentTemplate><FCKeditorV2:FCKeditorid="FCKeditor1"runat="server"/><asp:ButtonID="Send"runat="server"Text="Send"OnClick="Send_Click"/></ContentTemplate></atlas:UpdatePanel>


When I press the Send button the message is updated in the Chat, but the message from the editor don't desapear, only when I refresh the browser.

Anyone know one solution for this?

Thanks.

Paulo Alves.


Now I find the solution. First there is some incompatibilty with my CSS and the Atlas JS, so I replace with Server Side Label. The other was the property of UpdatePanel="Conditional", where I need to put an triger to work:

<atlas:UpdatePanel runat="server" ID="UpdatePanelMsg" Mode="Conditional"><Triggers> <atlas:ControlEventTrigger ControlID="Send" EventName="Click" /></Triggers><ContentTemplate><FCKeditorV2:FCKeditor id="FCKeditor1" runat="server" /></ContentTemplate></atlas:UpdatePanel> <asp:Button ID="Send" runat="server" Text="Send" OnClick="Send_Click" CausesValidation="False" />

The Mode="always" is not a good option because it post the UpdatePanel every 2 sec fired by Triger of Chat panel refresh.

The FCK is a little bit slow for this purpose, I' m tring to find another option like the FreeTextBox or just a TextArea.

Best regards,

Paulo Alves.



Hellow.,

Sorry for direct contact.But i want to ask u a query .Its argent to be in work.My task is

Test and evaluate the FCKeditor.NET control.(FCKEditor in SketchControl).

But i not understand why FCK editor require.Still i try 1 example send u code -->

<%@. Page Language="C#" AutoEventWireup="false" ValidateRequest="false" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@. Register TagPrefix="FCKeditorV2" Namespace="FredCK.FCKeditorV2" Assembly="FredCK.FCKeditorV2" %>

<html>

<head>

<title>FCKeditor - Sample</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

</head>

<body>

<form id="Form1" runat="server">

<FCKeditorV2:FCKeditor id="FCKeditor1" BasePath="/FCKeditor/" runat="server"></FCKeditorV2:FCKeditor>

<br>

<input id="Submit1" type="submit" value="Submit" runat="server">

</form>

</body>

</html>

But Give error like->server error HTTP Error 404 - Not Found.
pls tell what to do ...