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

Wednesday, March 28, 2012

Dynamic Extenders in AJAX beta - Please Help!

Ive managed to update my site to AJAX beta and ive got everything up and running again except for dynamic extenders! Please can anyone help, this driving me nuts!!!

Im trying to create a dynamic list of news feeds, organised by category. Where each category has its own collapsible extender.

In ATLAS i could just do this:

<asp:RepeaterID="RepeaterNewsCategorys"runat="server"DataSourceID="SqlAllNewsSourceCategorys">

<ItemTemplate>

<trclass="ItemTitle">

<tdalign="left">

<b><asp:LabelID="lblNewsCategory"runat="server"><%#Eval("Name")%></asp:Label></b>

</td>

<tdalign="right">

<asp:ImageID="imgNewsCategory"runat="server"/>

</td>

</tr>

<tr>

<tdcolspan="2">

<asp:PanelID="PanelNewsCategory"runat="server">

<asp:CheckBoxListID="chkNewsCategoryFeeds"runat="server"DataTextField="Name"DataValueField="ID"OnDataBound="chkNewsFeeds_DataBound"OnSelectedIndexChanged="chkNewsFeeds_SelectedIndexChanged"></asp:CheckBoxList>

</asp:Panel>

<AtlasControl:CollapsiblePanelExtenderID="CollapsibleNewsCategory"runat="Server">

<AtlasControl:CollapsiblePanelPropertiesTargetControlID="PanelNewsCategory"ExpandControlID="imgNewsCategory"CollapseControlID="imgNewsCategory"Collapsed="True"TextLabelID="lblNewsCategory"

ImageControlID="imgNewsCategory"ExpandedImage="../Images/Icons/Collapse.jpg"CollapsedImage="../Images/Icons/Expand.jpg"/>

</AtlasControl:CollapsiblePanelExtender>

</td>

</tr>

</ItemTemplate>

</asp:Repeater>

Nice and easy and everything worked fine. Now after updating to AJAX beta, none of the collapsible extenders are rendered and none of the images are loaded.

I read another post about dynamic extenders, and tried to create the extenders in the repeaters ItemDataBound.

<asp:RepeaterID="RepeaterNewsCategorys"runat="server"DataSourceID="SqlAllNewsSourceCategorys">

<ItemTemplate>

<trclass="ItemTitle">

<tdalign="left">

<b><asp:LabelID="lblNewsCategory"runat="server"><%#Eval("Name")%></asp:Label></b>

</td>

<tdalign="right">

<asp:ImageID="imgNewsCategory"runat="server"/>

</td>

</tr>

<tr>

<tdcolspan="2">

<asp:PanelID="PanelNewsCategory"runat="server">

<asp:CheckBoxListID="chkNewsCategoryFeeds"runat="server"DataTextField="Name"DataValueField="ID"OnDataBound="chkNewsFeeds_DataBound"OnSelectedIndexChanged="chkNewsFeeds_SelectedIndexChanged"></asp:CheckBoxList>

</asp:Panel>

</td>

</tr>

</ItemTemplate>

</asp:Repeater>

Code Behind:

ProtectedSub RepeaterNewsCategorys_ItemDataBound(ByVal senderAsObject,ByVal eAs System.Web.UI.WebControls.RepeaterItemEventArgs)Handles RepeaterNewsCategorys.ItemDataBound

'Find Controls

Dim holdExpandLabelAs Label

Dim holdExpandImageAs Image

Dim holdExpandPanelAs Panel

Dim holdExpandExtenderAs CollapsiblePanelExtender

holdExpandLabel =CType(e.Item.FindControl("lblNewsCategory"), Label)

holdExpandImage =CType(e.Item.FindControl("imgNewsCategory"), Image)

holdExpandPanel =CType(e.Item.FindControl("PanelNewsCategory"), Panel)

'Create CollapsiblePanelExtender object

holdExpandExtender =New CollapsiblePanelExtender()

'Set properties of CollapsiblePanelExtender

holdExpandExtender.ID ="cpe" & holdExpandPanel.ID

holdExpandExtender.TargetControlID = holdExpandPanel.ID

holdExpandExtender.CollapseControlID = holdExpandImage.ID

holdExpandExtender.ExpandControlID = holdExpandImage.ID

holdExpandExtender.ImageControlID = holdExpandImage.ID

holdExpandExtender.CollapsedImage ="../Images/Icons/Expand.jpg"

holdExpandExtender.ExpandedImage ="../Images/Icons/Collapse.jpg"

holdExpandExtender.Collapsed =True

'Add CollapsiblePanelExtender

