Showing posts with label inside. Show all posts
Showing posts with label inside. Show all posts

Wednesday, March 28, 2012

Dificult to reproduce : problems with webpartzones inside updatePanel

Hi !

That's very dificult to reproduce.

I'm creating a new website. I'm using the default webserver of Visual Studio 2005.

The home page users master pages and has a lot of user controls. The scriptManager and the webpartmanager are in masterpage.

One of the user controls uses three panels with ColapsiblePanelExtender. It's working now, after discovered It doesn't work without documentType tag.

The user controls are inserted in the master page, including a top menu with a top banner.

In the main page I have an UpdatePanel with two webpartzones and some webparts. I also have an UpdateProgress

The problems started when I tried to put outputcache in some user controls, like header and footer of the page.

1st Problem : The webParts in the middle don't allow to change position any more. When I move the webParts, the server is contacted (UpdateProgress works), answer is received but nothing change.

This happens sometimes. First I thinked it was cache, so I take out outputcache from all user controls and tried again, inserting outputcache one by one.

So I discovered that when I get this problem, if I delete the temporary directory for this application (in ASP.NET temp folder), close the webserver (and related process) and delete the browser cache the problem disappears.

2nd Problem : After insert outputcache in some user controls, something difference started to happend - when I move one webpart it changes, but the top banner change it's position, changing the page layout!

The UpdatePanel and webparts are in default.aspx page. Default.aspx uses one masterPage. Inside this master page is the top.ascx user control. Inside this control is the banner. So, something in the page change the layout, making the banner changes Its position!

In the moment I will undo all the cache changes, one by one, trying to discover wich change created this problema, but I don't believe one of the cache changes could do this.

With all this problems, the development becames too slow.

[]'s

Dennes

Hi !

I solved the banner problem, but I still don't know why it happend.

The original HTML was like this :

<style type="text/css" title="Portal BufaloInfo"><!--#banner {position:absoluteleft:284pxtop:21pxwidth:468height:60z-index:1}--></style><div id="banner"><a href="#"><img src="images/banner_468_60.gif" width="468" height="60" border="0"></a></div>

I changed to :

<div id="banner" style="position:absolute;left:284px;top:21px;width:468;height:60;z-index:1"><a href="#"><img src="images/banner_468_60.gif" width="468" height="60" border="0"></a></div>

So, now it works. Before this change, when the style was applied to DIV tag the banner was correct, when not, the banner apears in other position.

The main question is : Why the updatePanel, after a refresh, was changing the way this style was applied ?

[]'s

Dennes


Hi !

This seems to be a problem between Alas and IE, or something like that.

After I corrected the banner problem, IE stoped to apply the style to the rest of the page, to the entire page.

Like before : The pages start correct, after UpdatePanel has communicate with the server, the style disappears.

[]'s

Dennes

Monday, March 26, 2012

Detect AJAX postback in Application.EndRequest

Anyone know if there's a way to detect whether the current request is an AJAX postback or a regular postback from inside the Application.EndRequest event of an HttpModule? I have a module that writes out information to the end of a normal request (using response.write). However, this causes an AJAX postback request to fail. Or maybe there's a better way to append some text to the end of a request than response.write?

Ideas?

Test for (Request["X-MicrosoftAjax"] == "Delta=true"). That request header is present in partial postbacks.


Most excellent. Thanks!

HOWEVER, I'm a bit PEEVED at Microsoft for making the client-side AJAX javascript so sensitive to the data that comes back. If any part of my code does a response.write anywhere, the stupid AJAX Javascript on the client goes wobble-kneed and dies. Sheesh! I'd really like to be able to write out some text (using response.write) in both the master-page AND the httpModule's end_request event, but the AJAX Javascript on the client won't allow it! What a pain.

I've seen some c# code on the internet that shows how to modify the response that AJAX returns, but it's confusing as it's doing text translation (i.e., the function of the code is getting in the way of me understanding what it's doing to the response string).

Thanks for the answer to the original question.


Use some sort of HTTP viewer to inspect a partial postback response, and you'll probably see a way to do what you want to. Once you see it, hands-on, it's not too difficult to figure out how to alter (or see why Response.Write kills it).

I use FireBug for that, myself. I think Fiddler is a comparable IE addon.

DetailsView Inside of a Modal Popup

