Showing posts with label form. Show all posts
Showing posts with label form. Show all posts

Wednesday, March 28, 2012

UpdateProgress taking up space

I've placed an UpdateProgress control on my page. But it's taking up space on the form when not displayed. Is there a way to make it so that when it's not showing it won't take up any space on the page?

Never mind. I have so many panels, tables and other controls, that it realy makes it difficult to identify any problems. The UpdateProgress wasn't the issue.

UpdateProgressControl/UpdatePanel timeout

I have a main ASP.NET 2.0 web form (C# code-behind) that has an "inbox" that displays records from a database. The main web form has a AspTimer control and an UpdatePanel control that are used in concert to refresh the inbox every 2 minutes (120000ms) triggered by the timers Tick event. However, when a user creates a new record using another web form I am triggering an async refresh of the inbox (after the record is saved) by calling a javascript function (via ModalPopupExtender OnOkScript value) that detects the presence of a hidden button on the main form and firing it's click event which is handled as an asp:AsyncPostbackTrigger for the main web forms update panel. Everything works as designed, but from time to time after the remote page triggered refresh occurs the next timer refresh (Tick event) or other user initiated event (e.g. gridview row select, sort) will hang and result in an "Sys.WebForms.PageRequestManager TimeoutException: The Server request timed out."error. I am not sure if the remote page triggered refresh is confusing the AspTimer somehow or it is causing a collision of some sorts but any thoughts on the matter would be much appreciated.

Further details/update: Once I get the "Sys.WebForms.PageRequestManagerTimeoutException" error, I can consistentely get it to occur by clicking a button that triggers an async postback. It's as if the session has lost it's connection (note that this happens regardless if I am running against my local development machine (XP/IIS51) or our test server (2003/IIS6)). The very weird thing that is befuddling me is that if I use fiddler to watch the traffic to see what is going on it (the connection) will be magically restored and everything works fine again. There are no server side errors being thrown and JavaScript console in (NS/FireFox) does not show anything that would point me to a resolution.


Eureka!!! I figured out the problem. I have JavaScript methods that are called by my child forms when a user is clicking the "Close/Cancel" button that verify there are no unsaved changes before closing otherwise user is prompted to verify that they want to discard changes or not. If they confirmed that they wanted to close the web form I was simply calling window.close() but was not returning any value from the function which I think was a problem because the Close/Cancel button is located within the update panel (because the image changes depending on the scope of the form (e.g. new or view)) and thus despite closing the window I think the AJAX event lifecycle was being initiated but terminated abnormally because of the form closing. I added a "return false;" in my finally clause for all the functions that are used in the closing of a child web form and lo and behold my parent form no longer breaks (see example function below - added statement is bolded). I hope this solution also works for anyone else having a similar problem:

// Function Name: CloseVisitLog
// Function Purpose: Close the visit log form.
// Author: Michael Jensen
function CloseVisitLog(scope)
{
// put function within try-catch-finally block
try
{
// debug statement - set debug = true to view
if (debug) alert(">>Entered JavaScript:CloseVisitLog");

// declare local variables
var unsavedChanges = GetUnsavedChangesFlag();

if(scope == "new")
{
// make sure the user really wants to cancel
if (confirm("Are you sure you want to cancel creation of this visit log entry?"))
{
// close the window
window.close();
}
else
{
return false;
}
}
else if(scope == "view")
{
// if there are unsaved changes make sure the user really
// wants to close
if(unsavedChanges == "true")
{
if (confirm("There are unsaved changes, are you sure you want to close?"))
{
// close the window
window.close();
}
else
{
return false;
}
}
else
{
// close the window
window.close();
}
}
}
catch(ex)
{
var msg = "JavaScript:CloseVisitLog failed. ";
alert(msg + ex.messsage);
}
finally
{
// debug statement = set debug = true to view
if (debug) alert("<<Exiting JavaScript:CloseVisitLog");
// return false to prevent postback when window is closing
// otherwise parent form AJAX will break
return false;
}
}

Monday, March 26, 2012

Updating a UpdatePanel from another form?

This may be a silly question, but since I'm a total newbie I have to ask.

If I have say 5 different UpdatePanels on a form and if I from the same form open another form (window.open('anotherform.aspx...')) for data entry is it possible to update one of the UpdatePanels on the main form? Or, to the triggers all have to be situated at the same form as the UpdatePanel?

Any help is apreciated!

Instead of window.open and design a new page for popup, you can design using modalpopupextender and you can refresh any panels from the same page.

Updating a Tree Control with Ajax

I'm new to Ajax so forgive me if this is an obvious question. I have a Tree control that's populated when a form loads. It has 4 levels of nodes. When one clicks on the lowest level (the leaves) then associated data populates controls to the right of the tree view.

There has to be the ability to delete a leaf. When this is done, might the Ajax update control be used to remove the leaf from the tree, yet keep the tree positioned in the same place?

An unrelated question: Is there an ASP.Net 2.0 web control that acts like a resizable panel similar to what's available with WinForms? This sort of thing exists on MSDN: http://msdn2.microsoft.com/en-us/library/ms229335.aspx (ie. the panel on the left)

Robert W.


Hi,rmdw

What you meant "keep the tree positioned in the same place"?

I'm sorry for that I cann't understand your question.Can you provide more information?


Suppose you had a tree that looked like this:

+ A

+ B

+ C


Now suppose you open up the "B" node to reveal this:

+ A

- B

- B1

- B2

- B3

+ C

Now suppose the user wants to delete leaf "B2". What I would like is for the tree to be redrawn (refreshed) with B2 gone but still showing the user the same portion of the tree. Obviously for such a small example it probably always will be shown but imagine there were 100 parent nodes and multiple levels.

Robert


Ha Ha, I see, you wanna keep the tree like this:

+ A

- B

- B1

- B3

+ C

after you deleted leaf "B2".

But it show you this:

+ A

+ B

+ C

because the updatepanel refreshed.

I advise you using webservice or webmathod to achieve it instead using updatepanel.

Sample:

Default.aspx:

<%@. Page Language="C#" %>

<!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 id="Head1" runat="server">
<title>Untitled Page</title>

<script type="text/javascript">
// This function calls the Web Service method.
function EchoUserInput()
{
var echoElem = document.getElementById("WhichLeafToDelete");
WebService.DeletedLeaf(echoElem.value,SucceededCallback);
}
// This is the callback function that processes the Web Service return value.
function SucceededCallback(result)
{
//Do something to change the html of the tree to delete the leaf.
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="WebService.asmx" />
</Services>
</asp:ScriptManager>
<div>
<h2>
Simple Web Service</h2>
<p>
Calling a simple service that echoes the user's input and returns the current server
time.</p>
<input id="WhichLeafToDelete" type="text" />
<input id="EchoButton" type="button" value="Echo" onclick="EchoUserInput()" />
</div>
</form>
<hr />
<div>
<span id="Results"></span>
</div>
</body>
</html>

WebService.asmx:

<%@. WebService Language="C#" Class="WebService" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class WebService : System.Web.Services.WebService
{
[WebMethod]
public string DeletedLeaf (String input)
{
//Do something to delete the leaf in the database.
}
}

For more help, You can see thesetutorials:
http://ajax.asp.net/docs/tutorials/ExposingWebServicesToAJAXTutorial.aspx.
http://ajax.asp.net/docs/tutorials/ConsumingWebServicesWithAJAXTutorial.aspx

Let me know if you need more info.


Jin-Yu Yin:

I'm a bit confused. The actual display of the tree is a local matter, isn't it? As such, isn't it superfluous about whether to use a web service or code on the page?

What about the Ajax Update Panel wouldn't solve the problem I'm trying to solve?

Robert



Hi, Robert

If you don't need to do something at the server-side, e.g. deleting the leaf in the database, I mean that, If you just delete something at the client-side,you don't need to use a web service or code on the page, just use JavaScript to delete it. it's ok.

If you use an updatepanel to do this, it'll show you this:

+ A

+ B

+ C

because the updatepanel refreshed. It cann't remember what you had did before the postback

Updating an Update Panel on a page from Javascript

Hi All,

I am trying to update an update panel in a webform from Javascript. Form the documentation I think this might be possible using the Sys.Webforms.PageRequestManager but I have not been able to achieve this so far.

Any help would be greatful.

Hamlet

Hi Hamlet !

I been having the same wish ! After a lot of googeling the only way I found is to put an invisible button in a updatepanel and then raise it's postbackevent by registrering it's postbackevent in the scripthandler. Using the

$get('<%= YourControl.ClientID %>').click();

didn't work in FireFox and I supspect - but don't know for sure - not in ie7 ! One thing I wasted alot of time on was that the ValidateEventError but that was because I supplied an argument when registrering the clientscript in the scripthandler !

This feels like an uggly hack to accomplish what we want - but I didn't find any other way !

/MC24


I have been using

javascript:__doPostBack('__Page', 'some data' ) from the client.

This worked fine in the earlier release, but Beta 2.0 broke it because it started doing full postbacks instead of partial ones.

Evan


You can use the extender control I build.

http://daron.yondem.com

updating form updatepanel to updatepanel or one to many updatepanel

Hi all,

i have two updatepanels.

<updA>

<uc1 ..ascx> [...Reload this control or updating this panel ]

</updA>

<updB>

<uc2 ..ascx> [...onclick event ]

</updB>

i hope you anyone can solve this..

thanks

pkay

I am not sure what is your question. Can you please clarify? Thanks


When an updatePanel is updated, all the other updatePanels on the page also are updated.

This means that both <updA> and <updB> will be updated if you update one of them.

To avoid this, you can play with the "updateMode" updatePanel's property. This property is set to "always" by default but you can change it to "conditionnal" and then choose by yourself when your update panel has to be updated.


Hope it helps


hi kalahaine,

i got it. thanks for solution.

pkay


No problemSmile

Do not forget to mark your topic as answered.


hi all,

This is an updatepanel updating to other updatepanel: here my correct solution :

--updatepanel one

<asp:UpdatePanelrunat="server"ID="AAAupdatepanel"UpdateMode="Conditional">

<ContentTemplate>

<asp:UpdateProgressID="UpdateProgress2"runat="server"AssociatedUpdatePanelID="AAAupdatepanel">

<ProgressTemplate>

<imgsrc="images/loading-gif-sample-2.gif"alt=""/>

Loading .....

</ProgressTemplate>

</asp:UpdateProgress>

<uc3:AAAControlID="AAAControl1"runat="server"/>

</ContentTemplate>

</asp:UpdatePanel>

--updatepanel two

<asp:UpdatePanelrunat="server"ID="BBBupdatepanel"UpdateMode="Conditional">

<ContentTemplate>

<asp:UpdateProgressID="UpdateProgress2"runat="server"AssociatedUpdatePanelID="BBBupdatepanel">

<ProgressTemplate>

<imgsrc="images/loading-gif-sample-2.gif"alt=""/>

Loading .....

</ProgressTemplate>

</asp:UpdateProgress>

<uc3:BBBControlID="BBBControl1"runat="server"/>

</ContentTemplate>

</asp:UpdatePanel>

--updatepanel three

<asp:UpdatePanelrunat="server"ID="CCCupdatepanel"UpdateMode="Conditional">

<ContentTemplate>

<asp:UpdateProgressID="UpdateProgress2"runat="server"AssociatedUpdatePanelID="CCCupdatepanel">

<ProgressTemplate>

<imgsrc="images/loading-gif-sample-2.gif"alt=""/>

Loading .....

</ProgressTemplate>

</asp:UpdateProgress>

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

</ContentTemplate>

</asp:UpdatePanel>

-------here is code behind--------

ProtectedSub Button1_Click1(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles Button1.Click

Me.AAAupdatepanel.Update()

Me.BBBupdatepanel.Update()

EndSub

Updating the user interface on a web form BEFORE UpdatePanel finishes

Hello

does anyone know if it is possible to dynamically alter the contents of a control (e.g. a label) so that it updates BEFORE the UpdatePanel finishes its asynchronous operation? An example might be for a progress bar. I have a process which takes up to 5 minutes, but which generates an event as it progresses. I want to update a control each time this event gets triggered, but because I update the user interface in the async part, it doesnt do anything until it has completed.

For example imagine I have a button with an OnClick event inside an UpdatePanel, alongside a label in the UpdatePanel.
WHen I click the button, if I loop through one hundred objects, andwish to update the contents of the label as I do this (i.e. 'On itemnumber: x'), how is this done?

Thanks

Tom.

Have you tried calling the .Update() method on your update panel in the loop? That may or may not work.


Take a look at this:http://encosia.com/2007/10/03/easy-incremental-status-updates-for-long-requests/


I did try this within the asyn call, but nothing happens. I am assuming that whatever happens is built into a long string of javascript or suchlike which is not executed until completion.

That's right. Output buffering prevents anything along those lines from working. Using an iframe lets you work more interactively.

Wednesday, March 21, 2012

Urgent Help: Update Panel and Form Templates? - Need to finish this week ends.

Hello

I am new to ASP .NET so just wanted to confirm.

I actually tried a lot in regular asp .net website to update my textboxes when selecting a value from dropdown list.

but no luck.

so is update panel better in these cases. and does this work without having to code..

because i have two weeks left to this one page. and i was stuck on updating values of text boxes, checkboxes fields when updating ddl. i have ddl inside the formview template.

so when using update pannel: ddl will be outside the formview template??

how does it work basically??

please help asap.

thanks a lot all.

looking forward for reply.

surbhi

Have you use the OnSelectedIndexChanged event of the DDL yet ? Make sure you set the DDL AutoPostBack = true

No. I dont know how to use that event.

I am new and using VB for coding ..

Dont know how to use C#..

How do i use findcontrol statements in vb?

help asap. i have to finish it this week..

Thanks

Surbhi


You would probably benefit the most by looking at tutorials online then waiting for people to reply. Questions about events and c# or vb.net syntax can easily be answered by searching.

Well.. Ofcourse I have been looking online as well.

Not finding enough information on how to use this event..

Meanwhile here is my vb code for ItemUpdating event..

I dont know where I am making mistake. Correct me.. and I am using Formview, Sql DataSource.

and DropDownList which has project numbers. I just want to display new values when I select a different value in DDL. I have AutoPostBack=true and AppendDataBound =True..

Here is the code:

Private

Sub FormView1_ItemUpdating(ByVal senderAs Object,ByVal eAs FormViewUpdateEventArgs)'Dim ProjectNameTextBox As TextBox = FindControl("ProjectName")'Dim FormView1 As FormView = CType(sender, FormView)Dim rowViewAs DataRowView = CType(FormView1.DataItem, DataRowView)Dim rowAs FormViewRow = FormView1.RowDim ProjectNameTextBoxAs TextBox = CType(row.FindControl("ProjectName"), TextBox)

e.NewValues(

"ProjectName") = CType(row.FindControl("ProjectName"), TextBox)

ProjectNameTextBox.Text = rowView(

"ProjectName").ToString()

end sub

Urgent: Atlas breaking <asp:button> postback

On my form I have an <asp:ImageButton id='Calculate'> which calls a webservice to perform a calculation then populate a textbox.

I also have an <asp:button id='Save' test='Save'> which performs the form submit.

The Save button works correctly posting back to the server unles the Calculate button is pressed. If the Calculate button is pressed the asynchronous call for the calculation works, but afterwards the Save button will no longer postback.

I created <a href="http://links.10026.com/?link=javascript:__doPostBack('Save','')">Save it</a>. This works before the Calculate is pressed and fails after Calculate is pressed (exactly like the Save button).

Any ideas? I have a client I have to show this to in the morning.

thanks.....mac

hello.

not without seeing a small sample that reproduces the error...