e.Item.Controls.Add(holdExpandExtender)

But still nothing. Please can anyone help, ive run out of ideas and im tempted to go back to ATLAS at this point!

Please see the "Known Issue" post at the top of this forum. It addresses this issue.

Dynamic controls in Ajax UpdatePanel

I created a dynamic button and want to add the button click event as update panel trigger.
But does not work. Any idea ?
Thanks

String clientID;

protectedvoid Page_Init(object sender,EventArgs e)

{

Button btn =newButton();

btn.Text ="Write Hello";

btn.Click +=newEventHandler(Button1_Click);

Page.Form.Controls.Add(btn);

clientID = btn.ClientID;

}

protectedvoid Button1_Click(object sender,EventArgs e)

{

Label1.Text ="hello";

}

protectedvoid Page_PreRender(object sender,EventArgs e)

{

AsyncPostBackTrigger trigger =newAsyncPostBackTrigger();

trigger.ControlID = clientID;

trigger.EventName ="Click";

UpdatePanel1.Triggers.Add(trigger);

}

Try this instead of your code.

protected void Page_Load(object sender, EventArgs e)
{

Button btn = new Button();
btn.Text = "Write Hello";
btn.ID = "Button1";
btn.Click += new EventHandler(Button1_Click);
UpdatePanel1.ContentTemplateContainer.Controls.Add(btn);
//Page.Form.Controls.Add(btn);
// clientID = btn.ClientID;

AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = "Button1";
trigger.EventName = "Click";
UpdatePanel1.Triggers.Add(trigger);

}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "hello";

}


This works. But actually what I want is : when click on the Button1, the the UpdatePanel1 will be hide and a UpdateProgress (with a loading image) will show until the loading complete. And the UpdatePanel1 will show again with some updated info.


Try this code. I dont think its a perfect way. I am using some hack mentioned in

http://dotnetslackers.com/community/blogs/simoneb/archive/2006/09/02/481.aspx

<%@. 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">
protected void Page_Load(object sender, EventArgs e)
{

Button btn = new Button();
btn.Text = "Write Hello";
btn.ID = "Button1";
btn.Click += new EventHandler(Button1_Click);
UpdatePanel1.ContentTemplateContainer.Controls.Add(btn);
//Page.Form.Controls.Add(btn);
// clientID = btn.ClientID;

AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = "Button1";
trigger.EventName = "Click";
UpdatePanel1.Triggers.Add(trigger);
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "hello";
System.Threading.Thread.Sleep(4000);
}
</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 ID=sc1 runat=server ScriptPath="ScriptLibrary"></asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server"Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgressrunat=server AssociatedUpdatePanelID=Updatepanel1 ID=up1DynamicLayout=true DisplayAfter=4 >
<ProgressTemplate>
<table>
<tr>
<td>
Loading......
</td>
</tr>
<tr>
<td>
<img src="http://pics.10026.com/?src=" alt="image" />
</td>
</tr>
</table>
</ProgressTemplate>
</asp:UpdateProgress>
</div>
</form>
</body>
</html>
<script language=javascript>
Sys.Application.add_load(ApplicationLoadHandler)
function ApplicationLoadHandler(sender, args)
{
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(HidePanel);
Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(ShowPanel);
}
function HidePanel(sender, args)
{
for (var j = sender._updatePanelIDs.length - 1; j >= 0; j--)
{
varupdatePanel =document.getElementById(sender._uniqueIDToClientID(sender._updatePanelIDs[j]));
var postbackElement = args.get_postBackElement();
if(updatePanel && updatePanel.contains(postbackElement)) {
updatePanel.style.visibility='hidden';
}
}
}
function ShowPanel(sender, args)
{
var updatedPanels = args.get_panelsUpdating();
for (var j = updatedPanels.length - 1; j >= 0; j--)
{
updatedPanels[j].style.visibility='visible';
}
}
</script>


Is it posible to put the button outside the UpdatePanel ?

UpdatePanel1.ContentTemplateContainer.Controls.Add(btn);

Because I would not want the button to be hide while 'Ajax'.

Thanks

Dynamic Content events needed as Trigger events

Is there a way to add triggers at runtime? I have a bunch of dynamic images that show that I want to add the click events as triggers to update a larger image. Thanks.

I don't think you can add triggers dynamically (maybe it's possible, I don't see a way however).

