Showing posts with label dropdownlist. Show all posts
Showing posts with label dropdownlist. Show all posts

Saturday, March 24, 2012

UpdatePanel and Asynch trigger gives an error

I have 2 Update Panels "ajaxIssueSummary","ajaxCCPack".
"ajaxIssueSummary" contains a gridview "dgIssueSummary" which contains a DropDownlist "ddlIssueState" as a template field.
"ajaxCCPack" contains a gridview "dgCCPack".

<ajaxExt:UpdatePanel UpdateMode="Conditional" ID="ajaxIssueSummary" runat="server">
<ContentTemplate>

<asp:GridView ID="dgIssueSummary"
runat="server"
AutoGenerateColumns="False"
DataKeyNames="pkIssueTracker"
CellPadding="4"
ForeColor="#333333"
GridLines="Vertical"
SkinID="Fun"
Width="900px"
OnRowCreated="dgIssueSummary_RowCreated" >
<Columns>
<asp:BoundField DataField="pkCustomRule" HeaderText="pkCustomRule" InsertVisible="False"
ReadOnly="True" SortExpression="pkCustomRule" Visible="False" />
<asp:BoundField DataField="fkQuestionnaireField" HeaderText="fkQuestionnaireField"
SortExpression="fkQuestionnaireField" Visible="False" />
<asp:BoundField DataField="sInternalMessage" HeaderText="Internal Message" SortExpression="sInternalMessage" >
<ItemStyle Width="300px" />
</asp:BoundField>
<asp:BoundField DataField="sExternalMessage" HeaderText="External Message" SortExpression="sExternalMessage" >
<ItemStyle Width="300px" />
</asp:BoundField>
<asp:TemplateField SortExpression="sFriendlyName" Visible="False">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("sFriendlyName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblFriendlyName" runat="server" Text='<%# Bind("sFriendlyName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="pkIssueTracker" InsertVisible="False" SortExpression="pkIssueTracker" Visible="False">
<ItemTemplate>
<asp:Literal ID="lblpkIssueTracker" runat="server" Text='<%# Bind("pkIssueTracker") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:DropDownList ID="ddlIssueState" Runat="server" DataSourceID="IssuesStateDS" DataTextField="sIssueState" DataValueField="pkIssueState" SelectedValue='<%# Eval("pkIssueState") %>' AutoPostBack="true" OnSelectedIndexChanged="ddlIssueState_SelectedIndexChanged" >
</asp:DropDownList>
<asp:SqlDataSource ID="IssuesStateDS" runat="server" ConnectionString="<%$ ConnectionStrings:BritneyQuestionnaireDataConnectionString %>"
SelectCommand="SELECT [pkIssueState], [sIssueState] FROM [IssueState] WHERE pkIssueState in (1,3,6)"></asp:SqlDataSource>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>

</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<ajaxExt:AsyncPostBackTrigger ControlID="btnOrderGo" EventName="Click" />
<ajaxExt:AsyncPostBackTrigger ControlID="ddlDocument" EventName="SelectedIndexChanged" />
<ajaxExt:AsyncPostBackTrigger ControlID="btnUpdateAnswerBank" EventName="Click" />
</Triggers>
</ajaxExt:UpdatePanel>

<ajaxExt:UpdatePanel UpdateMode="Conditional" ID="ajaxCCPack" runat="server">
<ContentTemplate>

<asp:GridView ID="dgCCPack" runat="server" AutoGenerateColumns="False" AutoGenerateEditButton="True"
OnRowEditing="dgCCPack_RowEditing"
CellPadding="4"
ForeColor="#333333"
GridLines="Vertical"
OnRowCancelingEdit="dgCCPack_RowCancelingEdit"
OnRowUpdating="dgCCPack_RowUpdating"
SkinID="Fun" Width="900px">
<Columns>
<asp:TemplateField HeaderText="pkIssueTracker" InsertVisible="False" SortExpression="pkIssueTracker"
Visible="False">
<ItemTemplate>
<asp:Label ID="lblpkIssueTracker" runat="server" Text='<%# Bind("pkIssueTracker") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Internal Message" SortExpression="sInternalMessage">
<EditItemTemplate>
<asp:TextBox ID="ccEditInternalMessage" runat="server" Text='<%# Bind("sInternalMessage") %>' Width="300"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="ccInternalMessage" runat="server" Text='<%# Bind("sInternalMessage") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="300px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="External Message" SortExpression="sExternalMessage">
<EditItemTemplate>
<asp:TextBox ID="ccEditExternalMessage" runat="server" Text='<%# Bind("sExternalMessage") %>' Width="300" ></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="ccExternalMessage" runat="server" Text='<%# Bind("sExternalMessage") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="300px" />
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</ContentTemplate>
</ajaxExt:UpdatePanel>

***************************************************************
The task is: when "ddlIssueState" selected index changes I need to refresh "dgCCPack".
So this is what I did :

protected void dgIssueSummary_RowCreated(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddl = (DropDownList)e.Row.Cells[6].FindControl("ddlIssueState");
Microsoft.Web.UI.AsyncPostBackTrigger trigger = new Microsoft.Web.UI.AsyncPostBackTrigger();
trigger.ControlID = ddl.UniqueID.ToString();
trigger.EventName = "SelectedIndexChanged";
ajaxCCPack.Triggers.Add(trigger);
}
}
catch (Exception ex)
{
throw ex;
}
}

