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

Wednesday, March 28, 2012

Accessing values from dynamically created controls

Hi. I'm writing a web application that uses Atlas todynamically create controls in a specific section of a web page. I have 2 update panels. One of them contains a DropDownList. The other one will contain thedynamically created controls. The controls are created in the SelectedIndexChanged event of the DropDownList, and I coded that in the server side. All those controls are arranged in a table server control, which is also created in the SelectedIndexChanged event. The page also has a Button server control that will allow me to start processing the values entered by the user in the created controls. Of course this processing will be done in the server side. This button is not part of either update panel.

Now, the problem is that when I try to get the values of the controls in the Button Click server event, using the table.FindControl() function, I see that the table itself is null, so I cannot access any control value. I think the problem has to do with the fact that the table and its controls are created in the update panel, and for some reason everything created there is not available for my Button Click server event.

How can I solve this scenario?

Thanks,

Julio

Modifying the controls colletion during a postback is generally not a good idea in ASP.NET. Additionally, dynamically added controls will not persist through viewstate so you'll have to re-create and add them to the container on each postback.

Instead of adding/removing controls, I suggest you use the "Visible" property of the control. You can set the control.Visible=false, which will prevent it from rendering down to the client.

Hope this helps,

-Tony


Thanks a lot Tony. The problem is that the user can choose 25 different elements in my combobox, and each element will require to create/show from 1 to 20 new controls on the dynamic section of the page. So if I take your advise and just put all possible controls on the page on design view, hidding or showing them asappropriate, wouldn't it be too much overhead for my page?

Julio


Julio,

Any way you choose is going to require quite a bit of code on your end to determine when to show/hide or create/destroy controls. You are correct in that should you choose to instantiate all controls on the page load, it will indeed add extra overhead.

To acheive the results you are looking for, you'll need to test for which item is selected, and fill the update panel accordingly. The earlier this happens in the page lifecycle the better off you are. The one problem you might encounter is that replacing a control on the fly like this, could cause viewstate errors since the control which saved its viewstate in the previous response, has now been replaced with a completely different control.

We've actually built the behavior you're looking for directly into the Infragistics WebTab. It provides LoadOnDemand behavior though an AJAX mechanism. Using a Tab Interface also speeds up the development since you can separate your content into individual tabs, displaying only the relevant tab. In most cases the performance overhead incurred is well worth the development time saved. Of course, you'd need to make that call based on your own project requirements.

Hope this helps,
-Tony


Hi Tony. You are completely right. I have just found that viewstate error you mention. I have tried to control that error, but I just keep getting errors when adding/removing controls. I would like to try using Infragistics WebTab, as our company has full licenses for the NetAdvantage suite. Could you please show me a small example of how could I achieve this behavior with the WebTab and the LoadOnDemand behavior? Or maybe give me a link to an example? I would reallyappreciate it.

Thanks a lot for your help,

Julio


Hi Julio,

You'll need to getNetAdvantage 2006 Volume 2 if you don't already have it. On the WebTab, set AsyncMode=On, and AsyncOptions.EnableLoadOnDemand=True. Next, using the interactive design surface, simply drag and drop your content into the desired Tab pane. You can even switch between tabs by clicking the desired tab on the design-surface. The WebTab has UpdatePanel-like behavior built directly into it, so postbacks will automatically be turned into AJAX callbacks. The LoadOnDemand behavior will also enable the initial page load to contain only the content for the selected tab, all other tab content will be dynamically retrieved as necessary.

Hope this helps,
-Tony


Hi Tony. It seems likeUltraWebTabAJAX features won't help me. Theasync behavior I'm looking for starts outside the tab control, but not in the tabs itself. My UltraWebTab has 25 tabs inside it. I also have a dropdownlist which is outside my UltraWebTab. Now, without any AJAX behavior, what my page does is that, when you select an element in the dropdownlist I hide all the tabs except for the one that is related to the selected value on the dropdownlist. This of course causes a full roundtrip to the server.

So, what I'd like to happen is that, when I change my selection on the dropdownlist, all the not related tabs just become invisible, but with no roundtrip. I enabled all the async options you mentioned, but I thing they are mostly targeted for the scenarios where the user navigates between tabs, and no with my particular scenario. So I just thought I could solve this by adding an Atlas UpdatePanel and putting the UltraWebTab inside it. I also added a trigger to the panel so that any time the dropdownlist change its value, the updatePanel would update its contents.

Here is the code for my DropDownList:

<table>

<tr>

<tdstyle="width: 3px"valign="top">

<asp:DropDownListID="MyDropDownList"runat="server"AutoPostBack="True"DataSourceID="MyDataSource"DataTextField="Description"DataValueField="Id"></asp:DropDownList><asp:ObjectDataSourceID="MyDataSource"runat="server"SelectMethod="GetMyItems"TypeName="MyProduct.MyClass"></asp:ObjectDataSource></td>

</tr>

</table>

...And this is the code for the UltraWebTab and the UpdatePanel:

<table>

<tr><tdstyle="width: 239px; height: 101%;"valign="top"><atlas:UpdatePanelID="Up1"runat="server"Mode="conditional"><ContentTemplate><igtab:UltraWebTabID="MyUltraWebTab"runat="server"BorderColor="#949878"BorderStyle="Solid"BorderWidth="1px"ThreeDEffect="False"SelectedTab="16"AsyncMode="On"><DefaultTabStyleBackColor="#FEFCFD"Font-Names="Microsoft Sans Serif"Font-Size="8pt"ForeColor="Black"Height="22px"><PaddingTop="2px"/></DefaultTabStyle><Tabs>