I'm using a DetailsView to insert new records into a database as well as edit existing records. The Modal is called via ModalPopupExtender.Show() when a LinkButton is clicked and then hidden when the LinkButtons on the DetailsView are clicked. The Functions of the modal popup seem to work fine as well as the Insert() Update() methods of the DetailsView. The problem I'm having is with updating the Text property of the LinkButton at the bottom of the DetailsView to change it from "Add" to "Save" depending on the DetailsView.CurrentMode that I'm changing to/from. I've tried using Update Panels around the LinkButtons only in the DetailsView and then I added an AsyncPostBack trigger for the LinkButton that pops the modal DetailsView in Insert mode and an AsyncPostBack that pops the modal DetailsView in Edit mode from the GridView I have on the page. Then I added a PostBack trigger to handle clicks of the LinkButton on the DetailsView for Insert/Update (depending on the mode) and then Cancel. Both of the postbacks close the modal successfully, it's the AsyncPostBacks that are not updating the Modal DetailsView to show the right Text on the one LinkButton I'm trying to update. Any help would be appreciated. Here is the code:

1protected void Page_Load(object sender, EventArgs e)2 {34 }5protected void AddCategory_OnClick(object sender, EventArgs e)6 {7 ModalPopupExtender1.Show();8 CategoryDetailsView.ChangeMode(DetailsViewMode.Insert);910 }11protected void UpdateInsert_OnClick(object sender, EventArgs e)12 {13if (CategoryDetailsView.CurrentMode == DetailsViewMode.Insert)14 {15 CategoryDetailsView.InsertItem(true);16 }17if (CategoryDetailsView.CurrentMode == DetailsViewMode.Edit)18 {19 CategoryDetailsView.UpdateItem(true);20 }21 }22protected void Cancel_OnClick(object sender, EventArgs e)23 {24 ModalPopupExtender1.Hide();25 CategoryDetailsView.ChangeMode(DetailsViewMode.ReadOnly);2627 }28private LinkButton updateinsertbtn29 {30get31 {32 LinkButton udtisrtbtn;33 udtisrtbtn = (LinkButton)CategoryDetailsView.FindControl("UpdateInsertLinkBtn");34return udtisrtbtn;35 }36 }37private int index38 {39get40 {41return CategoryGridView.SelectedIndex;42 }43 }44protected void CategoryGridView_OnSelectedIndexChanged(object sender, EventArgs e)45 {46 CategoryDetailsView.ChangeMode(DetailsViewMode.Edit);47if (index != -1)48 {49 ModalPopupExtender1.Show();50 CategoryGridView.DataSourceID =null;51 CategoryTableAdapter categoryAdapter =new CategoryTableAdapter();52 CategoryGridView.DataSource = categoryAdapter.GetCategories();53 CategoryGridView.SelectedIndex = index;54int categoryid = Convert.ToInt32(((Categories.CategoryDataTable)CategoryGridView.DataSource).Rows[CategoryGridView.SelectedRow.DataItemIndex]["CategoryID"]);55 SqlDataSource1.SelectCommand ="Select CategoryName, CategoryDescription, CategoryID from Category where CategoryID = " + categoryid;5657 CategoryDetailsView.DataBind();58 CategoryGridView.DataSource =null;59 CategoryGridView.DataSourceID ="SqlDataSource1";60 SqlDataSource1.SelectCommand ="Select CategoryID, CategoryName, CategoryDescription from Category Order by CategoryName";61 CategoryGridView.DataBind();6263 }64 }

<asp:ContentID="Content1"ContentPlaceHolderID="maincontent"Runat="Server">
<script>
function okScript()
{
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm._doPostBack('UpdatePanel1','');
}
</script>
<asp:ScriptManagerid="ScriptManager1"runat="server"></asp:ScriptManager>
<table>
<tr>
<tdvalign="top"style="padding:5px;line-height:1.6em;">

<asp:HyperLinkID="AddCatLinkButton"runat="server"Text="Add New Category"NavigateUrl="javascript:NewCategory('addCategory.aspx');"></asp:HyperLink><br/>

<asp:LinkButtonID="AddCategoryLinkButton"runat="server"Text="Add New Category"OnClick="AddCategory_OnClick"></asp:LinkButton>

</td>

<tdvalign="top">

