Showing posts with label update. Show all posts
Showing posts with label update. Show all posts

Wednesday, March 28, 2012

Linebreak appears after update panel submits

I wrote a control that would allow a user to click on a label, and then edit it the value, and send back the new value to the server via an update panel.

However, the first time the value is sent to the server, a line break appears right above the text box, i dont think this is a css error, i can't seem to figure out what is causing it by examining the DOM. This only appears in IE, not Firefox, Any ideas?

Here's the mark up for the Control

<%@dotnet.itags.org. Control Language="VB" AutoEventWireup="false" CodeFile="QuickEditLabel.ascx.vb" Inherits="QuickEditLabel" %><script type="text/javascript"> function<%=Me.hidCurrentFileId.ClientID%>updateNumber(param) { var hiddenField = document.getElementById("<%=hidCurrentFileId.ClientID%>"); hiddenField.value = param; __doPostBack('<%=hidCurrentFileId.ClientID%>',''); } function QuickEditSwap(hideMe, showMe) { showMe.style.display = 'none'; hideMe.style.display = 'inline'; }</script><asp:HiddenField ID="hidCurrentFileId" runat="server" Value="" /><asp:UpdatePanel ID="updPanel" UpdateMode="Conditional" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="hidCurrentFileId" EventName="ValueChanged" /> </Triggers> <ContentTemplate>   <asp:Label ID="Label1" runat="server" CssClass="QuickEditText" ToolTip="Click to Edit"></asp:Label> <asp:TextBox ID="TextBox1" runat="server" CssClass="QuickEditTextBox" Width="93px"></asp:TextBox> </ContentTemplate></asp:UpdatePanel>

Here's the Code behind for the control

