Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Wednesday, March 28, 2012

updateprogress position in Firefox (urghh!)

Hi,

I have an updateprogress control that displays nicely in the middle of the screen, but only in IE.

The code is...

<

atlas:UpdateProgressid="loadingProgress"runat="server"><ProgressTemplate>

<divstyle="height:40px;width:250px;position:absolute;z-index:10000;left:expression((this.offsetParent.clientWidth/2)-(this.clientWidth/2)+this.offsetParent.scrollLeft);top:expression((this.offsetParent.clientHeight/2)-(this.clientHeight/2)+this.offsetParent.scrollTop+58); background-repeat: repeat-x; text-align: center; vertical-align: middle; border-right: black 1px solid; border-top: black 1px solid; border-left: black 1px solid; border-bottom: black 1px solid; background-image: url(Images/updateProgressBk.png);">

<

imgstyle="z-index: 109; left: 80px; position: absolute;top:22px"src="images/progressbar_microsoft.gif"/></div></ProgressTemplate></atlas:UpdateProgress> But in Firefox (dont like it myself but some users here use it), it positions on the top left of the screen.

Anyone know a fix, or does Firefox not know about "this.offsetParent.clientHeight" etc?

Thanks

Anyone know how to position the update progress control in the center of the page when viewing from Firefox?

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.

Updating a status label

I have a recently insalled the AJAX Beta 1 and I was wondering if it will enabled me to change a label multiple times in a sub... see the code below.

Protected Sub cmdSubmitUpload_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles cmdSubmitUpload.CliclblUploadStatus.Text ="Saving file on server..."'do the save herelblUploadStatus.Text ="Verifying file..."'call a routine that verifieslblUploadStatus.Text ="File verified."End Sub
I want to change the label and have the user see it change every time.  Is there a way to do this using AJAX?

Hello, the code that you write for an event handler will run on the server when the request is received, and the result of this is one and only one response that will update the page. If you want to provide this kind of feedback, you would need to write more client side code that executes each part of your process separately and can update the label before each step. You can seach msdn for a Whidbey feature called CallBacks that will allow you to do this, or you can make use of Atlas ability to call webservices from script.

Hope this helps,
Federico

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!

Updating an UpdatePanel only when certain item is clicked in Datalist

I have 2 UpdatePanels each with a Datalist in them. Here is my code:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DataList2" />
</Triggers>
<ContentTemplate>
<asp:DataList ID="DataList1" runat="server" DataSourceID="Ods1"BorderStyle="Solid" GridLines="Both" RepeatDirection="Horizontal">
<ItemTemplate>
<asp:ImageButton ID="ThumbImage1" runat="server"ImageUrl='<imagepath...>' />
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:DataList ID="DataList2" runat="server" RepeatColumns="4"DataSourceID="Ods2" BorderStyle="Solid" GridLines="Both"RepeatDirection="Horizontal" OnItemCommand="DataList2_ItemCommand"CellPadding="5">
<ItemTemplate>
<asp:ImageButton ID="ThumbImage2" runat="server"ImageUrl='<imagepath...>' CommandName="ThumbImage"CommandArgument='<passing the id...>' />
<br />
<asp:ImageButton ID="DeleteImage" runat="server"ImageUrl="images/delete.gif" CommandName="DeleteImage"CommandArgument='<passing the id...>' />
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>

and the code in DataList2_ItemCommand is as follows:

protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "DeleteImage")
{
//code to delete the image from database

...
this.DataList2.DataBind();
this.UpdatePanel2.Update();
}
else if (e.CommandName == "ThumbImage2")
{
//code to add the thumb image to the table attached to datalist1.
...
...
this.Datalist1.DataBind();
this.UpdatePanel1.Update();
}
}

As you can see in the above code, I want to update the UpdatePanel1 only when the imagebutton "ThumbImage2" is clicked and NOT when the imagebutton "DeleteImage" is clicked in Datalist2. But because Datalist2 is the cause of the AsyncPostBackTrigger for UpdatePanel1, it is updated when either one of the imagebuttons are clicked. Is there a way to change this?

Please help.