<!--Here comes my Tabs and controls -->

</Tabs><RoundedImageFillStyle="LeftMergedWithCenter"HoverImage="[ig_tab_winXP2.gif]"LeftSideWidth="7"NormalImage="[ig_tab_winXP3.gif]"RightSideWidth="6"SelectedImage="[ig_tab_winXP1.gif]"ShiftOfImages="2"/><SelectedTabStyle><PaddingBottom="2px"/></SelectedTabStyle><BorderDetailsColorBottom="90, 120, 160"ColorRight="90, 120, 160"/><AsyncOptionsEnableLoadOnDemand="True"/></igtab:UltraWebTab></ContentTemplate><Triggers><atlas:ControlValueTriggerControlID="MyDropDownList"PropertyName="SelectedValue"/></Triggers></atlas:UpdatePanel></td>

</tr>

But now I'm just getting an "Unknown Error" popup window every time I change my selection in the dropdownlist. It seems like any combination of UltraWebTab and UpdatePanel just does not work. I have already written Atlas apps with my current installation (June CTP) and they work fine until I add an UltraWebTab. All Atlas configurations in the web.config and the script manager are on place, so it should work.

Is there a known compability issue between UltraWebTab and UpdatePanel? If it is, is there any way I could achieve my desired behavior with UltraWebTab async and loadOnDemand options?

Thanks a lot,

Julio


Hi Julio,

You should contact Infragistics Developer Support and provide them the details above. A hotfix was made available on Friday, July 28th which may address this issue.

-Tony

Accessing objects outside update panel

I am trying to access the label or div which is outside the update panel after its post back occurs.

here is code...

how can I make that alert work in Button1_Click method?

thanks in advance...

protected void Page_Load(object sender, EventArgs e) { Label1.Text ="Standard Page Load: " + DateTime.Now.ToLongTimeString(); Label2.Text ="Standard Page Load: " + DateTime.Now.ToLongTimeString(); }protected void Button1_Click(object sender, EventArgs e) { lt.Text ="alert(document.getElementById('" + Label1.ClientID +"').value);"; Label2.Text ="Ajax Page Load: " + DateTime.Now.ToLongTimeString() + lt.Text; }

<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><div> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> <br /> <br /> <script language="javascript"> <asp:Literal id="lt" runat="server" /> </script> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

Try this:

protected void Button1_Click(object sender, EventArgs e)
{
string script = "alert($get('" + Label1.ClientID + "').innerText)";

ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", script, true);

Label2.Text ="Ajax Page Load: " + DateTime.Now.ToLongTimeString();

}


thanks Rashid... that was helpful.


Accessing Controls outside Update Panel.

Hello,

I am having a webapplication in which i am having two pages. w1.aspx and popup.aspx,

On w1.aspx I am having a Menu control and a UpdatePanel control (Ajax Control) and then under Update panel i am having a link named SigIN and a button named refresh,On the click of SignIN l;ink the popup.aspx opens which provides functionality to signin , On that popup window i am logging user in using ajax so there is no refresh in that popup when user signing in.

Now after user signin succefully from the popup.aspx page that is a popup window i am displaying a messge to the user there that "You are SignIN succesfully and now close this window"

When user close the popup window then user comes on the w1.aspx , Now i want when user press the Button Refresh that is present on the w1.aspx under updatepanel control.. then the text of first menu item in the menu control that is present on the page w1.aspx but not under updatepanel will be changed from SignIN to SignOUT, and the link label that is present on this page under updatepanel will be hidden after the click of this refresh button,

But the problem is on the click of this refresh button the link will be hidden but the text of the menu item is not changing. That is i am not able to acces the controls that are present outside the updatepanel control.

WHY??

is it possible to acces the control properties present outside the UpdatePanel control on the click of a button that is present under UpdatePanel control.

????????

Hi, you must to place any control that an another control on UpdatePanel changes on another UpdatePanel. Controls on UpdatePanel can′t to change controls outside UpdatePanel (Don′t happens an error, just don′t works). Don′t need to be the same UpdatePanel. Can be another one, but must be inside of UpdatePanel.


Hi mgodoy_desenv,

Can u please provide me a sample code for the same.

Thanks in Advance...


My codes are very big, so I will to try show. I don′t speak English so much, so excusive for my way of writing:

In code below, you have a control inside UpdatePanel and another one outside:

<html>
...
<asp: Textbox ID="Textbox1" runat="server"/>
...
<asp: UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server"/>
</ContentTemplate>
</asp: UpdatePanel>
</html
To Button1 to change the Text property of Textbox1, Textbox1 must to be placed inside of an UpdatePanel. You not will have an error if that don′t to happen. Just don′t works.

To work, the Textbox1 must be a place inside of an UpdatePanel. The good news is that it don′t need be inside of same UpdatePanel. It can be placed inside another one.

The code below corrects the problem:

<html>
...
<asp: UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>

<asp: Textbox ID="Textbox1" runat="server"/>
</ContentTemplate>
</asp: UpdatePanel>

...
<asp: UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server"/>
</ContentTemplate>
</asp: UpdatePanel>
</html>


Hi,

Your idea is working for a single page but when i am working with master page and menu then i think its not working properly.

Wht i am doing is,

I am having a webpage w1.aspx which is using the master page m1.master, Now my master page having a menu. I want to update the value of that page from the w1.aspx on the click of a button that is present under an updatepanel on w1.aspx.

