Wednesday, March 28, 2012

Multiple Update Panels

Evening all,

As part of a larger development, I had an idea to develop a quiz using two update panels on one page. My idea was that the first update panel would have two dropdown lists binded to a database. Dropdown list 1 would hold the question. When the user selected an entry from the list, the 2nd dropdown list would populate with the answer. I added a delay using theSelectedIndexChanged event as follows:

Protected

Sub DropDownList1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)

System.Threading.Thread.Sleep(10000)

EndSub

I also added an updateProgress control to displayTime is running out.

Now the 2nd update panel had a simple text field and a button. The idea was that the user would try to beat the controls in updatePanel1 displaying the result. The user would enter their answer and click submit. This would then be compared to the actual write answer and a score would be recorded. I guess you have enough here to get my drift.

Now the big problem with this is that whilst updatePanel1 is updating, any event in updatePanel2 throws an error along the lines of: "Invalid Postback or callback argument".

From what I can gather from the complete error message, some sort of validation has been actioned and these simultaneous callbacks/postbacks can't happen. Is this just the way it is or is their a way around this. The error message makes reference to setting a pages element in the config file with the attribute "enableEventValidation=True". Now this stops me getting the error message in my page, but the lists in updatePanel1 don't display the right data.

Any tips on this or idea's on how to achieve my original concept would be hugely appreciated. I have included the relevant code below.

Kind regards

Mike

<

asp:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering=true/><div><asp:UpdatePanelID="UpdatePanel1"runat="server"RenderMode="Inline"UpdateMode="Conditional"><ContentTemplate><asp:DropDownListID="DropDownList1"runat="server"DataSourceID="AccessDataSource1"DataTextField="question"DataValueField="qID"AutoPostBack=TrueOnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList><asp:DropDownListID="DropDownList2"runat="server"DataSourceID="AccessDataSource2"DataTextField="answer"DataValueField="answer"OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged"AutoPostBack="True"></asp:DropDownList><asp:AccessDataSourceID="AccessDataSource2"runat="server"DataFile="~/App_Data/quiz.mdb"SelectCommand="SELECT * FROM [answer] WHERE ([qID] = ?)"><SelectParameters><asp:ControlParameterControlID="DropDownList1"Name="qID"PropertyName="SelectedValue"Type="Int32"/></SelectParameters></asp:AccessDataSource><asp:AccessDataSourceID="AccessDataSource1"runat="server"DataFile="~/App_Data/quiz.mdb"SelectCommand="SELECT * FROM [questions]"></asp:AccessDataSource><asp:UpdateProgressID="UpdateProgress1"runat="server"DisplayAfter="0"><ProgressTemplate>

Hurry up.......

</ProgressTemplate></asp:UpdateProgress></ContentTemplate>

</asp:UpdatePanel><br/><hr/><asp:UpdatePanelID="UpdatePanel2"runat="server"RenderMode="Inline"ChildrenAsTriggers=falseUpdateMode="Conditional">

<ContentTemplate>

<asp:ButtonID="Button1"runat="server"Text="Button"OnClick="Button1_Click"OnDataBinding="Button1_DataBinding">

</asp:button>

<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox></ContentTemplate></asp:UpdatePanel>

I seem to have solved the initial error message problem by nesting the updatePanels as opposed to having 2 independent panels. I'll continue with this and see how I get on.

Any tips from anybody else would be hugely appreciated.

Kin Regards

Mike

No comments:

Post a Comment