PartialClass QuickEditLabelInherits System.Web.UI.UserControlPrivate myTextAs String Public Property Text()Get Return myTextEnd Get Set(ByVal value) myText = valueEnd Set End Property Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.LoadIf Not IsPostBackThen Me.Text ="33"Else Me.Text =Me.TextBox1.TextEnd If Me.TextBox1.Attributes.Add("onchange",Me.hidCurrentFileId.ClientID +"updateNumber(getElementById('" + Me.TextBox1.ClientID + "').value)") Me.Label1.Attributes.Add("onclick", "QuickEditSwap(getElementById('" + Me.TextBox1.ClientID + "'), getElementById('" + Me.Label1.ClientID + "'))")End Sub Protected Sub Page_PreRender(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.PreRenderMe.Label1.Text =Me.TextMe.TextBox1.Text =Me.TextEnd SubEnd Class

Here's the css i'm using for the control

 .QuickEditText {font-family: Verdana;} .QuickEditText:hover {text-decoration: underline; font-family: Verdana; cursor: pointer} .QuickEditTextBox {display: none; font-family:Verdana;}

Thanks in advance for any suggestions,

This is happening because of the default setting of the UpdatePanel's RenderMode property - which will render its contents into a <div> the first time. Try changing it to "Inline" so that it will instead render a <span> element.

link button inside update panel causes post back

I have a linkbutton inside the update panel. I registered it with AsyncPostBackTrigger, but when I click that link button, the whole page is refreshed instead of that update panel, what could I have gone wrong?

Check the EnablePartialRendering="true" of ScriptManager is et or not ?

Also check UpdateMode="Conditional" of UpdatePanel is set or not ?

Linkbutton inside update panel not working and causing exception

I page that contains an update panel. this page has a linkbutton that redirects to a new page and opens that page in a a new window(the page redirected to displays a picture). This linkbutton has been working all along with after adding this line of code in the pageload event.

ScriptManager.GetCurrent(Page).RegisterPostBackControl(LinkButton23)

suddenly, the linkbutton can nolonger redirect to the page when clicked and iam not aware of anything i did that may have crewed it up. I now get the following error message when i click it.

sys.webforms.webrequestmanagerParsererrorException: The message recieved from the server could not be parsed . Common causes for this error are when the response is modified by calls to response.write(), response.filters or server trace is enabled. Details: Error parsing near '<script language="ja'.

Actually i have noticed very strange behaviours by my IDE since i installed windows updates on tuesday, things like button click events not firing.

Any help.

Iam not sure if this extra information may help me get a reply. After some googling, most results are pointing to some thing to do with response.write in an update panel.

And in side the click event of my linkbutton, i have these javascript lines of code

ProtectedSub LinkButton23_Click1(ByVal senderAsObject,ByVal eAs System.EventArgs)

Dim myScriptAsString ="<script language=""javascript"">window.open('human Resources/viewer.aspx?id=" + employeenumber.SelectedValue +"') </" +"script>"

Response.Write(myScript)

EndSub

Iam not sure if this could be the cause of the problem but just in case.


<%@.PageLanguage="VB"AutoEventWireup="false" %>

I just changedAutoEventWireup from ="false" to="true" and every thing is back to normal, makes look stupid after wasting loosing over 8 hours. One more gotcha learnt though.

List Box and the update panel

I would like to know the event name to use when an ASP List Box is used with the update panel control. I would like the updatePanel to fire when the ListBox Selected Index Changed event occurs.

Thank You for any help

George

<asp:ListBoxID="ListBox1"runat="server"DataSourceID="AccessDataSource1"DataTextField="product_name"DataValueField="product_id"Rows="30"CausesValidation="True"></asp:ListBox>

<asp:AccessDataSourceID="AccessDataSource1"runat="server"DataFile="~/App_Data/test.mdb"SelectCommand="SELECT [product_id], [product_name] FROM [Products]"></asp:AccessDataSource>

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

<atlas:UpdatePanelID="up222"Mode="Conditional"runat="server">

<Triggers>

<atlas:ControlEventTriggerControlID="ListBox1"EventName="SelectedIndexChanged"/> <!-- DOES NOT FIRE -->

<atlas:ControlEventTriggerControlID="Button1"EventName="Click"/>

</Triggers>

<ContentTemplate>

<asp:LabelID="Label2"runat="server"Text="Labe354"></asp:Label>

</ContentTemplate>

</atlas:UpdatePanel>

You have everything exactly right, though it might not actually be what you want. Every time the SelectedIndexChanged event is raised, or the button is clicked, the UpdatePanel will be updated. However, to get any of that to happen, a postback must occur. In your sample page, the only way to get that to happen is to click the button. To make the page update immediately when the list selection changes, add this property to your ListBox: AutoPostBack="true"

Thanks,

Eilon

Monday, March 26, 2012

ListBox error with UpdatePanel

Using a listbox in an update panel with visible= false and AutoPostBack=true causes an error in the foloiwng code below. If I remove either the AutoPostBack and instead use a button to PostBack it works fine or if I remove the Visible it works fine. My workaround is to set the style of the listbox to display:none instead of using Visible.

I'm using the June CTP

<formid="form1"runat="server">
<atlas:ScriptManagerID="scriptManager"runat="server"EnablePartialRendering="true"/>
<div>
<atlas:UpdatePanelID="upListBox"runat="server">
<ContentTemplate>
<asp:ButtonID="Button1"runat="server"Text="Button"OnClick="AddListItems"/>
<asp:ListBoxID="ListBox1"runat="server"OnSelectedIndexChanged="ListBox1_SelectedIndexChanged"Visible="false"AutoPostBack="true">
<asp:ListItemText="one"/>
<asp:ListItemText="two"/>
<asp:ListItemText="three"/>
</asp:ListBox>
</ContentTemplate>
</atlas:UpdatePanel>
</div>
</form>

CODEBEHIND

publicpartialclassDefault2 : System.Web.UI.Page
{
protectedvoid ListBox1_SelectedIndexChanged(object sender,EventArgs e)
{
ListBox1.Visible =false;
}

protectedvoid AddListItems(object sender,EventArgs e)
{
ListBox1.Visible =true;
}
}

Hi,

there's an issue with the UpdatePanel and the __doPostBack function that prevents it to be injected on the page if it is required by a control inside an UpdatePanel.

The solution is to force the server to drop the __doPostBack function. Add this statement in the Page_Load method:

Page.ClientScript.GetPostBackEventReference(this, String.Empty);

Listbox selections to update secondary listbox items

Good Afternoon,

I am extremely new to the Atlas functionality, and am trying to address some customer requests using Atlas. Two listboxes, Category and SubCategory, are initially rendered on the page with all distinct values. My question is how to update the SubCategory listbox when items have been selected in the Category listbox. I have tried to include a parameter for the selection of the SubCategory items, but the list initially is rendered with no items since the parameter value is not assigned.

Any help, insight, or suggestions is greatly appreciated. Also, any suggestions on best practices is also welcome regarding controls utilizing Atlas (for example, using a dataset to populate the listbox versus going directly against the SQL tables).

Thank you,

Erik

Hi,

It sounds like the CascadingDropDown control in this toolkit may be the answer to your questions.

http://atlas.asp.net/atlastoolkit/CascadingDropDown/CascadingDropDown.aspx

Regards


Thank you for the response. Is there any way to utilize a listbox instead of a drop down? Currently, the users can select multiple items from the list.

Hi,

Could you initially populate the subcategory box in the page_load event (when not Page.Ispostback), then have the list updated with a control event parameter on the Category Listbox.

Hope this helps

Saturday, March 24, 2012

Literal Control Update Panel IE6

I have two buttons and a literal control placed inside an update panel which is sitting inside of a Drag Panel which is inside of some animation to display the initial panel. In IE7, everything works properly - when you click a button to refresh the image being drawn in the literal control, the button's text in changed to "Processing..." and then, when the response is obtained, the image is refreshed and the button's text is reverted back to its original state.

In IE7, however, the button works fine but the image never refreshs - even though I am re-writing the Literal upon postback. It is almost as if IE is caching the image. Does anybody know how to correct this issue?

Thanks!

In IE7 there is the animation disable by default, you can enable that in options.

Load content on demand or in portions

Hi,

I have large chunks of text (400-500Kb) that are loaded inside update panel when user clicks on a tree node with the book name. It works fine and all. The only thing is that the text is first downloaded to client and then shown - the user will have to wait for the whole 400Kb of text to download. Is there a way to show the first 5-10Kb of text once it has reached the client and keep loading the reast while user is reading?

And one more question - is this ok that Page_Load() event is fired every time UpdatePanel is updated?

Hi abolotnov,

To start with your last question it is normal that the page_load event get fired when you are doing a partial update. The trick is within the rendering of the HTML, so thats correct. What kind of control is inside your UpdatePanel (treeview?) You can use a updateprogress control to make clear to the user that the page is still updating. Can you past some code here so we can analyze your code. Thanks

Regards,


yeah, I know I can use UpdateProgress control to tell the user that the page is still updating... this is not I really want though -

say I have this UpdatePanel with DIV inside of it and need the text in DIV to be updated. The text is 400K - quite a lot for people with slow internet connection (dialup for example). I want them to be able to start reading the text before it's downloaded in whole. Say, if their connection speed is 4K/sec, they will be able to start reading in 1 second - 4K of text gives them enough to read before the rest is downloaded - another 4k will come next second etc.

What I have now is when the update starts use sees this message "content for reading pane is being updated, please wait" untill the whole portion of text is downloaded and then rendered. For people on slow internet connections it takes quite a while 400/4 secs.


Don't ask me why I can't split the text into smaller portions and allow users to page through the text - I will if there is no way to sort out what I want.

Thanks for any comments you may have on this.

load external url in page?

I have a treeView that lists SQL Reports available to the user. What I'd like to do is put the treeView into an Update Panel, and some other control that can display an external url, next to the treeView so that when a user clicks on a report, it fetches the contents of the url and displays it without doing a postback. So my question is, are there samples of this out there (I couldn't find any) and if so, what control would allow me to load external content into it (like an iframe)? I realize I could do the same thing with a div or iframe using javascript, but I'd like to use ajax if possible...