Now as you said take the control inside the update panel whose value you wann update, so i have taken the menu control under the update panel and then by taking the refrence of menu control on the page w1.aspx i am updating the value of the menu items. But after updatiing the values when i am moving the mouse over the menu items then it gives me the error. some javascript error. I d't know why this ?

If u can then try to do the same thing as i said... with master page..and menu contriol

....


There are many problems with use of UpdatePanel. We must be carefully with it, cause asynchronous post back uses many JavaScript. I haved, for example, many problems with Server.Transfer and UpdatePanel.

Your case isn′t diferent. UpdatePanel can has updated the menu control in a wrong way. Try do this:

1. Use a DataSource to menu. Create a method to populate it with a DataTable, or Xml.
2. When you to want to change items of menu control, change the DataSource (DataTable, or Xml) and call DataBind method of menu.

I don′t speak English so much. So, excuse me for my way of writing.


The Menu control is one of the few ASP.NET controls that isnot compatible with async postbacks. Seehttp://asp.net/AJAX/Documentation/Live/overview/UpdatePanelOverview.aspx#UpdatePanelCompatibleControls for reference.

I would think you should leave the Menu controloutside of the UpdatePanel, but make it a trigger for the UpdatePanel you want to update with <asp:UpdatePanel ...><Triggers><asp:AsyncPostBackTrigger ControlID="MyMenu" /></Triggers>...</asp:UpdatePanel>.


Actually, rereading the question, I may have missed the point here... I was assuming the Menu control was the one triggering the update, but that some other control on the page was being updated.

If the Menu control is the one you want to update, I think you're out of luck, since the Menu can't live inside an UpdatePanel.

Accessing controls inside an updatepanel in onPreInit event

I have an update panel inside a user control that is initialized during the page's PreInit event. However, as soon as I put an updatepanel inside this user control I can no longer access the controls inside this updatepanel during the PreInit event. The controls are all just "null". Am I doing something wrong, or does the updatepanel somehow change my ability to access these controls?Thanks,Jon

Set a breakpoint in PreInit and step through the PageLifeCycle then you see in what Event the UpdatePanel get initialized.


I was just wondering why putting an updatepanel in would break my existing code? Shouldn't it get initialized at the same time as the other controls?
Please have a look at Wally'sPodcast about the clientside lifecycle. I think he's awnsering youre questions.

accessing controls from diff updatepanels

Hi

Just wondering is it possible to access controls from diff update panels

I have a treeview in 1 updatepanel, upon selecting a node in the tree I want to display a panel outside the updatepanel, possibly in another updatepanel

confusing? maybe

Dim panel1 As Panel = CType(Me.UpdatePanel1.FindControl("panel10"), Panel)

Panel1.Visible = True

It definately finds the contro, but will not mae it visible

thoughts ?

Hi!

Are you calling UpdatePanel1.Update() after you set the visible property to true? If you are missing that the Panel will be "visible" but not "showing" as visible.

Also, just a doubt: Why you need to use FindControl to find controls inside UpdatePanels? They aren't NamingContainers, thus you should be able to call them directly from the page.

Regards,

Juan


One more note: if you're talking about using a TreeView, note that the TreeView control isn't compatible with partial rendering (so it can't get updated inside an UpdatePanel). Seehttp://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx#UpdatePanelCompatibleControls.

A good way to think about the UpdatePanel is that it doesn't really change the way postbacks work. So if you can do what you want to with a regular postback, then it should just be a matter of wrapping the write regions of the page in UpdatePanels and setting up the triggers (or calling UpdatePanel1.Update() in the code-behind) to make sure those regions of the page get updated when appropriate during the async postback. My advice would be to get this working how you want with regular postbacks, then add UpdatePanels (which will by default all update on every async postback), and finally optimize by setting UpdateMode="Conditional" and setting up your triggers, so you selectively update the parts of the page that you need to.


thanks guys , some great advice there

UpdatePanel1.Update() was the key here


Steve Marx:

One more note: if you're talking about using a TreeView, note that the TreeView control isn't compatible with partial rendering (so it can't get updated inside an UpdatePanel). Seehttp://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx#UpdatePanelCompatibleControls.

Steve , Is this something that will be fixed in future AJAX releases

I also have some file upload controls on the page that I really need to have there

Monday, March 26, 2012

Accessing ASP.NET Profile

Hi,

How can I update Profile propertys in my Atlas application? Since I don't use update panels, I call web services to make server requests. I know that I can access the Session by declaring [WebMethod(EnableSession=true)], but can I also enable Profiles there?

Or are there alternatives to web services?

In javascript, you access profile properties using something like:

Sys.Profile.properties["list"] = [1, 2, 3];

And then you want to call:

Sys.Profile.save();

To enable this feature, you do need to have a few things in config defined:

<configSections>
<section name="profileService" type="Microsoft.Web.Configuration.ProfileServiceSection" requirePermission="false" />
</sectionGroup>
</configSections>

<microsoft.web>
<profileService enabled="true" getProperties="*" setProperties="*" />
</microsoft.web>

This will enable atlas access to the Profile object, and let you get and set all properties, note you can lock down which propeties you want get/settable thru atlas using the get/setProperties in the profileService section.

Hope that helps,
-Hao


Thank's a lot. After your reply I searched the atlas docs again and now I have no clue, why I overlooked the profile topic before!Wink [;)]

This feature is so cool!Cool [cool] I love Atlas more everyday...

Access HiddenField when using Update Panel

Hello,

I have a page that using update panel. I register hiddenfield using ScriptManager.Registerhiddenfield. I want to get the value, but it always failed.

This is the code :

protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = this.Request.Form["__vsKey"];
}

protected void Button1_Click(object sender, EventArgs e)
{
ScriptManager.RegisterHiddenField(this, "__vsKey", "myValue");
}

When I don't use update panel, it's working properly. Do anyone know how to access the value?

Thanks before

What kind of error you are getting ?

To register a hidden field for a control that is inside anUpdatePanel control so that the field is registered only when the panel is updated, use theRegisterHiddenField(Control, String, String) overload of this method. If you are registering a hidden field that does not pertain to partial-page updates and you want to register a hidden field only one time during initial page rendering, use theRegisterHiddenField(String, String) method of theClientScriptManager class.


The problem is I don't get the value from this hiddenfield when using UpdatePanel. It always return null value.

I'm using a button to register the hiddenfield

protected void Button1_Click(object sender, EventArgs e)
{
ScriptManager.RegisterHiddenField(this, "__vsKey", "myValue");
}

And when the page load, a label display the hiddenfield value

protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = this.Request.Form["__vsKey"];
}