<asp:UpdatePanelid="UpdatePanel1"runat="server"UpdateMode="Conditional">

<contenttemplate>

<asp:GridViewid="CategoryGridView"runat="server"DataSourceID="SqlDataSource1"CellPadding="3"DataKeyNames="CategoryID"AutoGenerateColumns="False"OnSelectedIndexChanged="CategoryGridView_OnSelectedIndexChanged">

<Columns>

<asp:CommandFieldHeaderText="Edit"ShowSelectButton="true"SelectText="Edit"/>

<asp:BoundFieldDataField="CategoryID"HeaderText="CategoryID"InsertVisible="False"ReadOnly="True"SortExpression="CategoryID"Visible="False"/>

<asp:BoundFieldDataField="CategoryName"HeaderText="Name"SortExpression="CategoryName"/>

<asp:BoundFieldDataField="CategoryDescription"HeaderText="Description"SortExpression="CategoryDescription"/>

<asp:TemplateFieldHeaderText="Remove Category">

<ItemTemplate>

<asp:LinkButtonID="DeleteButton"runat="server"Text="Remove"CommandName="Delete"></asp:LinkButton>

</ItemTemplate>

<ItemStyleHorizontalAlign="Center"/>

</asp:TemplateField>

</Columns>

<EmptyDataTemplate>

There are no categories to display.

</EmptyDataTemplate>

</asp:GridView>

</contenttemplate>

</asp:UpdatePanel>

</td>

</tr> </table>

<asp:PanelID="CategoryPanel"runat="server"GroupingText="Product Category"Style="display:none;"CssClass="modalPopup">

<asp:DetailsViewID="CategoryDetailsView"runat="server"AutoGenerateRows="False"DataKeyNames="CategoryID"DefaultMode="ReadOnly"

DataSourceID="SqlDataSource1"CellPadding="3"CssClass="TextBox"OnModeChanged="CategoryDetailsView_OnModeChanged">

<Fields>

<asp:BoundFieldDataField="CategoryID"HeaderText="CategoryID"InsertVisible="False"

ReadOnly="True"SortExpression="CategoryID"Visible="False"/>

<asp:BoundFieldDataField="CategoryName"HeaderText="Name"SortExpression="Name"/>

<asp:BoundFieldDataField="CategoryDescription"HeaderText="Description"

SortExpression="Description"/>

</Fields>

<FooterTemplate>

<asp:UpdatePanelID="LinkUpdate"runat="server"EnableViewState="true"UpdateMode="Always"RenderMode="Inline">

<ContentTemplate>

<asp:LinkButtonID="UpdateInsertLinkBtn"runat="server"Text="Test"OnClick="UpdateInsert_OnClick"></asp:LinkButton>

</ContentTemplate>

<Triggers>

<asp:AsyncPostBackTriggerControlID="AddCategoryLinkButton"EventName="Click"/>

<asp:AsyncPostBackTriggerControlID="CategoryGridView"EventName="SelectedIndexChanged"/>

<asp:PostBackTriggerControlID="UpdateInsertLinkBtn"/>

<asp:PostBackTriggerControlID="CancelButton1"/>

</Triggers>

</asp:UpdatePanel>

<asp:LinkButtonID="CancelButton1"runat="server"Text="Cancel"OnClick="Cancel_OnClick"></asp:LinkButton>

</FooterTemplate>

</asp:DetailsView>

<divalign="center">

<asp:LinkButtonID="OkButton"runat="server"></asp:LinkButton> <asp:LinkButtonID="CancelButton"runat="server"></asp:LinkButton>

</div>

</asp:Panel>

<ajaxToolkit:ModalPopupExtenderID="ModalPopupExtender1"runat="server"TargetControlID="AddCatLinkButton"CancelControlID="CancelButton"OkControlID="Okbutton"

PopupControlID="CategoryPanel"OnOkScript="okScript()"BackgroundCssClass="modalBackground"DropShadow="true">

</ajaxToolkit:ModalPopupExtender>

<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:IT_ASSETDbase %>"

DeleteCommand="DELETE FROM [Category] WHERE [CategoryID] = @dotnet.itags.org.CategoryID"

InsertCommand="INSERT INTO [Category] ([CategoryName], [CategoryDescription]) VALUES (@dotnet.itags.org.CategoryName, @dotnet.itags.org.CategoryDescription)"

