Showing posts with label following. Show all posts
Showing posts with label following. Show all posts

Wednesday, March 28, 2012

UpdateProgress subcontrols modification

I have the following code in place on my page. What I would like to do is to dynamically set the
lblProcessingRequest Text property during page load, because the site have some local language
customization build in.

I have tried a lot of things, but can't manage to get it to work.

<asp:UpdateProgressID="UpdateProgress"runat="server"AssociatedUpdatePanelID="UpdatePanel"DisplayAfter="100"DynamicLayout="False">

<ProgressTemplate><imgsrc="images/ProcessAnimation.gif"align="absMiddle"> <asp:labelID="lblProcessingRequest"Text="Processing request..."runat="server"Font-Bold="True"></asp:label></ProgressTemplate></asp:UpdateProgress>

The content is a template, so you can't immediately get at the controls like you normally can.

The template is instantiated during PreRender, so you should be able to hook into the Page's PreRenderComplete event, then do a FindControl on the update progress to get to the label:

private void PreRenderCompleteHandler(object sender, EventArgs args) {
Label l = (Label) UpdateProgress.FindControl("lblProcessingRequest");
l.Text = ""; // some localized text
}

Whenever you do this sort of thing, please, please be wary of ViewState. You should disable ViewState on that label, or you will be persisting viewstate data that doesn't need to be. If you are doing this for many labels on the page it could really add up to a problem. Read my (lengthy) article on ViewState, linked in my signature, if you have time.


ProtectedSub Page_PreRender(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.PreRenderTryCType(UpdateProgress.FindControl("lblProcessingRequest"), Label).Text ="Some local Text"
Catch exAs Exception
EndTryEndSub

Sorry to say that this doesn't work. The control is not found. Couldn't this be because the label only is visible during the UpdateProgress, and at all
other time is hidden? I even tried hooking the control in the UpdateProgress PreRender method, but that didn't work eighter...


Ok, was I litte to hasty here.

Protected

Sub Page_PreRenderComplete(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.PreRenderComplete

Hooking into the PreRenderComplete works fine!

UpdateProgress.FindControl() does not work in beta 2

We have upgraded to beta 2 and the following code (which worked under beta 1) does not work.

The FindControl() method is returning null and the UpdateProgress.Controls.Count property is showing as 0.

Is this a problem in beta 2? Can anyone help with a solution?

<asp:UpdateProgressID="atlasProgress"runat="server">

<ProgressTemplate><asp:LabelID="messageLabel"runat="server"Text="Original Message"></asp:Label></ProgressTemplate></asp:UpdateProgress>

Label updateLabel = (Label)this.atlasProgress.FindControl("messageLabel");if (!(updateLabel ==null))

{

updateLabel.Text = "New Message";

}

I tested your codes and found the same problems as yours.asp:UpdateProgress.FindControl can not work in Ajax Beta 2.Maybe this is caused by Ajax Beta 2 framework.

Here are some explanations from ASP.NET Team for your reference.

Summary:

Due to a known issue with ASP.NET AJAX Beta 1, you may find that Extender controls no longer work with templated controls such as GridView or FormView. This issue will be addressed in the next release of ASP.NET AJAX.

Background:

The ScriptManager component on your ASPX page is responsible for rendering out the client script (JavaScript) that creates the client side components. The ScriptManager walks the list of components that need these hookups during it's PreRender phase of the page lifecycle. Unfortunately, templated controls often create their inner control heirarchies during PreRender as well. Therefore, since the ScriptManager appears earlier in the page than the templated control, the extenders have not been created yet, and the hookups don't happen.

Workaround:

Fortuantely, for the common case, there is a simple workaround. You simply need to force control generation earlier in the page lifecycle. The simplest way to do this is to call DataBind method or Controls property from the Page_Load.

protected void Page_Load(object sender, EventArgs e)

{

GridView1.DataBind(); // for databound controls

object o = Login1.Controls; // for templated controls

}

Caveat:

This doesn't work for templated controls that make changes to their tree, such as a GridView with an EditItemTemplate in it. If you have that scenario, unfortunately, you'll need to wait for the next release of ASP.NET AJAX Beta 1 to enable it.

Wish the above can help you.


Hi I'm having the same problem with the AjaxControlToolkit

Dim temp_lkExportedCSV As HyperLink = CType(UpdateProgress1.FindControl("lkExportedCSV"), HyperLink)
Dim temp_lblPercent As Label = CType(UpdateProgress1.FindControl("lblPercent"), Label)
Dim temp_lblStatus As Label = CType(UpdateProgress1.FindControl("lblStatus"), Label)

temp_lkExportedCSV.Enabled = False | And here I get an exception, because no control was found.


And I called the Controls method in the page load just like it was explained bu tit still didn't work.

Dim o As Object = Me.UpdateProgress1.Controls

Am I doing something wrong?


Maybe it's the nature of the UpdateProgress that's looks invisible until the associated UpdatePanel is updating.


This is a known issue with the UpdateProgress control. It gets added very late in the page's lifecycle. Move your code to the Page_PreRenderComplete event or Page_Unload event. Page_Load is too early.

Monday, March 26, 2012

Updating a website with data from an asynchronously called Webservice

Hi!

I wrote the following code to update a label on my aspx-page with data retrieved by an asynchronously called Webservice.

Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.LoadIf Not Page.IsPostBackThen Dim wsAs localhost.WebServiceTest =New localhost.WebServiceTestDim ResultAs IAsyncResult = ws.Beginmessages(AddressOf renderResult, ws)End If End Sub Private Sub renderResult(ByVal ResultAs IAsyncResult)Dim wsAs localhost.WebServiceTest =CType(Result.AsyncState, localhost.WebServiceTest) Label1.Text = ws.Endmessages(Result)End Sub

The problem is that the Label (which is surrounded by an Updatepanel) does not get updated with the value returned by the Webservice although "renderResult" is executed correctly. (Maybe the problem is that the asynchronous function is called in a different thread on the webserver?)

Do you have any ideas or solutions to solve this issue?

Thank you

No suggestions?


Try doing your asynchronous webservice calls from the client-side rather than from the server.

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

http://www.asp.net/AJAX/Documentation/Live/tutorials/ASPNETAJAXWebServicesTutorials.aspx


As DisturbedBuddha points out, you would probably want to do this sort of thing client side (remember the runat=server thing).

But, if youreally want to do this server side, my first question would be - is the updatepanel inside a form?

Cheers

Martin


Thank you for your help.

Calling the webservice client-side worked!

Saturday, March 24, 2012

upload doesnt work inside Update Panel.

I put following code inside an UpdatePanel. The upload control doesn't work.
If I remove the updatepanel, the it is OK.

<input id="fileUpload" type="file" size="60" name="fileUpload" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload"></asp:Button>You're right, this is a known issue. Do a search.
Hi~ One walk around to this is to put an iframe in update panel and do the upload in the page held in that iframe~

I'm sorry, but has anybody found the solution for this problem?


File uplod is not suposed to work within update pannel.
Solution how to overcome this behavior:
http://msmvps.com/blogs/luisabreu/archive/2006/12/14/uploading-files-without-a-full-postback.aspx

Maybe this helps...

Or add a button beside file upload control with name "Upload file" and add postback trigger to update pannel for that button click event. File will be uploaded when this button is pressed but page then will do normal postback

Mindaugas