But, the label display nothing when I use UpdatePanel.

Saturday, March 24, 2012

about file upload2

Hi,

I have a fileupload control inside update panel however I don't need to upload any file I just need the file path and filename etc...

eventhough I can see it pastes the path inside the fileupload text part, I can't read it programmatically..

Thankss.

Why do you need the path to a file on the client computer? You can't read a file from the client computer anyway. What are you trying to achieve?


Dim instance As FileUploadDim value As Stringvalue = instance.FileName
.....................
 FileUpload.FileName:Gets the name of a file on a client to upload using theFileUpload control.

gridview:

Dim instance As FileUploadDim value As Stringvalue = instance.FileName
.....................
 FileUpload.FileName:Gets the name of a file on a client to upload using theFileUpload control.

Note that the original posted wanted the filename AND the path..


alexdresko:

Why do you need the path to a file on the client computer? You can't read a file from the client computer anyway. What are you trying to achieve?

This question reminded me how dumb I am :) thanks..

Well I'm coding a webmail interface and my mail server COM API asks for the path but this path is my server's path not the clients :D ok..

But if I know the path somehow; couldn't I upload the file programmatically? without fileupload control, I mean ok it ease the life but if it doesn't work inside an update panel how can I come up with?

Thanks for the reply..


No, you have to use the fileupload control. When the page posts back, you can save the file they uploaded to your server and from THAT you can determine the path to pass to your COM API.

Make sense?


Yes got it;

Thanks..

So is there anyway to do it with updatepanel?


No. You have to wrap your fileupload control within another updatepanel and set EnablePartialRendering = False. Supposedly there are other workarounds, and I know there is at least one third party AJAX enabled upload control, but the built-in fileupload control doesnt work with ajax..


Thanks for the reply;

Do you mean EnableViewState=False?? cause I couldn't find such property (EnablePartialRendering=False)

Wednesday, March 21, 2012

A Question about Atlas Update Panel

I have a questio about atlas update panel!

I upload files with ms FileUpload control in the Atlas UpdatePanel, but always failed. I donnot know why. It's weird, when I set the ScriptManager EnablePartialRendering = false, everything is OK! what's wrong with my UpdatePanel?


Thanks for your help?

Many thanks!

Chinese boy!

Unfortunatelly you cannot use fileupload control within updatepanel.

I am pretty sure it was discussed here a time ago, try to find it here, there is more description why it is not possible

Nice day

Milo


oh..My!!

Thanks for your reminding! anyway it's a big flaw of MS atlas. could you tell me where the discuss post was? I want to know more about this bug!

Thank you again!


HI liuguoping

some note in documentation can be found here:http://atlas.asp.net/docs/Server/Microsoft.Web.UI/UpdatePanel/DeclarativeSyntax.aspx

and some threads in forum dealing with it are i.e. here:

http://forums.asp.net/thread/1301989.aspx
http://forums.asp.net/thread/1321664.aspx
http://forums.asp.net/thread/1361452.aspx

You will be able to find more, try to put "uploadfile updatepanel" into top right search textbox on this page.

Nice day,

Milo


Thanks a lot!

A postback via update panel resets TabIndex?

I have a few controls inside an update panel. One of them is a dropdownlist with autopostback = true. After it postbacks (you know in Ajax style, no full page postback) the the tab indexes of the controls seem to get ignored or reset. I end up back at the first control in the tab index or else sometimes no control is focused when hitting the tab key.

Anyone find the same issue?

There's a workaround I found, just in case you're using ASP.NET Ajax.

In my example, I have a FormView and two DropDownLists, the first is called "ddlCountries", with AutoPostBack=True. The second is called "ddlStates".

In my case, my page is using an ScriptManager. And my FormView is inside an UpdatePanel.


Just create an event for the "ddlCountries" as follows:

protected void ddlCountries_SelectedIndexChanged(object sender, EventArgs e){DropDownList ddlStates = (DropDownList)FormView1.FindControl("ddlStates");ScriptManager1.SetFocus(ddlStates);}

And voi-là!!


Thanks I found that solution too, its a pity the tabindex settings are ignored with partial postacks in ASP.net Ajax.

A group of PostBackTrigger in my updatepanel

I use a repeater to print out information (hyperlinks) from my database. When you click a hyperlink I want to update a updatepanel.

The problem is that the controlID for each link must be typed in a PostBackTrigger to work perfectly. I can't add PostBackTriggers at run time? Any solutions?

Regards Gustav


Can't you set your updatepanel's mdoe="Always" ?
If I remove my triggers and set UpdateMode="Always" the updatepanel updates without Ajax.

