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 it always return to the original place?

<asp:ScriptManager ID="ScriptManager1" runat="server" />
<cc1:DragPanelExtender ID="DragPanelExtender1" runat="server" TargetControlID="Panel1"
DragHandleID="Panel2">
</cc1:DragPanelExtender>
<asp:Panel ID="Panel1" runat="server" Height="300" Width="200">
<asp:Panel ID="Panel2" runat="server" Height="25" Width="200" BackColor="Black">
</asp:Panel>
Test</asp:Panel>

I would like the Panel1 can be dragged and stay the place where I drop it.

How to do that?

I believe the body of the page has to have been assigned some sort of physical dimension:

http://forums.asp.net/p/1150327/1874846.aspx

See point #23 and Listing 6 of this article:

http://aspalliance.com/1450_Working_with_DragPanel_AJAX_Control.4


Many thanks for replying.

Why javascript function can not be found in Firefox with a AJAX page?

Following page works fine with IE. When click on Html button, the javascript function is called and works fine.

But when run the same page in Firefox, it reported that the error as below:

myFunction is not defined

onclick(click clientX=0, clientY=0)

What's the possible reason and how to solve it?

--the page code:the page also include some Ajax toolkit and the code for that is omitted.

<%@dotnet.itags.org. Page Language="vb" AutoEventWireup="false" Codebehind="workshop.aspx.vb" Inherits="my.workshop" %>
<!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>Workshop Registeration</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<link href="http://links.10026.com/?link=StyleSheet1.css" rel="stylesheet" type="text/css" />
<script type="text/jscript" language="javascript" >

function reset(){
document.workshop.reset();
}

function myFunction() {
alert("test");
}

</script
</head>
<body class="page">
<form id="workshop" runat="server">
<asp:ScriptManager runat="server" EnableScriptGlobalization="true" ID="MasterScriptManager"
EnablePartialRendering="true" ScriptMode="Release" AsyncPostBackTimeout="72000">
</asp:ScriptManager>
<div>
<table border="1" cellpadding="0" cellspacing="0">
<tr class="namearea">
<td align="center" class="dataarea">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="right" style="width: 50%">
<input class="jsbutton" onclick="javascript:myFunction();" type="button"
value="Button1" />
</td>
<td align="left" style="width: 50%; background-color: White;">
<br />
<asp:PlaceHolder ID="plcmyHolder" runat="server"></asp:PlaceHolder>
<br />
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

Change the script type from text/jscript to text/javascript and it'll work.

why Javascript doesnt work properly in updatepanel?

i wanna my gridview to change into editrow model by click any space in the row , so i wrote in the aspx page:

.....
<script type="text/javascript">
function ClickEvent(cId)
{
var id=cId;
document.getElementById("rowid").value=id;
document.getElementById("btnBindData").click();
}
</script>
.....

<asp:LinkButton ID="btnBindData" runat="server" OnClick="btnBindData_Click" Width="0px" style="width:0px; height:0px"></asp:LinkButton>
<input type="hidden" id="rowid" runat="server" /> //send clicked row index to editindex property

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="userName" HeaderText="userName" SortExpression="userName" />
<asp:BoundField DataField="userPassword" HeaderText="userPassword" SortExpression="userPassword" />
</Columns>
</asp:GridView>

In the aspx.cs file i wrote:

.......

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#dfe345'");

e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

e.Row.Attributes["style"] = "Cursor:hand";

e.Row.Attributes.Add("OnClick", "ClickEvent('" + e.Row.RowIndex + "')");

}
}

......

protected void btnBindData_Click(object sender, EventArgs e)
{
GridView1.EditIndex=Convert.Int32(this.rowid.Value);

.....

GridView1.DataBind();
}

It works well without UpdatePanel ,but when put the GridView in the UpdatePanel ,when I click the row, the GridView got disappeared.

Replace asp:LinkButton with asp:Button. If you want you can sorround your button with a hidden div (to hide from the user). Also add UseSubmitBehavior="false" to the asp:Button.

For example:

<div style="display: none; line-height: 0pt;">
<asp:Button id="btnBindData" runat="server" OnClick="btnBindData_Click" UseSubmitBehavior="false" />
</div>

Why JSON?

Say, please, what was the main reason to use JSON object serializing in Atlas instead of SOAP? Easy deserializing? Or light weight? Or something else?

And will Atlas support SOAP in the future?

Thanks.

Pavel,

Easy deserializing is indeed a big part of it. The ability to just call JavaScript's 'eval' instead of having to reconstruct an object graph from an XML DOM makes JSON much easier to you. JSON is also a more concise format.

It is conceivable that Atlas will support SOAP in the future.

David


Thanks for quick answer.

Why Microsoft done this in Ajax

Hello,

Till the time i have heard that Microsoft is releasing the ASP.NET AJAX i am excited that i have to just copy the dll's of this ASP.NET AJAX into my webapplication becaz earlier i have used Atlas products dll in my application , in that i just cpoied the dll into the bin folder of my application and its working perfect.

But i can't understand the reason why Microsoft have removed this feature from his new release ASP.NET AJAX, they know this that many websites running on hosted servers and they d't have permission to install any software on that server still they have done this,

Can any one explain me why they have done this is there any reason for this, Is ASP.NET AJAX not working fine in the din folder or Wht?

Now with ASP.NET AJAX you dont need to copy the ajax framework dll into the bin directory as you used to do with ATLAS. When ASP.NET AJAX was installed, these dll's will be installed directly into the GAC and all most all the hosting providers might have done this already. You just need to re-configure your web.config file and also keep track of the changes from ATLAS to BETA to RC which can be found at

Converting Applications from "Atlas" CTP to ASP.NET AJAX RC
Converting Applications from ASP.NET AJAX Beta 2 to ASP.NET AJAX RC

Its not that ASP.NET AJAX is not working fine with the bin folder. With each and every release, there will be changes like adding new functionality, bug fixing etc..,

Thanks

Why mix live.com with ATLAS? or even pageflakes?

I am not sure if other people has the some question as I have. I am using ATLAS, and trying to find out what features are available. There are more features to come, but I need keep looking what are available since I don't want to deveope them if they are there ready for use.

But look on the ATLAS pages, often you will see pageflakes, live.com etc. They are good sites, they are using ATLAS. But the thing is they don't build with ATLAS only. So my question is what is the point to put them here, just let us admire the nice features they have but no way to build our site like thme?

hello.

well, i guess that is what you'll have to do with everything, ie, you'll allways have to expand/tweak it to fit your needs. seeing sites like those might give you new perspectives about what you can do with the platform.