But I am getting the following error :
A control with ID 'ddlIssueState' could not be found for the trigger in UpdatePanel 'ajaxCCPack'.

Please suggest the right way of doing this

You can not trigger the?asynchronous?postback events of?the asp:DropDownList named "ddlIssueState" which?is?in?the?"ajaxIssueSummary"?
UpdatePanel?from?another?UpdatePanel?called?"ajaxCCPack".
Here is a solution for you to solve the issues.
Place two asp:GridViews in the same asp:UpdatePanel and set?asp:PostBackTrigger?to?asp:GridView?named?"dgIssueSummary" through the triggers of the asp:Updatepanel named "ajaxIssueSummary".When?the?SelectedIndexChanged?event?of?the?asp:DropDownList?named?
"ddlIssueState"?happens, try?to?trigger?the?second?asp:GridView?named?"dgCCPack".It?should?work?fine.
Wish this can help you.

updatepanel and dropdownlist: invalid postback

This just isnt my day, i just took a whole 15 minutes to write down my problem and the stupid site comes up wioth a oops something went wrong (we lost your post)Angry. I'll be real quick on explaining this time then...

If you look here: http://forums.asp.net/t/1112220.aspx

That's what happened to me today, I'm forced to put update panels everywhere so my data keeps displaying on postbacks. I have a drowpdownlist in an updatepanel in a formview with autopostback set to true that triggers the onselectedindexchanged event. I basically just load some info according to the selected item in a css info box there, so no big deal. If I change my selection once, it works fine, however, after that ALL postback events on my page come up with a javascript alert beginning with "Invalid postback or callback." and then tells me to register the data to the event or something like that. I have tried registering for asynchroneous postback, I tried clientscript.registerforeventvalidation... Nothing works.

I read that I had to register for all possible data that could be displayed in my dropdownlist. However, the dropdownlist content is loaded once (when the button to display the formview is clicked) and won't ever change back until the user cancels or reloads another one. so it shouldnt be a problem...

what am I missing? I don't want to turn enabledeventvalidation to false cuz the way my application is built, it would cut out validation from 80% of my pages or so, which isnt cool. I could take out ALL the update panels, but that's not really a good idea either. So please help, any input is appreciated.

Thanks a lot for your time guys.

You can turn off validation for just that one page. You don't have to turn it off for the whole site. Also the cause of this error can be a number of problems from multiple form tags ect. so check everything.


ok now thats kinda rough... I tried turning the event validation to off for just the page... and now no matter what I do, I can't seem to get my dropdownlist to fire its selectedindexchanged event anymore. I tried adding the event handler in the page load, I tried moving the handler in the code, I turned the validation back on. Nothing works anymore...

I made a small test by moving the dropdown outside of the formview. It works -_-' (ok so i get a bunch of object reference not set to an instance of an object because of how i was getting the reference to my dropdownlist in the formview (findcontrol...), but the event is fired.) Knowing it worked before this morning, even though i was getting this error, what in the world happened? I tried

protected void Page_Load(object sender, EventArgs e)
{
//...
if (MultiView1.ActiveViewIndex == 0 && fvAddEditCat.CurrentMode == FormViewMode.Insert)
{
//add the event handler to the ddl DropDownList ddl = (DropDownList)fvAddEditCat.FindControl("ddlCategories");
ddl.SelectedIndexChanged +=new EventHandler(ddlCategory_SelectedIndexChanged);
}
}

protected void ddlCategory_SelectedIndexChanged(object sender, System.EventArgs e)
{
LoadCategoryInfo();
}

protected void LoadCategoryInfo()
{ ... }


and here is the markup of the formview and the insertitemtemplate