The easiest maybe to handle the hyperlink click event on the server side, and update the desired updatepanel in the click event by the .Update() method.

For handling all hyperlink click event in single event in the server side, and determine which link was clicked: check msdn for handling events in repeater, this is a regular asp.net task not ajax. Search for: "How to: Respond to Button Events in DataList, Repeater, or GridView Items"

A form, a treeview, a update panel, and required field validator.

Ok. Lets see if I can explain this. I have a treeview in a uppdate panel. It has an "Add User" node and some "Users" nodes uder it(Siblings). I have a "Add/Edit User" form in the page, inside a panel inside a update panel. This form has a submit command button and the fields have required field validators. These validators are in a ValidationGroup with the submit button. It''s set up so that when a user clicks the "Add User" node, the form panel is made visible so that a new user can be added. When you click on a particular users node, the users information is loaded into the fields and the panel is set to visible so you can edit the users information.


Here's the issue:

When you select the "Add User" node on the tree the blank fields load and all is good. If after that you click on a users node, the users info is loaded into the fields as it should, and that update panel is updated, but all the validators fire. So, selecting a node in the treeview causes the validation to fire even though they are grouped with the Submit button. I expected the validation grouping would solve the issue, but it didn't. Now I'm stumped. Just staring at it.?Any ideas? Anyone?


Thanks,

CL

One issue could be that treeviews aren't supported in updatepanels... We have noticed some strange issues when we were trying to get one work. You may also want to make sure that everything else has causes validation set to false.
Thanks for your reply. I'll look into the causes validation thing and see if that works.
mdenn, you're a dang genius. That worked. Thanks a bunch.

A control with ID ImageButton5 could not be found for the trigger in UpdatePanel up1.

I have 20 ImageButtons on my page and UpdatePanel . In Update Panel Triggers i've added all this buttons

<asp:AsyncPostBackTriggerControlID="IB1"/>

<asp:AsyncPostBackTriggerControlID="ImageButton1"/>

<asp:AsyncPostBackTriggerControlID="ImageButton2"/>

<asp:AsyncPostBackTriggerControlID="ImageButton3"/>

<asp:AsyncPostBackTriggerControlID="ImageButton4"/>

<asp:AsyncPostBackTriggerControlID="ImageButton5"/> Here I am Getting this Message

A control with ID 'ImageButton5' could not be found for the trigger in UpdatePanel 'up1'.

4 first Image Buttons update panel can find but after 5th no ..... What can be the problem ??

Please post your source code so we can see it in the context of the entire page.


Post some more code details, So it will be more helpful


<asp:UpdatePanelID="up1"UpdateMode="Conditional"runat="server"ChildrenAsTriggers="True">

<Triggers>

<asp:AsyncPostBackTriggerControlID="IB1"/>

<asp:AsyncPostBackTriggerControlID="ImageButton1"/>

<asp:AsyncPostBackTriggerControlID="ImageButton2"/>

<asp:AsyncPostBackTriggerControlID="ImageButton3"/>

<asp:AsyncPostBackTriggerControlID="ImageButton4"/>

<asp:AsyncPostBackTriggerControlID="ImageButton5"/>

</Triggers>

<ContentTemplate>

This is Update Panel code :

and there are just 20 ImageButtons on form ... thats all code


Seeing the rest of the page would really help.


Hi,

Thank you for your post!

Where is yourImageButton5? Is it in anothernaming container?

You cann't set button that is in a different naming container with the updatepanle as a trigger. That is the answer.

If you really want it to be a trigger, this is the workaround:

Programmatically addingAsyncPostBackTrigger controls is not supported. Find out the control viafindcontrol method, then use theRegisterAsyncPostBackControl(Control) method of theScriptManager control to programmatically register a postback control, and then call theUpdate() method of theUpdatePanel when the control posts back.

If you have further questions,let me know!

Best Regards,


Thanks a lot for your reply ...

I am sorry for my dummy knowlege but what does it meananothernaming container ?

my button is on the same page in same <table> but in different <tr> , this could be a problem ?


Hi,

Thank you for your feedback!

Seehttp://msdn2.microsoft.com/en-us/library/system.web.ui.inamingcontainer.aspx.

INamingContainer Interface

Identifies a container control that creates a new ID namespace within aPage object's control hierarchy. This is a marker interface only.

Naming container is a container contorl which implemented the INamingContainer Interface, contorls in Naming container 2 have different ID namespace with contorls in Naming container 1, so ....

If you have further questions, let me know.

Best Regards,

A ContentTemplate must be specified for UpdatePanel

Why has the Update Panel been changed in the new release so that a ContentTemplate must be specified. In my project i'd like to dynamically add controls to the panel in a user control.

Is this something that that is permanent?

Do not confuse the ASP.NET Panel control with the ASP.NET "Atlas"UpdatePanel.The ASP.NET "Atlas"UpdatePanel is a new control able to do partial rendering

