Showing posts with label updating. Show all posts
Showing posts with label updating. Show all posts

Wednesday, March 28, 2012

AJAX update without updating viewstate

Hey,

Does someone know if it's possible to update contents on the webform without sending the viewstate and other useless stuff?

Sometimes I update only one value of a textbox. An update of the viewstate is not necessary. This is a problem; sending the viewstate again makes the reponse to slow . (it takes >500ms, and that is too slow)

Withajaxpro the response takes ~40ms. But I don't want to use both frameworks (I use ajax.asp already for the ajaxtoolkit)

I tried:

RegisterDataItem without an updatepanel update.RegisterClientScriptBlock with an updatepanel update


ps. I don't want to disable or reduce the viewstate, that isn't possible.

Hi

You can use page methods. No ViewState is transferred when invoking page method. Then update your TextBoxes with JavaScript.

Seehttp://www.singingeels.com/Articles/Using_Page_Methods_in_ASPNET_AJAX.aspx

-yuriy
http://couldbedone.blogspot.com


AH, that looks interesting. It look likes the ajaxpro method.Smile

I will post later some comparison times.

AJAX update panel updating all panels!

Hey there, I have 2 updated panels on a page update panel1 and update panel2.

One is triggerd by a list box and the other is triggered by an image button,, the only problem is although each trigger is assigned to their respective list boxes, whenever a trigger is activated it refreshes both update panels, which is not what I want.

This is my update panel refreshed by the image button

<asp:UpdatePanelID="UpdatePanel2"runat="server"><ContentTemplate><TABLEid="Table6"style="WIDTH: 208px; HEIGHT: 248px"cellSpacing="1"cellPadding="1"width="208"border="0"><TR><TDstyle="HEIGHT: 197px; width: 206px;"vAlign="top"align="center"><BR><asp:listboxid="ListBox1"runat="server"Width="143px"Font-Names="Arial"AutoPostBack="True"Height="232px"></asp:listbox></TD></TR></TABLE></ContentTemplate><Triggers><asp:asyncPostBackTriggerControlID="SearchButton"EventName="Click"/></Triggers></asp:UpdatePanel>

Any thoughts on this?

Thanks in advance

You need to set the UpdateMode on the UpdatePanels to "Conditional". By default it is set to "Always" which means it will be updated on any postback.

Saturday, March 24, 2012

Ajax timer update does not work when it updates a text box with some special characters

The Ajax time seems to have some trouble updating a panel that contains a text box with some special characters. I managed to replicate the problem using a very simple page that is inlcuded below. The problem is that the second update causes an error 500 from the development server of Visual Studio.

The page just has an update panel with a single multi-line text box. The code for the timer update assignes the text box the string "<br>\n".

Does anyone know how to solve this problem?

The Page is:

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.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:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox> <asp:Timer ID="Timer1" runat="server" Interval="5000" OnTick="Timer1_Tick"> </asp:Timer> </ContentTemplate> </asp:UpdatePanel> </form></body></html>
The code for the update is:

public partialclass _Default : System.Web.UI.Page {protected void Page_Load(object sender, EventArgs e) { }protected void Timer1_Tick(object sender, EventArgs e) { TextBox1.Text = "<br>\n;"; }}

Regards,

Ivan

By the way, I do realize that the problem is with special characters that trigger the ASP.NET security validations. Changing the text in the Text Box to HTML encoded is not an option, because in this text box the user should be entering and editing HTML code.

Ajax Timer Tick updating GridView in an unwanted way

I display an empty data set in my gridview by manipulating the gridview to show the headers and a row displaying only No Records Found. Here is the code for that:

if (EQTable.DefaultView.Count == 0)//if filtered data is empty, make sure to show header { EQTable.Rows.Clear(); EQTable.Rows.Add(EQTable.NewRow()); TimeStampGridView.DataSource = EQTable; TimeStampGridView.DataBind();int colNum = TimeStampGridView.Columns.Count; TimeStampGridView.Rows[0].Cells.Clear(); TimeStampGridView.Rows[0].Cells.Add(new TableCell()); TimeStampGridView.Rows[0].Cells[0].ColumnSpan = colNum; TimeStampGridView.Rows[0].Cells[0].Text ="No Records Found."; }

When the timer Tick event goes off is should only check if new data is present by checking the last write time to an xml file. If no new data is present is just returns, On the return, it updates the gridview to show all the cells of the empty row and erases the No Records Found text. Here is the code:

protected void UpdateTimer_Tick(object sender, EventArgs e) {string oldTime = Lb_LastRun.Text;string newTime = GetLastRunTime();if (oldTime != newTime)//doesn't go in for an empty row, but messes up cells of gridview { Lb_LastRun.Text = newTime; EnableExtractorCols(); LoadGrid(); DisableExtractorCols(); } }

Anyone know what I'm doing wrong here? Thanks for the help!!!

I got around this problem by changing the timer tick code:

protected void UpdateTimer_Tick(object sender, EventArgs e)
{
string oldTime = Lb_LastRun.Text;
string newTime = GetLastRunTime();
if (oldTime != newTime)
{
Lb_LastRun.Text = newTime;
EnableExtractorCols();
LoadGrid();
DisableExtractorCols();
}
if (TimeStampGridView.Rows.Count > 0)
{
Label EQLabel = (Label)TimeStampGridView.Rows[0].FindControl("Label1");
if (EQLabel.Text == "")//check for empty row, this is important for displaying headers only on a status filter
{
int colNum = TimeStampGridView.Columns.Count;
TimeStampGridView.Rows[0].Cells.Clear();
TimeStampGridView.Rows[0].Cells.Add(new TableCell());
TimeStampGridView.Rows[0].Cells[0].ColumnSpan = colNum;
TimeStampGridView.Rows[0].Cells[0].Text = "No Equipment Found.";
}
}
}

is there another way to stop this updating?

AJAX Timer bug when it updates a panel containing a single Text Box with the characters "&

The Ajax timer seems to have a problem updating a panel what contains a text box that has the characters "<br>\n". Attached is the source code for a very simple page a single multi-line text box where the timer code-behind just assigns the textbox the string "<br>\n". When run, the second update will cause an 500 error from the server.

This error does not happen when the text is something else, say "Hello World".

I assume that the problem is that the sequence "<br>\n" in the text box causes the timer Java Script to break somehow. Anyone knows oh to solve this problem? I am using Ajax 1.0 and the Visual Studio Development Server.

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.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:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox> <asp:Timer ID="Timer1" runat="server" Interval="5000" OnTick="Timer1_Tick"> </asp:Timer> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

The code behind for the time update is:

protected void Timer1_Tick(object sender, EventArgs e) { TextBox1.Text ="<br>\n;"; }

Ivan.

I am sorry, the code for the post got mangled but the editor. The code behind for the time update should be:

public partialclass _Default : System.Web.UI.Page {protected void Page_Load(object sender, EventArgs e) { }protected void Timer1_Tick(object sender, EventArgs e) { TextBox1.Text = "<br>\n"; }}

Apparently, the string <br> is detected as a potentially harmfull string. One solution is to HTML encode the string. However, I do need to display the string <br> in the text box, not <br>. The user must be able to edit the HTML code that we will use.

Ivan.


Apparently, the string <br> is detected as a potentially harmfull string. One solution is to HTML encode the string. However, I do need to display the string <br> in the text box, not <br>. The user must be able to edit the HTML code that we will use.

Ivan.