You don't want to set the datalist as the trigger, you want to set the individual ImageButtons as the triggers. Remove the triggers from UpdatePanel1, as well as the UpdateMode="Conditional".

<asp:UpdatePanelID="UpdatePanel1"runat="server">
<ContentTemplate>
...
</ContentTemplate>
</asp:UpdatePanel>

Then in the DataList2_ItemDatabound event, add the following:

ProtectedSub DataList2_ItemDataBound(ByVal senderAsObject,ByVal eAs System.Web.UI.WebControls.DataListItemEventArgs)Handles DataList2.ItemDataBound
Dim ibtnAs ImageButton =CType(e.Item.FindControl("ThumbImage2"), ImageButton)
Dim trggrAsNew AsyncPostBackTrigger
trggr.ControlID = ibtn.ClientID
trggr.EventName ="Click"
UpdatePanel1.Triggers.Add(trggr)
EndSub


In the ItemCommand event, I am executing some server side code for the imagebutton that was clicked in that specific row of datalist based on its id (which I retrieve using e.CommandArgument).

If I use the approach that you mentioned above, how do i retrieve the database id of the image clicked?

Thanks


DataList2.DataKeys.Item(e.Item.ItemIndex)


The solution you suggested works like a charm. I removed the datalist as the trigger & added the imagebutton as trigger in ItemDataBound event. Also, I still execute the server side code in ItemCommand event based on the which button clicked & everything works fine.

Thanks a ton.

Updating label in Master page from aspx page using Update panel

Hi,

I have master page that has label. Now aspx page that is using that master page has some code in update panel that save data in DB that will load by master page and update the label. problem is that code in update page can refresh master page to reload data to update label

My question is How I update the panel label when code on aspx page using update panel updates DB.

Thanks

Seehttp://www.asp.net/AJAX/Documentation/Live/tutorials/UsingUpdatePanelMasterPages.aspx

-Damien

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

Wednesday, March 21, 2012

Urgent AutocompleteExtender Does not work

Hello ,

I have aproblem with autocomplete extender in Vb website , it does not work at all never call the webservice

here is the code for the page

<asp:TextBox id="TxtITEM_NO" runat="server" CssClass="dbn_tb" Width="225px" autocomplete="off"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ID="AUTOCOMP" runat="server" ServicePath ="MESCService.asmx" ServiceMethod ="GetItemCompletionList"
MinimumPrefixLength="2" CompletionInterval="1000" EnableCaching="true" TargetControlID="TxtITEM_NO" CompletionSetCount="12" />

and this is the code inside MESCService.asmx

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Collections.Generic

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class MESCService
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Shared Function GetItemCompletionList(ByVal prefixText As String, ByVal count As Integer) As String()
If count = 0 Then count = 20
Dim x As New ikrima.DAL.DBAccess
Dim ds As New System.Data.DataSet
ds = x.ExecuteDataSet("select ITEM_ID FROM ITEM_MASTER ")
Dim items As List(Of String) = New List(Of String)

Dim words As Data.DataRow() = ds.Tables(0).Select("ITEM_ID LIKE '" + prefixText + "%'")
Dim num, i As Integer
num = IIf(words.Length < count, words.Length, count)
For i = 0 To num - 1
items.Add(words(i).Item("ITEM_ID").ToString)
Next
Return items.ToArray
End Function

End Class

can any one help me , why this is not work ,

hi ikrima,

Add the following attribute above your webservice class

[ScriptService]

Regards,


Replace this"<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _"line of yours with -----> <ScriptService()> _


Thanks for our replies

i replace my code and change it to <scriptservice()>_ but till now it does not work , and when try to trace my code i found that the autocompleteExtender does not call the webservice , when ever all other ajaxtoolkit is running well

so what is your suggession to solve this ?


HI Ikrima,

Why do you set the propertyautocomplete="off"> ??

Regards,


HI ,

if you rfer to the samplewebsite which is download with AjaxcontrolToolkit source , you will find in the Autocomplete sample they use it ,

actually i try to remove it also but nothing happend

Thanks


Move your MESCService.asmx to your ScriptManager

e.g.