In typical ASP.NET 2.0 applications, when a postback occurs, the page is re-rendered. This causes the page to flash in the browser. On the server, during postback, the page lifecycle executes. This ultimately raises the control event that caused the postback and runs the event handler (for example, a Button control's Click handler).

The ASP.NET "Atlas"UpdatePanel control eliminates the full page refresh. TheUpdatePanel control is used to mark a region in the page that will be updated when a postback occurs, but without the traditional postback behavior in the client. On the server, the page still handles the postback and runs normally, such as raising event handlers. But during the final rendering of the page, only the regions defined byUpdatePanel controls are created. This is referred to aspartial rendering.

Hope this helps

Irinel


I have a webpart server control class that i have extended. i'd like to add a update panel around the contents of the webpart so i can derive from this new class which has all the functionaly of webpart but its contents is with in an update panel.

I'd this like to add webparts derived from this extended class and add them dynamically to page via database.

I was having problems with the fact that u can not directly add controls to an update panel by adding controls i've solved this problem by deriving a class from ITemplate and then adding the template to the content template of the update panel.

I now have the problem the following problem

"The UpdatePanel 'Update' was not present when the page's InitComplete event was raised. This is usually caused when an UpdatePanel is placed inside a template. "

which i'm not saw how to resolve.

I've had success with a update panels dynamically around dynamically added webpartzones with in the onpreint event.

Any help would be appreciated.

Thanks

Paul

A bug? None-Stop Timer~~Need Help!

I placed a timer in an update panel, and add a trigger to the update panel. when a button clicked the trigger raised and the timer enabled, once again clicked the button, the timer have should be stopped, but it still works. click again! It seems there's a new timer and the old timer works, too~~~~

It is a bug? the following is the code.

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

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

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True">
</atlas:ScriptManager>
<div>
<atlas:UpdatePanel ID="upTimer" runat="server" EnableViewState="True" Mode="Conditional">
<ContentTemplate>
<atlas:TimerControl ID="timerProgress" runat="server" Enabled="false" EnableViewState="False" Interval="1000" OnTick="timerProgress_Tick">
</atlas:TimerControl>
</ContentTemplate>
<Triggers>
<atlas:ControlEventTrigger ControlID="cmdStart" EventName="Click" />
<atlas:ControlEventTrigger ControlID="cmdCancel" EventName="Click" />
</Triggers>
</atlas:UpdatePanel>
<atlas:UpdatePanel ID="upProgress" runat="server" EnableViewState="True" Mode="Conditional">
<ContentTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ContentTemplate>
<Triggers>
<atlas:ControlEventTrigger ControlID="timerProgress" EventName="Tick" />
<atlas:ControlValueTrigger ControlID="timerProgress" PropertyName="Interval" />
</Triggers>
</atlas:UpdatePanel>
<atlas:UpdatePanel ID="upButtons" runat="server" Mode="Conditional">
<ContentTemplate>
<asp:Button ID="cmdStart" runat="server" EnableViewState="False" OnClick="cmdStart_Click"
Text="开始上传" />
<asp:Button ID="cmdCancel" runat="server" OnClick="cmdCancel_Click" Text="取消上传" Visible="False" />
</ContentTemplate>
<Triggers>
<atlas:ControlEventTrigger ControlID="cmdStart" EventName="Click" />
<atlas:ControlEventTrigger ControlID="cmdCancel" EventName="Click" />
</Triggers>
</atlas:UpdatePanel>

</div>
</form>
</body>
</html>
=========================================

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void cmdStart_Click(object sender, EventArgs e)
{
cmdStart.Visible = false;
cmdCancel.Visible = true;
timerProgress.Enabled = true;
}
protected void cmdCancel_Click(object sender, EventArgs e)
{
cmdStart.Visible = true;
cmdCancel.Visible = false;
timerProgress.Enabled = false;

}
protected void timerProgress_Tick(object sender, EventArgs e)
{
CheckBox1.Checked = !CheckBox1.Checked;
}
}

I am having the same problem. The timer cannot be turned off - even if the timer itself is placed inside the updatepanel. Often what you wanna do is have the update panel update every x seconds while some task is running, and then be turned off.

Any suggjestions on how to disable the timer? - (or is this a bug) ?


There are several issues with the TimerControl and partial rendering. I solved the problem by writing a custom control. Copy the code from this snippet to a file in your App_Code directory