Thanks!

eddie

Chao,

I would put the iframe inside the UpdatePanel and the Trigger controling the URL's ID from the treeview. This is similar to having a gridview or any view inside an UpdatePanel with a trigger controlling a button. The button is of course outside the UpdatePanel.

WS

p.s. not responsible for not working ... hihihi ... but that's how i see it.

Wednesday, March 21, 2012

LoadControlState event not firing in update panel.

I have a link which is wrapped in a update panel. This link works as an expand/collapse link. The expand/collapse status of the link is saved in the control state. But i found that the LoadControlState event does not fire but the SaveControlState does. Because of this, i always get the expand/collapse state of the link as Collapsed which is default. I am kind of stuck on this now. I dont want to use session as it does not sound like a session wide data. I tried using hidden variables but even that does not work with ajax because Request.Form always has old value.

The reason i want to use control state and not viewstate is becasue i want to disable the viewstate on this page.

Any help is much appreciated.

Nilesh

Hi Nilesh,

I tried using hidden variables but even that does not work with ajax because Request.Form always has old value.

What you mean?

If you want to store something,you can store them in javascript variables.

Please check this:http://forums.asp.net/p/1134520/1813803.aspx#1813803

it store the scrollLeft/scrollTop in javascript variables.

Best Regards.

Loading Controls using an update panel

