Showing posts with label dear. Show all posts
Showing posts with label dear. Show all posts

Wednesday, March 28, 2012

Update textbox value

Dear friends,


I'm trying to update a textbox value by values that occour in a for each statement.
Ex.:

List<string> words = new List<string>();
words.Add("Test1<br>");
words.Add("Test2<br>");
words.Add("Test3<br>");
words.Add("Test4<br>");
words.Add("Test5<br>");

foreach (string s in words)
{
txtOcorrencias.Text += s;
System.Threading.Thread.Sleep(2000);
}

I want that each word appear for time, but when the function runs, all the words at the same time.

How I code this?

It's because you are doing this on the server. The server doesn't return the page to the browser every time it sleeps. It runs all of the code and then renders the page.

Have you considered doing this in javascript?


Yes, I try to use javascript but I used Thread to simulate other methods that the application have to execute on the server.


This is one way of doing it:http://encosia.com/2007/10/03/easy-incremental-status-updates-for-long-requests/


gt1329a

I'm using the code you recommend to me, It works 100%.

Thanks.

Updatemode=Conditional still updatepanel is refreshing

Dear all...

I have two update pannel in my page. And both have some controlls and its update progress controll. I have given the updatemode property to conditional for both update pannels. Al also i have assigned the triggers properly. The problem i am facing now is..

We can refer as follows

First update pannel as - [A] and Seccond update pannel as - [B]

I want to update the [B] when i am clicking on a button which resides in [A] , But when i am clicking on the button its refreshing both. And also its showing both updateprogress ..

Thank you very much

hi,

I think both progress bar will be showing because you might not assign associateupdatepanelid in updateprogress.

If u assign this could it will possible for you share your code.


hello.

well, take a look at the childrenastriggers property of the updatepanel control. if you set it to false, your button won't refresh that panel. the problem is that if you have other controls that need to refresh their "parent" panel, then you'll need to register those controls as async postback controls (scriptmanager.registerasyncpostbakcontrol) and refresh the panel during a partial postback started by one of those controls (by calling the update method).


I have asisgned associateupdatepanelid in both updateprogress and also I marked childrenastriggers = false. Still its happening.

hello again.

can you build a really simple page that reproduces this problem and post it here?


I have made almost a same sample... In this sample app also i am facing the same problem...

-----The HTML Part

=================================================================================

<body>

<formid="form1"runat="server">

<asp:ScriptManagerID="ScriptManager1"runat="server"/>

<divstyle="width: 359px; height: 274px">

<asp:UpdatePanelID="UpdatePanel1"runat="server"ChildrenAsTriggers="False"UpdateMode="Conditional">

<ContentTemplate>

<divstyle="width: 315px; height: 185px; background-color: inactivecaptiontext">

<br/>

<asp:ButtonID="butRefresh1"runat="server"Height="36px"Text="To Refresh the update panel 1"Width="203px"OnClick="butRefresh1_Click"/>

<br/>

<br/>

<asp:TextBoxID="text1"runat="server"></asp:TextBox><br/>

<br/>

<asp:ButtonID="Button2"runat="server"Height="31px"Text="To refresh the update panel 2"

Width="200px"OnClick="Button2_Click"/> <br/>

</div>

</ContentTemplate>

<Triggers>

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

</Triggers>

</asp:UpdatePanel>

<asp:UpdateProgressID="UpdateProgress1"runat="server"AssociatedUpdatePanelID="UpdatePanel1"DisplayAfter="10">

<ProgressTemplate>

Loading ....

</ProgressTemplate>

</asp:UpdateProgress>

</div><br/><br/><div>

<divstyle="width: 582px; height: 229px">

<asp:UpdatePanelID="UpdatePanel2"runat="server"ChildrenAsTriggers="False"UpdateMode="Conditional">

<ContentTemplate>

<divstyle="width: 521px; height: 115px; background-color: lightgoldenrodyellow">

<br/>

<asp:TextBoxID="text2"runat="server"Height="23px"Width="313px"></asp:TextBox>

<br/>

<br/>

<asp:UpdateProgressID="UpdateProgress2"runat="server"DisplayAfter="10">

<ProgressTemplate>

<divstyle="width: 368px; height: 100px; background-color: #ffccff">

<asp:LabelID="Label1"runat="server"Font-Bold="True"Font-Italic="False"Font-Size="X-Large"

Font-Underline="True"Height="75px"Text="Loading ...."Width="325px"></asp:Label></div>

</ProgressTemplate>

</asp:UpdateProgress>

</div>

</ContentTemplate>

<Triggers>

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

</Triggers>

</asp:UpdatePanel></div></div></form></body>

=================================================================================

VB.NET Source code...

=================================================================================

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

Dim iAs Int32

For i = 1To 10000000

text1.Text ="Pannel1 refreshed ..."

Next

EndSub

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

Dim iAs Int32

For i = 1To 10000000

text2.Text ="Pannel2 refreshed ..."

Next

EndSub

=================================================================================

I hope youi will try your level best for me to getrid of from this problem...

Thank you


hello.

well, you're getting refresh because you've also set up the buttons as triggers. this will force a postback. I'm putting here a very simple example of how you can refresh the panel through code:

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
void c(object sender, EventArgs e)
{
panel.Update();
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:scriptmanager runat="server" id="manager" />
<asp:Updatepanel runat="server" id="panel" UpdateMode="conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:Button runat="server" ID="bt" Text="refresh" OnClick="c" /><br />
<asp:Button runat="server" ID="Button1" Text="don't refresh" /><br />
<%=DateTime.Now.ToString() %>
</ContentTemplate>
</asp:Updatepanel>

<%=DateTime.Now.ToString() %>
</form>
</body>
</html>