The best way to procede depends on your needs. If *all* you need is your UpdatePanel to update() when some image is clicked and you don't know what / how many images at runtime, you could just dynamically add the image controls to the UpdatePanel's container controls, and give each image an onclick attribute with a postback reference. Something like this:

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="false" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><script runat="server"> protected void Page_Load(object sender, EventArgs e) { Image Image1 = new Image(); UpdatePanel1.ContentTemplateContainer.Controls.Add(Image1); Image1.ID = "Image1"; Image1.ImageUrl = "img.png"; Image1.Attributes.Add("onclick", ClientScript.GetPostBackClientHyperlink(Image1, "Image1PostBack")); }</script><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server" > <ContentTemplate> asdf </ContentTemplate> </asp:UpdatePanel> </form></body></html>
 

If the dynamic images need to be outside the UpdatePanel you want to trigger - does it matter to your update which dynamic image was clicked? Depending on that, there are other possibillities.

Ben


Ben,

Thanks for the post. I figured it out. You can add triggers to the updatepanel.

Dim x As New AsyncPostBackTriggerx.ControlID = <name of control that will be doing the update>x.EventName = "Click"update.Triggers.Add(x)

Just make sure this runs even after a post back.

Dynamic Cascading DropDownLists

Hi All,

Thx, for your help in advance. I have 2 update panels, UpdatePanel1 and UpdatePanel2 respectively.

UpdatePanel1 has 'n' dynamically generated DropDownLists with their CascadingDropDown extender.

UpdatePanel2 has a TextBox and a Button.

When the last dynamically generated dropdownlist is clicked (a selectedIndexChanged event is fired) where I clear the TextBox. Since they are dynamically generated, I always add the dynamic dropdownlists (and extenders) on the OnInit event of the page. My problem is that when the Button is clicked, the DropDownLists may be still loading their values (some default selected values, selected via cascadingDropDown.SelectedValue property), so on postback the SelectedIndexChanged event is fired, before the OnClick event of the button takes place. This causes the following scenario:


1. DropDownLists Dynamically Added

2. User Enters Text (DropDownLists StillLoading their default values)

3. User Clicks Button (DropDownLists StillLoading their default values)