I'm currently trying to load controls onto the page dynamically and I was trying to use the UpdatePanel so that the controls could load w/o the page refreshing but I'm running into a problem with that. When I click the button that loads the control, it forces a refresh. How do i fix that?

here's the code

<%

@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default" %>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">

<

headrunat="server"><title>Untitled Page</title>

</

head>

<

body><formid="form1"runat="server"><atlas:ScriptManagerID="ScriptManager1"runat="server"/><asp:ButtonID="btnControl1"runat="server"Text="Load Control 1"CausesValidation="False"OnClick="btnControl1_Click"/><asp:ButtonID="btnControl2"runat="server"Text="Load Control 2"CausesValidation="False"OnClick="btnControl2_Click"/><atlas:UpdatePanelID="udpPanel"runat="server"><ContentTemplate><div><asp:PlaceHolderID="PlaceHolder1"runat="server"></asp:PlaceHolder></div></ContentTemplate><Triggers><atlas:ControlEventTriggerControlID="btnControl1"EventName="Click"/><atlas:ControlEventTriggerControlID="btnControl2"EventName="Click"/></Triggers></atlas:UpdatePanel></form><scripttype="text/xml-script">

<page xmlns:script=

"http://schemas.microsoft.com/xml-script/2005">

<references>

</references>

<components>

</components>

</page>

</script>

</

body>

</

html>

ASPX.cs

using

System;

using

System.Data;

using

System.Configuration;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

public

partialclass_Default : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

}

protectedvoid btnControl1_Click(object sender,EventArgs e)

{

this.PlaceHolder1.Controls.Add(Page.LoadControl("~/Control1.ascx"));

}

protectedvoid btnControl2_Click(object sender,EventArgs e)

{

this.PlaceHolder1.Controls.Add(Page.LoadControl("~/Control2.ascx"));

}

}

Hi,

it seems that your aren't setting EnablePartialRendering="True" on the ScriptManager control.
I enabled that and I still couldn't get it to work. Any other suggestions?
I fixed it. I'm not quite sure what I did but it works lol.

Loading scripts with ScriptMangerProxy not finding page controls since update to RC1

I have recently updated my AJAX to RC1 and some pages that load js in the scriptmanagerproxy have stopped working...
The problem is that when i try to get a text box it doesnt exist...

$get("txtFirstLine").value

...this is not in a function its just in the file but the object is not found.
It will work i wrap it in a function and call that function at the end of my aspx markup

<scriptlanguage="javascript"type="text/javascript">firstfunction();</script>

...its like the js is now all executed before the aspx page and controls on it are created.

Is this is the case?
Is there an event in the AJAX library that i can use to run this script once the page has been created?

Thx
Steve

You can take a look at theSys.Application.init andSys.Application.load events in the doc.