using System;using Microsoft.Web.UI.Controls;namespace CustomControls{ /// /// Summary description for StoppableTimer /// public class StoppableTimer : TimerControl { public StoppableTimer() { } protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (this.Page.IsPostBack) { this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "TimerStop", "Web.Application.findObject('" + this.ClientID + "').set_enabled(" + (this.Enabled ? "true" : "false") + ");" , true); } } protected override void RenderScript(Microsoft.Web.Script.ScriptTextWriter writer) { writer.WriteStartElement("timer"); writer.WriteAttributeString("id", this.UniqueID); writer.WriteAttributeString("interval", this.Interval.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteAttributeString("enabled", this.Enabled.ToString()); writer.WriteStartElement("tick"); writer.WriteStartElement("postBack"); writer.WriteAttributeString("target", this.UniqueID); writer.WriteAttributeString("argument", string.Empty); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndElement(); } }}
Next register this custom control as a tag and use it.
<%@. Page Language="C#" AutoEventWireup="true" CodeFile="TimerTest.aspx.cs" Inherits="Default2" %><%@. Register TagPrefix="AppCode" Assembly="App_Code" Namespace="CustomControls" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"> </atlas:ScriptManager> <div> <atlas:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <span id="Span1" runat="server"></span> <AppCode:StoppableTimer runat="server" ID="Timer1" Interval="1000" Visible="true" OnTick="Timer1_Tick"> </AppCode:StoppableTimer> </ContentTemplate> <Triggers> <atlas:ControlEventTrigger ControlID="Timer1" EventName="Tick" /> </Triggers> </atlas:UpdatePanel> </div> </form></body></html>

When the issues with Atlas timer control are fixed in a release you can simply replace AppCode:StoppableTimer with atlas:TimerControl.


how to use your custom control in an application like : to fetch the data without postback at a regular interval and depending upon some condition need to stop the timer so that we can stop data fetching operation?

Jaideep


Nice pice of code Rama Krishna.

I tried to modify your component to Marts CTP, but I cant get it to work. Writing the following:

writer.WriteAttributeString(

"id", UniqueID);

Will result in a assertion error from atlas - stating that the control is dublicate (it is not - looking at the source) - and the script (set_enabled part) will set the xml enabled = false - but the update continues. Im having a hard time - anyone got this to work?

Here is my (not functional) Marts CTP version of the control - what am I doing wrong here ?

public

classStoppableTimer :TimerControl {public StoppableTimer() {

}

protectedoverridevoid OnPreRender(EventArgs e) {base.OnPreRender(e);if (Page.IsPostBack) {

Page.ClientScript.RegisterStartupScript(Page.GetType(),

"TimerStop","Sys.Application.findObject('" + UniqueID +"').set_enabled(" + (Enabled ?"true" :"false") +");"

,

true);

}

}

protectedoverridevoid RenderScript(Microsoft.Web.Script.ScriptTextWriter writer) {

writer.WriteStartElement(

"timer");

writer.WriteAttributeString(

"id", UniqueID);

writer.WriteAttributeString(

"interval", Interval.ToString(System.Globalization.CultureInfo.InvariantCulture));

writer.WriteAttributeString(

"enabled", Enabled.ToString());

writer.WriteStartElement(

"tick");

writer.WriteStartElement(

"postBack");

writer.WriteAttributeString(

"target", UniqueID);

writer.WriteAttributeString(

"eventArgument",string.Empty);

writer.WriteEndElement();

writer.WriteEndElement();

writer.WriteEndElement();

}

}


This solved my problem of the timer not writing out an ID when its created on the server. Also I'm very happy there is a script writer.

protected override void RenderScript(Microsoft.Web.Script.ScriptTextWriter writer)

Thanks.


Thank you everyone who contributed in previous posts

I've got this workn with March CTP in internet explorer 6

Its mostly the same but my main goal was to create a timer on the server and be able to stop and start it on the client and there was no clientid there. Argh I already have vb in app_code so its now vb and it has a Namespace to match my other Atlas stuff.

Heres the prerender routine. First off I'm adding a script to use on the client to start and stop the timer. Since I check the result of the findobject I don't bother checking for postback and I use enabled.tostring.tolower instead of the inline if.

Imports

Microsoft.VisualBasic

Imports

Microsoft.Web.UI.Controls

Namespace

DWS.Web.AtlasProtectedOverridesSub OnPreRender(ByVal eAs System.EventArgs)IfNotMe.Page.ClientScript.IsClientScriptBlockRegistered(Me.GetType,"DWSTimerStartStop")ThenDim sbAsNew StringBuilder

sb.Append(

"function DWSTimerStartStop (clientid,boolstop){")

sb.Append(

"var s = Sys.Application.findObject(clientid);")

sb.Append(

"if (s) {s.set_enabled(boolstop)};")

sb.Append(

"}")

Page.ClientScript.RegisterClientScriptBlock(

Me.GetType,"DWSTimerStartStop", sb.ToString,True)EndIfIfNotMe.Page.ClientScript.IsStartupScriptRegistered(Me.GetType,"DWSTimerStartStop" &Me.ClientID)ThenDim sbAsNew StringBuilder

sb.Append(

"DWSTimerStartStop(""" &Me.ClientID &""",")

sb.Append(

Me.Enabled.ToString.ToLower)

sb.Append(

");")

Page.ClientScript.RegisterStartupScript(

Me.GetType,"DWSTimerStartStop" &Me.ClientID, sb.ToString,True)EndIfMyBase.OnPreRender(e)EndSub

I think everyone had the renderscript. I put a MS timercontrol on the page and checked the render xml-script side by side (view source on browser) so I could compare the groups control output with that of Atlas.

ProtectedOverridesSub RenderScript(ByVal writerAs Microsoft.Web.Script.ScriptTextWriter)

writer.WriteStartElement("timer")

writer.WriteAttributeString("id",Me.ClientID)

writer.WriteAttributeString("interval",Me.Interval.ToString(System.Globalization.CultureInfo.InvariantCulture))

writer.WriteAttributeString("enabled",Me.Enabled.ToString())

writer.WriteStartElement("tick")

writer.WriteStartElement("postBack")

writer.WriteAttributeString("target",Me.UniqueID)

writer.WriteAttributeString("eventArgument",String.Empty)

writer.WriteEndElement()

writer.WriteEndElement()

writer.WriteEndElement()

EndSub

EndClass

I was going for server so here's a server example

PartialClass C_photo

Inherits DWS.Web.WebParts.WebPartBasectrl

'here it is

PrivateWithEvents txAsNew DWS.Web.Atlas.TimerControl

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load

'Set timer interval

tx.ID =

"dan1"

tx.Interval = 5000

Me.Controls.Add(tx)'Here are my two controls that operate on the client. They use the script generated in the control prerender.

Dim xAsNew HtmlButton

x.InnerText ="stop"

x.Attributes.Add(

"onclick","DWSTimerStartStop(""" & tx.ClientID &""",false)")Me.Controls.Add(x)Dim yAsNew HtmlButton

y.InnerText =

"start"

y.Attributes.Add(

"onclick","DWSTimerStartStop(""" & tx.ClientID &""",true)")Me.Controls.Add(y)EndSub

EndNamespace

And of course the group goal of having the enabled works too.

Protected

Sub Button1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles Button1.ClickIf Button1.Text ="Stop"Then

Button1.Text =

"Play"

tx.Enabled =

FalseElse

Button1.Text =

"Stop"

tx_Tick(sender, e)

tx.Enabled =

TrueEndIfEndSub

Thank you to whoever started this thread.

Thank you to the scriptwriter example.

Thank you eventArgument fix.

DWS


I just started using Atlas with the April CTP. I'd really like to have the ability to cancel the timer. I can't seem to get this to work though. I converted the code in the previous post to C#. I think that went ok.

Should the Timer control be incuded in the UpdatePanel or should it be outside the panel?

Thanks,

Andy


hello.

i'd put it out...btw, there's another thread on this forum (it's huge, maybe 3 pages now) that shows another option to clear a timer from a page.


Rama Krishna, this was very helpful!

I modified the code a bit to work with the April CTP, and added a few client side APIs to pause, resume and toggle the timer. Here is the modified code:

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;
using Microsoft.Web.UI.Controls;

namespace Yadda.Web.UI.WebControls {

/// <summary>
/// This is a workaround for an issue in the June CTP of Atlas - the provided TimerControl cannot be stopped or paused
/// by the client.
/// This is based on code from Rama Krishna, http://forums.asp.net/1222935/ShowPost.aspx
/// This one inherits from the provided TimerControl and fixes these issues.
/// Once this is fixed in Atlas this control should be removed and replaced with the standard one.
/// Client-side API:
/// TimerToggle(clientID) - toggles the timer between off and on state
/// TimerPause(clientID) - temporarily pause the timer; no events will be fired until TimerResume will be called.
/// TimerResume(clientID) - resumes a paused timer; Can be safely called multiple times.
/// </summary>public class TimerControlWithPause : TimerControl {
public TimerControlWithPause() {
//
// TODO: Add constructor logic here
//}protected override void OnPreRender(EventArgs e) {
base.OnPreRender(e);
// Render client-side APIs:this.Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(),"TimerToggle",
"function TimerToggle(clientId) {" +
"var timerObj = $object(clientId); " +
"if (!timerObj) return; " +
"if (timerObj.get_enabled()) TimerPause(clientId); else TimerResume(clientId); " +
"}" +
"function TimerPause(clientId) {" +
"var timerObj = $object(clientId); " +
"if (!timerObj) return; " +
"timerObj.set_enabled(false); " +
"}" +
"function TimerResume(clientId) {" +
"var timerObj = $object(clientId); " +
"if (!timerObj) return; " +
"timerObj.set_enabled(true); " +
"}",
true);// This will sync the client side state with the server state on postbacks:if (this.Page.IsPostBack) {
this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(),"TimerStop",
(this.Enabled ?string.Format("TimerResume('{0}');",this.ClientID) :string.Format("TimerPause('{0}');",this.ClientID))
,true);
}
}

protected override void RenderScript(Microsoft.Web.Script.ScriptTextWriter writer) {
writer.WriteStartElement("timer");
writer.WriteAttributeString("id",this.ClientID);
writer.WriteAttributeString("interval",this.Interval.ToString(System.Globalization.CultureInfo.InvariantCulture));
writer.WriteAttributeString("enabled",this.Enabled.ToString());
writer.WriteStartElement("tick");
writer.WriteStartElement("postBack");
writer.WriteAttributeString("target",this.UniqueID);
writer.WriteAttributeString("eventArgument",string.Empty);
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndElement();
}
}
}


Nice solution yanivgolan. This is working great.


I'm still waiting for Visual Web Developer to finish installing- I have no experience with Atlas and very little ASP.net experience and this thread is a little old, but it sounds like the timer thing is a bug that will be fixed in future versions of Atlas, so a lot of these workarounds seem a little convoluted... wouldn't the following workaround be good enough for most applications until Atlas fixes itself??:

protected void timerProgress_Tick(object sender, EventArgs e)
{

If (timerProgress.Enabled )
CheckBox1.Checked = !CheckBox1.Checked;
}


When I use code similar to this... (I've actually tried it a few different ways now...) It compiles and runs fine under VS 2005's internal web... But when I try to publish it and run it from any other stand alone web server (including the IIS on the same box the VS 2005 is on) I get an error when I try to load the page:

Compilation Error

Description:An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message:CS0117: 'ASP.default_aspx' does not contain a definition for 'myTimer_Tick'

Source Error:


Line 16: </atlas:ScriptManager>
Line 17: <div>
Line 18: <AppCode:StopableTimer runat="server" ID="myNewTimer" Enabled="false" Interval="900" OnTick="myTimer_Tick">
Line 19: </AppCode:StopableTimer>


Does anyone have any sort of suggestion as to why this may be happening, and how I might fix it..?

Any thoughts or suggestions would be very much appreciated!

Thanks! ;)

- Andrew

hello.

according to the error message, it seems like the myTimer_Tick method isn't being found. where have you defined it?


Hello,

Thanks for the reply...

Of course... myTimer_Tick -has- to be defined, or it would not run under Visual Studio, right? ;)

But you're right in that it seems it isn't being found.. but why not..?

It is defined in the Default.aspx.cs file - referenced as the "CodeFile" at the top of the Default.aspx file. Here's the top two lines of my Default.aspx file:

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@. Register TagPrefix="AppCode" Namespace="MyCustomControls" %
The Namespace is where the StoppableTimer is that's similar to the code a few posts above, which I got from:

http://runithomsen.blogspot.com/2006_03_01_runithomsen_archive.html

Do I need to define it some other way..? It still doesn't make sense (to me!) that it works under Visual Studio's internal web browser, but not when I publish it to an IIS server. :(

Any thoughts or suggestions would be appreciated! :)

Thanks!

Cheers

- Andrew