4. SelectedIndexChanged Fired (this clears the textbox , so I can't read the value in step 2)

5. Button's OnClick Fired

6. When I try to read the TextBox text, it has been cleared in step 4.

Am I doing something rong? Why both events(SelectedIndexChanged and OnClick) are fired when I'm expecting only the OnClick event to happen. Any thoughts of how to avoid this?


Thx




Hi Maxdmvp,

First, we suggest that you should set your UpdatePanel's UpdateMode="Conditional". This will avoid that one UpdatePanel cause to another UpdatePanel's refreshment.

maxdmvp:

4. SelectedIndexChanged Fired (this clears the textbox , so I can't read the value in step 2)

5. Button's OnClick Fired

You should use a debugging tool such as Web Development Helper and FireBug to find out the reason.

Best regards,

Jonathan


Thx for your response Jonathan...


The problem that I describe rises when you try to edit. Imagine this scenario: The dropDownList's (updatePanel1) are properties of a product, when you finish selecting you have assembled a product model number. When you enter the page to edit how many items of this product you want in your cart (textBox and button in UpdatePanel2), you already know the product's properties (you preselect the values in the dropDownList's), but while these are loading it is posible for you to enter a number in the textBox and click the "add" button in UpdatePanel2. In this scenario the "SelectedIndexChanged" is fired before the "OnClick" of the button, when I just expect the "OnClick" to be fired. As you can see it doesn't matter, in this case, if the UpdateMode="Conditional".

Also thx for your advice on user FireBug, I use it often but I'm not sure how can it help me debug this problem... could you please provide a further advice?

Thx



Hi Maxdmvp,

I'm not clear enough now, so would you please give me a sample now? Please do me a favor that remove all the unnecessary part before you post it. Thanks.

Best regards,

Jonathan.

Dynamic AJAX loaded control with updatepanel problem.

Hi,

Hopefully someone can shed some light onto whether this can be done as I am not having much luck so far.

I have a page with an Update panel. On this page I have a button that through an asynchronous postback loads a usercontrol (lets call it A). The usercontrol that is loaded (A) also has an update panel and a button. When the button on the usercontrol (A) is clicked I want it to load another usercontrol (B) through ajax into the updatepanel.

So we have nested usercontrols and updatepanels - the page hosts Usercontrol A which hosts usercontrol B.

Loading the Usercontrol A is working without a problem and I am persisting the loaded control by use of viewstate and reloading the controls in the OnInit event.

However clicking the button on usercontrol A will not load the usercontrol (B). This is because the click event behind the button does not fire.

I would be grateful if anyone has tried this and found a way of making it work.

Thanks

Hi,

Can you post a simple and clear sample here?


Hi, nzwy1p

Since you dynamically add the first(parent) user control, you should add it to the PlaceHolder in the Page_Load event every time instead of adding it just in theButton's Click event. Because when you only add it in theButton's Click event, after post back, theuser controlwill disappear. And itdoesn't land on your breakpoint inButton1_Click inUserControlA.ascx,There is non UserControlA when your postback by clickingButton1 in theUserControlA.

Try this:

Page:

<%@. 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">
protected void Button1_Click(object sender, EventArgs e)
{
UpdatePanel1.Update();
}

protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
UserControl uc;
uc = (UserControl)LoadControl("UserControlA.ascx");
PlaceHolder1.Controls.Add(uc);
}
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" />
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
</form>
</body>
</html>

UserControlA:

<%@. Control Language="C#" ClassName="UserControlA" %>

<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
UserControl uc;
uc = (UserControl)LoadControl("UserControlB.ascx");
PlaceHolder1.Controls.Add(uc);
}
</script>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" />
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button in UserContorlB" />

UserControlB:

<%@. Control Language="C#" ClassName="UserControlB" %>

<script runat="server">

</script>

<asp:Label ID="Label1" runat="server" Text="UserContorlB's content"></asp:Label>

For more help, You can see theselink:http://forums.asp.net/t/1108394.aspx

Let me know if you need more info

Monday, March 26, 2012

dynamic addhandler not working in update panel

hi all,

i have designed a page, with a place holder in it, the placeholder is inside a updatepanel, the placeholder gets filled with images at load, and when i click the viewcart button it get filled with the image information with few dynamic buttons, i have added addhandler for those buttons, but they are not firring up. i am pasting my code here if some one can help me plz.

Dim

updateorderlnkbtn AsNew button ' this is done at the genearal section of the page to make it globalAddHandler updateorderlnkbtn.click,AddressOf cancelBtn_click ' at page init

please help me

hi all

i have done some other changes to the code but still the same problem, if any one of you can give me some idea that would be highly appreciated

thanks


hi all

I have done some thing here that my 5 static buttons that are created at runtime are working fine now but the problem is with the dynamic table, i am placing a delete button in the dynamic table now the dynamic table is created at runtime and i want the delete button to remove the row.

the other buttons (5 buttons) code is something like this , i have wrote the code behing the load, the problem is that i can't wrote the dynamic table code behind the load, the dynammic table is created when i click a viewcart button

please help

Dummie question about UpdatePanel

I have a problem which can be sumarized in the following:

- UpdatePanel with a button

- Text box outside update panel

- Want button "click" method to update the text in the textbox.

How is this possible? I have read some suggestions (Luis Abreu suggests a "dummie button" with _DoPostBack. The problem is I am very new to asp so have no idea about where and how to place the code and have no idea about how javascript works in the page, so I did not underestand that solution nor how to implement it...

Any help is appreciated!

I've say you should put the things that you want updated inside the UpdatePanel, with a Trigger on the button click event. The button does not have to reside inside the UpdatePanel. So, your example should be reversed, with the UpdatePanel with a textbox and a button outside the UpdatePanel.
Hi,

quick example that illustrates what senyl said above:

<%@. 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"> protected void btnUpdate_Click(object sender, EventArgs e) { txtDate.Text = DateTime.Now.ToString(); }</script><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="scriptManager" runat="server" EnablePartialRendering="true"></atlas:ScriptManager> <atlas:UpdatePanel ID="UpdatePanel1" runat="server"> <Triggers> <atlas:ControlEventTrigger ControlID="btnUpdate" EventName="Click" /> </Triggers> <ContentTemplate> <asp:TextBox ID="txtDate" runat="server"></asp:TextBox> </ContentTemplate> </atlas:UpdatePanel> <asp:Button ID="btnUpdate" runat="server" Text="Update" OnClick="btnUpdate_Click" /> </form></body></html>

senyl:

I've say you should put the things that you want updated inside the UpdatePanel, with a Trigger on the button click event.  The button does not have to reside inside the UpdatePanel.  So, your example should be reversed, with the UpdatePanel with a textbox and a button outside the UpdatePanel.

The problem is that my real scenario is slightly more complicated:

One of the UpdatePanels is a GridView with a column which is a button for "add new row". As it is embedded in the gridview, I can't take it out.

The other updatePanel is a FormView that becomes visible when the former button is clicked. It then shows insert boxes and it has a "insert" button that also needs to be in the formview...to insert the record.

Well, my best advice is to watch that video by Scott Gutherie on the Atlas homepage, where he uses a gridview and a formview with atlas. You could also make the updatepanels render always, and code the triggers properly.

Hope this helps (it probably won't, but it is my best guess)

Saturday, March 24, 2012

DropdownList Update

Hi,

I have modified the sample program for Data Demo. I've used ASP.NET AJAX....I have a dropdownlist and a gridview inside an updatepanel. Also, im connected thru a objectdatasource. the dropdownlist gets value from objectdatasource1. The value comes from a distinct state from the author table while the gridview is connected to objectdatasource2. The value for objectdatasource2 comes from auther table where state = to the dropdownlist selected value.

Now what i want to achieve is that if i edit the state in the gridview my dropdownlist will be automacatically refresh. I tried adding <asp:AsyncPostBackTriggerControlID="GridView1"EventName="SelectedIndexChanged"/> to the updatepanel. I was able to save the changes but the dropdownlist doesnt.

Thanks

2lits

When both the controls that cause a refresh to the updatepanel are inside it, you can use the ChildrenAsTriggers property of the UpdatePanel. Set it to True, and your Dropdownlist should be re-binding.

Thanks


The ChildrenAsTriggers was already set to true but still my dropdownlist is not re-binding...any other thoughts? thanks!


Is your updateMode on conditional basis?

Thanks


it was set to always.

Thanks


I'd say step one is to remove the UpdatePanel and see if this is working in regular postback mode. If it is, then we need to figure out what's going wrong with your UpdatePanels.

I'd want to see some code at that point... is there just one UpdatePanel on the page? Is the GridView inside it? Is the DropDownList?


Yes There is only one Update Panel. The Gridview , dropdownlist, and the sources are inside it.

here's my code :

<formid="form1"runat="server"><asp:ScriptManagerID="ScriptManager1"runat="server"/> <divtitle="My First AJAX-Enabled Data Driven Page"><asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="Conditional"><ContentTemplate> <asp:DropDownListID="DropDownList1"runat="server"DataSourceID="ObjectDataSource1"DataTextField="State"DataValueField="State"AutoPostBack=True></asp:DropDownList><asp:GridViewID="GridView1"runat="server"AllowPaging="True"AutoGenerateColumns="False"DataSourceID="ObjectDataSource2"AllowSorting="True"DataKeyNames="AuthorID"><Columns><asp:CommandFieldShowEditButton="True"ShowSelectButton="True"/><asp:BoundFieldDataField="AuthorID"HeaderText="AuthorID"InsertVisible="False"ReadOnly="True"SortExpression="AuthorID"/><asp:BoundFieldDataField="FirstName"HeaderText="FirstName"SortExpression="FirstName"/><asp:BoundFieldDataField="LastName"HeaderText="LastName"SortExpression="LastName"/><asp:BoundFieldDataField="City"HeaderText="City"SortExpression="City"/><asp:BoundFieldDataField="State"HeaderText="State"SortExpression="State"/><asp:BoundFieldDataField="Zip"HeaderText="Zip"SortExpression="Zip"/><asp:BoundFieldDataField="Phone"HeaderText="Phone"SortExpression="Phone"/></Columns></asp:GridView><br/> <asp:ObjectDataSourceID="ObjectDataSource2"runat="server"OldValuesParameterFormatString="{0}"SelectMethod="GetData"TypeName="DataSet2TableAdapters.SelectAuthorsTableAdapter"UpdateMethod="Update"><SelectParameters><asp:ControlParameterControlID="DropDownList1"Name="State"PropertyName="SelectedValue"Type="String"/></SelectParameters><UpdateParameters><asp:ParameterName="AuthorID"Type="Int32"/><asp:ParameterName="FirstName"Type="String"/><asp:ParameterName="LastName"Type="String"/><asp:ParameterName="City"Type="String"/><asp:ParameterName="State"Type="String"/><asp:ParameterName="Zip"Type="String"/><asp:ParameterName="Phone"Type="String"/></UpdateParameters></asp:ObjectDataSource><asp:ObjectDataSourceID="ObjectDataSource1"runat="server"OldValuesParameterFormatString="original_{0}"SelectMethod="GetDataState"TypeName="DataSet2TableAdapters.StateListTableAdapter"></asp:ObjectDataSource><br/></ContentTemplate><Triggers><asp:AsyncPostBackTriggerControlID="DropDownList1"EventName="SelectedIndexChanged"/><asp:AsyncPostBackTriggerControlID="GridView1"EventName="RowUpdated"/></Triggers></asp:UpdatePanel> </div></form>
The updatemode is set to always. I just test it to conditional.

The updatemode is set to always. I just test it to conditional.

Thanks


And what's supposed to happen to the DropDownList when you edit the GridView?

Did you try removing the UpdatePanel? I have a feeling this isn't working with regular postbacks either and doesn't really have to do with AJAX, since your UpdatePanel code looks correct.


I should be able to see the updates in the state. example if I change the state from MI to NW upon save i should be able to see NW added in the dropdownlist. It is working on the regular postback...

Steve Marx:

I have a feeling this isn't working with regular postbacks either and doesn't really have to do with AJAX, since your UpdatePanel code looks correct.

This is to do with AJAX. When the DropDownList is binded declaratively, the list wont get refreshed on the triggers of the updatepanel. You need to explicitly bind the dropdownlist in the events specified on the updatepanel. But if have you had used the same ObjectSource for both the GridView and DropDownList, then sure the list gets updated.

Since the OP is working on the same database table, one ObjectDataSource is enough and when the GridView UpdateCommand is called, the data for the DropDownList is pulled again.

Thanks


e_screw, I don't quite understand... the databinding should work exactly the same way in a regular postback and an async postback. I'm still having trouble figuring out how this can work without the UpdatePanel but fail with it.

Certainly the DropDownList has to be bound again in the event handler, but what does that have to do with AJAX?


yes..thats also my understanding. How does the updatepanel rebind the data?

Thanks so much!


Steve Marx:

... the databinding should work exactly the same way in a regular postback and an async postback. I'm still having trouble figuring out how this can work without the UpdatePanel but fail with it. Certainly the DropDownList has to be bound again in the event handler, but what does that have to do with AJAX?

I am not sure though (still learning AJAX), the DataBinding of the controls (set declaratively using DataSourceID) will be started before the PreRender event of the page and not sure if the necessary client-scripts for that will be injected into the page by AJAX. I have checked with a different ObjectDataSource (each for Dropdownlist and GridView), and there was no client-script generated for the DropDownList unless there was explicit binding. When you are using the same ObjectDataSource for both the controls, there was client-script inject for both even if there was no explicit binding.

Thanks

Dropdownlist is flickering During Asynchronous Postback

I have placed dropdownlist along with some other controls in an Update panel.During Async Postback, the dropdownlist is flickering. Can any one help me to avoid the flickering of Dropdownlist

Anything in the update panel may flicker. If you don't want something to, you may want to take it out of the update panel. You can use it as a trigger if you are changing something based of the selected index when it changes.

I have noticed this as well. I tried to figure it out for a day or so and I'm taking a break from it. Hopefully someone will answer.

I don't see this behaviour with text boxes though...


It could also be more noticeable if you have a large number of items in the dropdown and more noticeable if they are bound to it. As I said in my previous reply, you can remove it from the update panel if you do not need to change the dropdown's contents by placing it outside the update panel.

Dropdownlist inside a User Control (all inside an updatePanel)

Hi there!

I have a dropdownlist with autopostback=true

The dropdownlist is inside a User control dinamically generated inside an update panel.

When I select a different item from the dropdownlist... "DropDownList1_SelectedIndexChanged" and I try to get the SelectedValue, I always get 0. While debuggin I could discover that the number of Items inside the dropdownlist was 0! (and obbiously the dropdownlist was charged with data)

The incredible thing is that after the first postback, I can select items from the dropdownlist and the SelectedIndexChanged gives me the correct SelectedValue!

Someone can help on this?

Many thanks,

Jbmixed

The problem was that I was doing the dopdownlists databind from a public property (I was getting a list of objects).

Now I am only stablishing the property, and I wait to the Load event to do the databind.

I hope this helps other people.

dropdownlist inside a update panel is not updating

Hello,
I have a update panel and inside that panel I have three items, dropdownlist, text box and button.
Dropdownlist is being bound to select statement (SqlDatasource) which retrieve list of boxes borrow by department.
Text box is used to updated the information for person name who returned the box.
Button is used when I want to update the information for a retunbox.in the button event handler I update the status of box from borrow to return with the name of the return person and display the information result to end user for success of failure.

I can see the sauces information on the gui and also see the in the database it is updating.
When I refresh the page it remove that box number from the dropdownlist but not when I click the button to update the information. I have set the trigger for updatepanel to conditional mode with button click.

I also try to programatically updated the dropdownlist (both when first time it load the page and on clicking the button) but it still didn't work.

Any help would be really appreciated.

Thanks

F5 refresh doesnot support in Ajax and there is no need for the trigger as the button is already inside the update panel since all child controls are trigger by default

rohit


Thanks.

But the problem still remains same, dropdownlist is not updated once the button is clicked and it has changed the status from borrowed to retuned in the database. Dropdownlist still show the box number as borrowed box.


I assume your button click calls a function.

In that case try to call the update function of the updatepanel.

e.g. <asp:UpdatePanel ID="MyUpdatePanel" .........

Button Click Function:

MyUpdatePanel.Update();

If it's not working, post your HTML here so others can help.

Aeires.


No, this doesn't work.

Here is the code:

<asp:UpdatePanel ID="updatePanelBorrow" runat="server">
<contenttemplate>

<asp:Panel id = "plborrrow" runat="server">

<asp:DropDownList onblur="ResetColor()" id="ddlQABoxList" onfocus="ChangeColor()" tabIndex=3 runat="server" Width="154px" ToolTip="Select SafeGuard No to Borrow it" AppendDataBoundItems="True" CausesValidation="True"><asp:ListItem Value="-1">Choose a SafeGuard</asp:ListItem></asp:DropDownList>

<asp:Textbox id="txtname" runat="server"/>

<asp:Button id="btnSaveBorrow" tabIndex=8 onclick="btnSaveBorrow_Click" runat="server" Text="Save Borrow Info" Width="111px" SkinID="TopPanelSkinID" ToolTip="Update Borrow information for the Safeguard box or QA Box"></asp:Button

</asp:Panel>
</contenttemplate>

</asp:UpdatePanel>

Here is code : first to bind dropdownlist (it is basically box numbers)

public void GetQABoxList()
{
_connection = new SqlConnection(_connString);
//The command object for sql statement
_command = new SqlCommand();
try
{
_connection.Open();
_command.Connection = _connection;
_command.CommandText = "spListOfQABoxes";
_command.CommandType = CommandType.StoredProcedure;

//Execute the insert statemtent

dataAdapter = new SqlDataAdapter();
dataAdapter.SelectCommand = _command;
dataAdapter.TableMappings.Add("Table", "[QA Box]");

DataSet dataset = new DataSet();
dataAdapter.Fill(dataset);

ddlQABoxList.DataSource = dataset.Tables["[QA Box]"].DefaultView;
ddlQABoxList.DataTextField = "boxNo";
ddlQABoxList.DataValueField = "boxNo";
ddlQABoxList.DataBind();

}
catch (Exception exp)
{
Trace.Write(exp.Message);
}
finally
{
_command.Dispose();
_connection.Close();
}
}

Code for button click:

protected void btnSaveBorrow_Click(object sender, EventArgs e)
{
lblMessage.Visible = false;
lblMessage.Text = "";
String boxno = ddlQABoxList.SelectedItem.Text;


_connection = new SqlConnection(_connString);

//The command object for sql statement
_command = new SqlCommand();
try
{
_connection.Open();
_transaction = _connection.BeginTransaction();
_command.Transaction = _transaction;
_command.Connection = _connection;

_command.CommandType = CommandType.StoredProcedure;
_command.CommandText = "spUpdateBorrowBoxInfo";

//Execute the insert statemtent
int val = _command.ExecuteNonQuery();
if (val > 0)
{
plReturn.Visible = false;
lblMessage.Visible = true;
lblMessage.Text = "Borrow information for QA Box # " + boxno + " has been Updated";

// ddlQABoxList.DataSource = dsBorrowBox;
// ddlQABoxList.DataBind();

txtBorrowedName.Text = "";
txtContents.Text = "";
}
_transaction.Commit();
// GetQABoxList();
DataBindDept();
}
catch (Exception exp)
{
lblMessage.Visible = true;
lblMessage.Text = exp.Message.ToString();
Page.SetFocus(ddlQABoxList);
Trace.Write(exp.Message);
}
finally
{
_command.Dispose();
_connection.Close();
}
// GetQABoxList(); use these two lines to enforce to update dropdownlist, NO SUCCESS!
// UpdatePanelAndDDL();
}

it looks like your problem is the dropdown is not refreshing after button click event, for that u need to call GetQABoxList() againg to refresh your dropdown list.

if this is not what you want then please explain your problem more clearly.

Rohit


Well, In the button_Click eventhandler I do call the GetQABoxList() as my primary concern is to get the latest list of qa boxes numbers to bind with dropdownlist. I commnet out this method but it was not working for me.

Thanks


try putting

ddlQABoxList.SelectedIndex = 0 at the end of GetQABoxList() and see if it works for you.


and one thing include

ddlQABoxList.Clear() in the the begining and

ddlQABoxList.SelectedIndex = 0 at the ending

inside the GetQABoxList() subroutine

and make sure there should not be any javascript error shown on ststus bar

i hope it helps

Rohit


Thanks

It work fine with the suggestion you gave.

dropdownlist in updatepanel1 to update updatepanel2

I have 2 ddl in an updatepanel1 and when one is selected, panel refreshes to load ddl #2 based on ddl1 choice. Works great, love it. Now can ddl2 change cause updatepanel2 to refresh?doh! nevermind... set update to conditional and call updatepanel.update from codebehind.

Dropdownlist in Update Panel

Hello everyone,

can you please tell me how to read or set SelectedValue property of a dropdownlist which is located inside a update panel? I can reference it with no problems but all I get is an empty string. Assigning a value doesn't do anything.

Thanks,
Radoslav

The same way you do when you have no UpdatePanel.

Post your code and let us see what you are doing wrong in !


It is same ,when u use it normally.

No extra code, just you have to declare the DropDownList inside the UpdatePanel


Can you provide some code details ...So it will be helpful.

<asp:ScriptManager ID="sm1" runat="server" EnablePartialRendering="true"></asp:ScriptManager>

<asp:UpdatePanel ID="UpdatePanel 1" UpdateMode="Conditional" runat="server">
<ContentTemplate>

<asp:DropDownList ID="itemNumber" runat="server" OnSelectedIndexChanged="itemNumber_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
</asp:DropDownList>

</ContentTemplate>
</asp:UpdatePanel>


Hope it will help youSmile

Wednesday, March 21, 2012

Dropdownlist flickers in IE6.0 inside Update panel

Hi All,

There is few drop down lists inside update panel on my page. As of now I cannot make these drop down lists stand outside Update panel. These Drop down list boxes flickers in IE6.0 whenever updatepanel containing them gets updated/refreshed while this works absolutely fine in fire fox, safari and IE7.0 beta version.

Is there some solution so that I can remove flickers from IE6.0 whenever update panel refreshes?

Thanks in Advance.

Can you post the source?


Hi,

The same issue has been discussed athttp://forums.asp.net/t/990278.aspx.

AsGarbin said in that thread:

This is not an issue of the Atlas framework. It is an issue in the way IE6 renders this type of boxed list.

Best Regards

DropDownList blinks on update in IE, not in FF

I have some pages with lots of updatepanels and stuff, and everything works fine. The only glitch: each and one drop down list inside an UpdatePanel disappears when the update of that particular UpdatePanel is initiated, and then reappears whan the update is finished. This is quite some annoying "blink" ! :)

The "blink" happens to all my ddl's inside update panels, irrespective of whether I actually change their values, rebind, whatever. But, it happens in only IE 6, but NOT in FF 2, where the updates runs smoothly, just as for all other components in all my update panels.

Anyone with any ideas on how to stop the ddl's from blinking in IE ?


Bump. Anybody facing similar problem ? Or rather, solutionSmile

DropDownList and AutoPostBack - Cannot Get the Actual Selected Value

Hello,

I have an update Panel that contains 2 DropDownLists, one of which has an AutoPostBack that eventually populates the other. The problem is that, although it works (the autopostback), i am always getting the last value added to the dropdown list by binding. THat is, i do not get the value that was selected when the event was fired. What could be wrong?

Can I see the code that you are using?. It seems to me that the selected value is being lost somewhere.

German Afanador

DropDownExtender: Refresh content

I have a drop-down extender, where the control ID references a Panel, which contains a TreeView. When I update the contents of the TreeView, and hit the drop-down button, the treeview shown is not refreshed. Is there any way that I can force a refresh?

Thanks - Bennie

How are you updating the treeview?

Ron


I am adding/removing tree nodes in a public method of the treeview.


Is the TreeView in an UpdatePanel? I'm trying to determine how all of the controls in question are composed. Could you post a snippit of the aspx?


this is the DropDownExtender:

<

ajaxToolkit:DropDownExtenderrunat="server"ID="DDE"TargetControlID="bookmarksTextLabel"DropDownControlID="DropPanel"/>

This is the DropPanel:

<asp:PanelEnableViewState="false"ID="DropPanel"ForeColor="#747678"runat="server"Style="text-align:left;padding-bottom:0px;padding-top:0px;margin-bottom:0px;margin-top:0px;display:none;visibility:hidden;">

<divstyle="border-color:Blue; border-width: 1px; border-style:solid; padding: 1px,1px,1px,1px;">

<bmt:BookmarksTreeid="tvBookmarks"runat="server"/></div></asp:Panel>

I tried enabling/disabling ViewState, but to no avail.


Does it work without using the drop-down extender? Please verify that the tree is populating correctly without the extender on the page. Is all of this content within an UpdatePanel?

It does work without the DropDownExtenter. No, there is no outer UpdatePanel.