<asp:FormView ID="fvAddEditCat" runat="server"
DataKeyNames="Data_Element_Category_Id" DataSourceID="odsDataElemCat"
DefaultMode="Edit" OnItemInserting="fv_ItemInserting" Visible="false"
OnItemCommand="fv_ItemCommand" OnItemInserted="fv_ItemInserted"
EnableViewState="False" OnItemUpdated="fv_ItemUpdated">
<InsertItemTemplate>
<table class="DataEntryForm">
<tr class="DataEntryTitle">
<td colspan="2">
Data Element Category
</td>
</tr>
<tr>
<td>
<span style="color:Red;">*</span>Category
</td>
<td>
<ajax:UpdatePanel ID="upnl2" runat="server" UpdateMode="Conditional"><ContentTemplate>
<asp:DropDownList ID="ddlCategories" runat="server" AutoPostBack="true" />
<a href="#" class="info"> ? <span class="info" style="width: 320px;">
<table>
<tr>
<td>
Description:
</td>
<td><asp:Label ID="lblCatDesc" runat="server" /></td>
</tr>
<tr>
<td>
Memo:
</td>
<td><asp:Label ID="lblCatMemo" runat="server" /></td>
</tr>
<tr>
<td>
Status Code:
</td>
<td><asp:Label ID="lblCatStatusCode" runat="server" /></td>
</tr>
<tr>
<td>
Creation Date:
</td>
<td><asp:Label ID="lblCatCreateDate" runat="server" /></td>
</tr>
</table>
</span></a>
</ContentTemplate></ajax:UpdatePanel>
</td>
</tr>
<tr>
<td>
Memo
</td>
<td>
<asp:TextBox ID="txtMemo" runat="server" TextMode="multiline" Columns="40" rows="3" text='<%# Bind("Data_Element_Category_Memo")%>'/>
</td>
</tr>
<tr>
<td style="width: 150px;"><span style="color:Red;">*</span>Status Code:</td>
<td style="width: 200px;">
<asp:TextBox ID="txtStatusCode" runat="server" Text='<%# Bind("Status_Code")%>' />
<asp:RangeValidator id="RangeValidator2" runat="server" controlToValidate="txtStatusCode"
ErrorMessage="Data Element Category Sstatus Code must be a number between 0 and 255, or nothing."
Display="Dynamic" CssClass="MsgVal" ValidationGroup="EditDEC" MinimumValue="0" MaximumValue="255" Type="Integer" />
<asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server" controlToValidate="txtStatusCode"
ErrorMessage="Status Code must be entered."
Display="Dynamic" CssClass="MsgVal" ValidationGroup="EditDEC" />
</td>
</tr>
</table>
<asp:Button ID="btnInsert" runat="server" CommandName="Insert" Text="Insert" ValidationGroup="EditDEC" />
<asp:Button ID="btnCancel" runat="server" CommandName="Cancel" text="Cancel" CausesValidation="false" />
</InsertItemTemplate>
note that it all worked until i added that dropdownlist event and had to wrap the ddl and the label into their own updatepanel because otherwise the postback would clear the update panel it was into.

the event name is still in the onselectedindexchanged in the markup... I don't have any secondary form tags or the likes... All I have is a serious feeling that formviews are more trouble than they seem to be useful. I built a few forms with the same kind of functionality before (without the formview) and although the object assignation from all the textboxes is tedious, it works and i don't get stupid ajax errors amd i dont lose my events all the time.

I'm goign to try to remove the event handler and the update panel and rework it from scratch... i've had to do that with another control I worked on and "ajaxified", and if it still doesn't work, I'll probably just give up and use a normal form, unless someone here comes up with the miracle answer im looking for.

Thanks for trying to help.


I think I need vacations... This was too simple a change so i could think of it before now (15 minutes before I wouldve decided to go back to the normal form). Basically, I have the formview static on the page, however, its set to invisible on the first page load, and is only made visible through a button click. However, when I change the dropdownlist index, this button is not clicked again, and so, even if the formview's insert template stays there thanks to the update panel, the code doesnt think it exists. The result: the dropdownlist's event handler is nothing then too. Now, on to how I fixed it? I called the function that shows the form on the page_load when the mode is on insert.

Talk about losing my time on stupid problems... Once again, thanks for trying to help ^^ (I still don't know how it worked before, and what exactly was causing this ajax error... but it works now so lets just hope i never come accross it again)

UpdatePanel and DropDownList with AutoPostBack=true

Using Atlas January CTP

I can't get a DropDownList with AutoPostBack=true to work inside an UpdatePanel. Is that a known limitation? Any solution/workaround?

The AutoPostBack does not work; the Web page does not post back.

Thanks.What do you mean that the Web Page does not postback? Are you saying that you can't get the client-callback to work for your DDL within the UpdatePanel? It works fine for me and others on this forum. Can we see you code?

I managed to get this to work. I had to:

1. Change my UpdatePanel mode to "Conditional"

2. Add a trigger like:

<atlas:ControlEventTriggerControlID="ddlMyDropDown"EventName="SelectedIndexChanged"/>


Thanks for taht post I was having the same problem with Atlas March CTP.
This should be in the dowcumentation.
I will blog about this.
Hey Duede theres is not Such Property atlas:ControlEventTrigger Please Help with the Solution i am trying to update 2nd dropdown list from 1st dropdown list
Try this:

<atlas:ControlValueTrigger ControlID="DropDownList1" PropertyName="SelectedValue" /
Put this under the <trigger> tag, which should be under the update panel for the 2nd dropdown list.