SelectCommand="SELECT 'javascript:NewCategory(''editCategory.aspx?CategoryID=' + CAST(CategoryID AS nvarchar) + ''');' AS URL, CategoryID, CategoryName, CategoryDescription FROM Category"

UpdateCommand="UPDATE [Category] SET [CategoryName] = @dotnet.itags.org.CategoryName, [CategoryDescription] = @dotnet.itags.org.CategoryDescription WHERE [CategoryID] = @dotnet.itags.org.CategoryID">

<DeleteParameters>

<asp:ControlParameterControlID="CategoryGridView"Name="CategoryID"PropertyName="SelectedValue"Type="Int32"/>

</DeleteParameters>

<UpdateParameters>

<asp:ParameterName="CategoryName"Type="String"/>

<asp:ParameterName="CategoryDescription"Type="String"/>

<asp:ParameterName="CategoryID"Type="Int32"/>

</UpdateParameters>

<InsertParameters>

<asp:ParameterName="CategoryName"Type="String"/>

<asp:ParameterName="CategoryDescription"Type="String"/>

</InsertParameters>

</asp:SqlDataSource>

</asp:Content>

">

I was unable to accomplish changing the Text property value to what I wanted but I ended up modifying the code to remove the Update Panels in order to get modal DetailsView to Insert and Edit records and then update the GridView control by calling GridView.DataBind() after the Update() or Insert() methods were called for the DetailsView. Not exactly what I wanted but works.

Wednesday, March 21, 2012

Delegates on succes webservice call

Hi All,

I am writing a control where i would like to refer to a method inside my own control, see code below to make the situation clear:

var webRequest = Sys.Net.WebServiceProxy.invoke('Webservice/ImageService.asmx','Hello',false,null,this.WebserviceCallCompleted,this.WebserviceCallFailed,null, 10000);

First i do a webservice call which is working great! As you can see when the call succeeds the function WebserviceCallCompleted is invoked. In this method i would like to set a variable and start the rendering proces again. I do this with:this.Render;

WebserviceCallCompleted:function(result)

{

this._buttonText = result;

this.Render;

}

When i run this code the Render method isn't invoked. any ideas? should i use delegates?

Thanks in advance!

Regards,

To Resolve the this keyword use Function.createDelegate. Like:

var successHandler = Function.createDelegate(this, this.WebserviceCallCompleted);

var webRequest = Sys.Net.WebServiceProxy.invoke('Webservice/ImageService.asmx','Hello',false,null,successHandler,this.WebserviceCallFailed,null, 10000);


Hi KaziManzurRashid,

Thanks for your reply. I implemented your solution but it isn't working (yet) below you see what i have done:

InvokeWebservice:function()

{

var _completeHandler = Function.createDelegate(this,this.WebserviceCallCompleted);var webRequest = Sys.Net.WebServiceProxy.invoke('Webservice/ImageService.asmx','Hello',false, {"test":$get('txtfld1').value}, _completeHandler,this.WebserviceCallFailed,null, 10000);

}

,

WebserviceCallCompleted:function(result)

{

this.Render;

}

The WebserviceCallCompleted method is invoked so the delegate is implemented right. When i take a closer look at the this instance is see that 'this' is representing the right control and it contains a Render method but it still isn't invoked. Any idea?

Regards,


I could not find any reason the Render is not get executed, may be you should put this.Render() instead of this.Render.


hi KaziManzurRashid,

Very stupid but thats the trick i changed this.Render in this.Render() and it works. Probably there is a difference when you refer to a method when creating a delegate and when refering directly to it. I feel a little stupid! Thanks for your time and solutionBig Smile

Regards,

Degradable ajax

A pure hypotetical question.

Suppose I have an updatepanel with say a datagrid inside and it has a trigger relates
to another submit button. How can you make it degradeable? Have you heared any future
possibilty?

I am not sure it exactly addresses your question, but our goal with UpdatePanel is for it to be a no-op on browsers that don't support XmlHttp... so you should be able to easily degrade to a full postback model... is that what you were asking?

..brad


yeah, sorry for not being clear. that's exactly what i meant. thanks.

DefaultButton in a Panel inside an ajax UpdatePanel