<asp:ScriptManager runat="server" ID="ScriptManager1" EnablePartialRendering="true">
<services>
<asp:servicereference path="~/MESCService.asmx" />
</services>
</asp:ScriptManager>

Hope it works. For it works. For me it does.


Sad , still not working................

Even there is no query on server or any response/request from the page it just ignore it


Sad , still not working................

Even there is no query on server or any response/request from the page it just ignore it


hi i have the same problem in c#,so if u find any solution,please post it here

thanx


replace "<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _" with "<System.Web.Script.Services.ScriptService()> _"


Have you found a solution to your problem?

I found the solution, it seems that the Function name DOES matter. Here is my webservice code returning a generic string array:

Imports

System

Imports

System.Web

Imports

System.Collections

Imports

System.Web.Services

Imports

System.Web.Script.Services

Imports

System.Web.Services.Protocols

Imports

System.Data.SqlClient

<System.Web.Script.Services.ScriptService()> _

<WebService(Namespace:=

"http://tempuri.org/")> _

<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _

<

Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _

Public

Class WebServiceInherits System.Web.Services.WebService

<WebMethod()> _

<ScriptMethod()> _

PublicFunction GetCompletionList(ByVal prefixTextAsString,ByVal countAsInteger)AsString()Dim strArray(2)AsString

strArray(0) =

"abc"

strArray(1) =

"def"

strArray(2) =

"ghi"Return strArrayEndFunction

End

Class

Urgent: AutoCompleteExtender doesnt work/Updatepanel doesnt work

This is my code for the AutoCompleteExtender

<asp:textboxid="txtQuickSearch"runat="server"CssClass="inputText"style="width:145px; "></asp:textbox>

<atlas:AutoCompleteExtenderrunat="server"ID="acSearch">

<atlas:AutoCompletePropertiesTargetControlID="txtQuickSearch"Enabled="True"ServicePath="http://localhost/Sony.BusinessSuite.Web.UI/AtlasServices/MasterData.asmx"ServiceMethod="GetAllModels"minimumprefixlength="2"/></atlas:AutoCompleteExtender>

When i start typing fiddler shows:

#ResultHostURLBodyCachingContent-TypeUser-defined1401localhost

/Sony.BusinessSuite.Web.UI/AtlasServices/MasterData.asmx?mn=GetAllModels

4.431text/html

The same happens with an update panel...

basically i've been trying to use atlas things in the application we are working on here for about 3 weeks now... and up until now it has been very cumbersome and time consuming.

Hi,

Could you post the code for the method you are using in your webservice

Thanks


Hi,

you are getting a 401. I believe that it happens because you are trying to access a web service in another domain and this is not allowed in normal conditions. Please checkthis thread.

Here's the webservice code, thanks in advance to have a look...

[WebService(Namespace ="http://tempuri.org/")]

[WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]

[ToolboxItem(false)]

publicclassMasterdata :WebService

{

[WebMethod]

publicstring[] GetAllModels(string prefixText,int count)

{

ArrayList filteredList =newArrayList();

//Get the available product categories from the principal object.

Principal principal = (Principal)Context.User;

List<Category> myCategories = principal.Categories;

List<DKCategory> myDKCategories =newList<DKCategory>();

foreach (Category catin myCategories)

myDKCategories.Add(newDKCategory(cat.OID));

//Get the models from the masterdata service (limited to the users available categories).

Proxy.Pricing.Model.ModelService ModelSVC =new Proxy.Pricing.Model.ModelService();

List<Model> myModelsSVC = ModelSVC.GetModels(myDKCategories,null);

foreach (Model modin myModelsSVC)

{

if (mod.Name.ToLower().StartsWith(prefixText.ToLower()))

filteredList.Add(mod.Name);

}

return (string[])filteredList.ToArray(typeof(string));

}

}


Hi,

I tried the solution in the thread you suggested, but it didn't work. I don't think it is related to this though, because the webservice i'm calling is in the same project than the page consuming it.

Could the problem be related to the fact i'm using the "web application project"? or nested masterpages?

Wesley


hello.

what response do you get from fiddler?


Hi,

Have you tried using as RelativePath within your ServicePath parameter?

Regards