The DefaultButton does not act properly on browsers other than MS IE. I guess that the WebForm_FireDefaultButton is the main problem. When I override this function by one that i wrote the problem becomes solved.

Could you post the fix you made please? Right now I'm about to pull out the update panels on my page because I must have default button working under firefox.

Thanks


I would also like to know the fix, and where you put the fix at. Thanks!

Default Focus with the Login control and the Ajax RoundedCornersExtender

I have a problem that either has a simple solution or is an Ajax bug - I don't know which.

I've implemented the Login control inside a panel that has its corners enhanced by the RoundedCornersExtender. It looks great but one negative side effect is that the initial focus is no longer in the UserName textbox. Remove the extender and the problem goes away.

Any ideas?

Robert W.
Vancouver, BC

Hi Robert,

Can you show me a small, self-sufficient repro regarding this issue?


Raymond,

Greetings from the North end of the I-5 !!! :-)

One perfect example of this can be found here: http://pocketpollster.com/beta/Login/login.aspx

I looked for your e-mail address on here but can't find it. You can e-mail me here: A1 at PocketPollster dot Com

And then I can send you the source files back.

Robert



Robert, I think it will be better if you post a simple demo here. All the community may benefit from this. :)

I had a rough idea for solving your problem. Can you add a javascript function which will run on pageLoad? And set focus to the userName textbox in this method. For instance:

function pageLoad()

{

window.setTimeout(setfocus, 1000);

}

function setfocus()

{

$get("the client id ").focus();

}


Raymond,

I will try your workaround but hopefully you can let the Ajax guys at MS know of this definite bug. Here's the barebones of the code:

<%@. Page Language="C#" MasterPageFile="~/main.master" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="_login" %>
<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Panel ID="panelLogin" runat="server" Height="250px" Width="270px" BackColor="#F9F9F9">
<asp:Login ID="Login1" runat="server" BorderPadding="12">
<TitleTextStyle HorizontalAlign="Left" VerticalAlign="Top" Height="40px" Font-Bold="true" Font-Size="Large" />
<TextBoxStyle Width="140px" />
<LoginButtonStyle Width="70px" />
</asp:Login>
</asp:Panel>
<cc1:RoundedCornersExtender ID="RoundedCornersExtender1" runat="server" TargetControlID="panelLogin" BorderColor="black" Radius="5" />
</asp:Content>

protected void Page_Load(object sender, EventArgs e)
{
// Make the Sign In button the default button and place the cursor in the User Name textbox
if (!IsPostBack)
{
Page.Form.DefaultButton = Login1.FindControl("LoginButton").UniqueID; // This works!
Page.Form.DefaultFocus = Login1.FindControl("UserName").UniqueID; // Doesn't currently work because of the Ajax RoundedCornersExtender control
}
}

------------
- End of Code -

Robert


http://www.codeplex.com/AtlasControlToolkit/WorkItem/View.aspx?WorkItemId=11520


Gracias, amigo!!

Well, my app takes this one step further. While this is related to the Ajax RoundedCornersExtender, it is also aggravated by the Ajax TextBoxWatermarkExtender control as well. Basically, I have a MasterPage with a LoginView control on it, and my content page (Register.aspx) is a 2-step CreateUserWizard process. I managed to figure out how to handle the Default Button work around (LoginView login button was being defaulted), but then I came across the Focus issue. Due to the fact that I have the TBWE control on the textboxes I want to focus, the Ajax controls are overriding my focus settings. Using Raymond's workaround, I managed to be able to get Step 1 of my CreateUserWizard control to set the focus to my first textbox (though only 90% of the time). The problem is that I then don't have any recourse on setting the focus of the first control on the second step since the load event is already set. Any ideas?


Shouldn't this now be fixed with the latest release - 10920? If so, I still have the problem.


I've been on holidays so wasn't aware that it was released ... and on my birthday no less! The notes with the release do seem to indicate that the problem has been resolved.

Robert


I have downloaded the latest release and I still get this issue. Without the RoundedCornersExtender I can set the focus in a textbox on page load, as soon as I put one on the page the focus doesn't work. Anyone else still having this issue or is something not right in my set up?


I have now had the opportunity to test it too. It definitely is NOT fixed. I even went so far as to set the default focus to the actual (hard-coded) UserName control name but it did not work. With the RoundedCornerExtender it does, so I'm convinced that the bug is not fixed.