|
Rank: Member Groups: Member
Joined: 10/1/2007 Posts: 17
|
I am working on creating a class registration page where based on data read in from the database, the page displays all available classes for a given day.
This information is being dumped into a table, with a checkbox so the user can select what class they want to attend.
Currently Im using all server side calls (no javascript) as I need to do a bunch of checking to see if the class is available, if they already don't have a conflicting class, ect..
The problem I am currently running into is if there is any lag, the page allows someone to do a rapid selection (select two checkboxes before the postback), and thus causing issues on the page.
I believe the callbackPanel is my answer, but I don't know what I need to set as the trigger, as I am dynamically creating the checkboxes when I build the table.
So I guess I have two questions, is CallbackPanel going to give me what I need, and how do I trigger the callbackpanel with a dynamically created checkbox?
Thanks
Edited to add, this is in vb.net.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi Chris,
The CallbackPanel should be fine for you. As for the trigger, you can set the parent control as a trigger, that way all child controls of that parent control will become trigger. For example, if you have link buttons in a DataGrid and you want all link buttons to trigger callback, you can set that DataGrid as a trigger. If you use it this way, the trigger control (in this case, the link buttons) must be a server control. For example, if you dynamically create HTML link elements instead of LinkButton control, the trigger won't work.
If you do need to create HTML link elements, you will need to make it to call eo_Callback, for example:
<a href="javascript:eo_Callback('Callback1', 'some_other_argument');">callback</a>
This way you will handle the Callback's Execute event instead of the trigger control's event because the trigger is not a control.
For your particular problem, you may want to set the CallbackPanel's AutoDisableContents to true. That way all contents of the CallbackPanel will be immediately disabled when the callback is in progress.
One thing that you want to pay extra attention is, if you trigger is a server control (for example, a LinkButton) and you do want to handle its server side event, you will need to recreate them when the page postbacks. This is true for any ASP.NET page, so it is not particular related to CallbackPanel at all. However it's often been overlooked when CallbackPanel is used.
Thanks
|
|
Rank: Member Groups: Member
Joined: 10/1/2007 Posts: 17
|
Oh excellent, let me give that a try.
|
|
Rank: Member Groups: Member
Joined: 10/1/2007 Posts: 17
|
Ok I have my table wrapped in a callbackpanel as shown below. Table10 is the table that I am filling with my class information. In that table I am adding to the first cell a checkbox named chk for each row of the table. I have some simple code in the callbackpanel1_execute function and I don't seem to ever hit it. I have tried leaving chk.postback on and off, neither seem to execute the callback trigger. You had mentioned in a link situation, calling javascript to execute the callback, Im not sure if I need to do that, nor how to tie that to a checkbox control.
Code: Visual Basic.NET
<eo:CallbackPanel ID="CallbackPanel1" runat="server" AutoDisableContents="true"
Triggers="{ControlID:Table10;Parameter:}" Width="760px">
<asp:Table ID="Table10" runat="server">
<asp:TableRow ID="TableRow66" runat="server" BackColor="LightGray">
<asp:TableCell ID="TableCell258" runat="server">Select</asp:TableCell>
<asp:TableCell ID="TableCell259" runat="server">Presentation</asp:TableCell>
<asp:TableCell ID="TableCell260" runat="server">Start Time</asp:TableCell>
<asp:TableCell ID="TableCell261" runat="server">End Time</asp:TableCell>
</asp:TableRow>
</asp:Table>
</eo:CallbackPanel>
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Can you post your code that add the checkbox?
|
|
Rank: Member Groups: Member
Joined: 10/1/2007 Posts: 17
|
In a nut shell:
chk.AutoPostBack = True chk.ID = iCount tcellChk.Controls.Add(chk) trow.Cells.Add(tcellChk) Table10.Rows.Add(trow)
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi Chris,
We looked into it and realized that the containing control must be an INamingContainer in order for the child control to trigger CallbackPanel (sorry about that!). The easiest way to get around this is to put the Table into a user control, then set the user control as a trigger. This would work because UserControl is an INamingContainer.
Other workarounds are also possible. For example, you can use an asp:Repeater control to enclose your table. This way you would need to data bind the repeater with an one item array so that your table got created once. You can also create a control that inherits from asp:Panel but implements INamingContainer and then enclose your table with it. Whatever way it is, the key is INamingContainer.
Thanks
|
|
Rank: Member Groups: Member
Joined: 10/1/2007 Posts: 17
|
hmm, can't say I have any idea currently how to do that, guess its google time.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi Chris,
If you are not sure, then using a UserControl is the easiest. Just create a user control, move the whole table into that user control, then set the user control as a trigger.
Thanks
|
|
Rank: Member Groups: Member
Joined: 10/1/2007 Posts: 17
|
Finally after trying to get the table to be recognized in the main form, I have my user control set up, and it looks like its firing just fine.
Now, I need to know what checkbox fired the event. Is there a way to know that?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Yes. You should be able to use Page.Request.Form["__EVENTTARGET"] to get the full client ID of your checkbox. Note the ClientID is derived from ID but they two are different.
|
|
Rank: Member Groups: Member
Joined: 10/1/2007 Posts: 17
|
Looks like its the usercontrol name $ the id that gets sent back.
So then one last (I think) question, any way I can easily check to see if the value of that checkbox is checked or not (true or false)?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Again check Page.Request.Form collection. You should see an item that is the same as the checkbox's ClientID (or derived from it) in the collection if the check box is selected. Otherwise it is not.
|
|
Rank: Member Groups: Member
Joined: 10/1/2007 Posts: 17
|
Got it, its working great, thanks.
Now, since Im no longer posting back on this page (ya!!), I have one other table thats being updated. Its a static table, and has no data behind it (its a "day at a glance").
I put it in another callbackpanel but now Im unsure what I should trigger off of. Since its loaded first on the page, if I try to use my usercontrol to trigger it, neither works. Is there a way in code I can cause the trigger?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Yes. For that you will need to take a look of eo_Callback function. The help file along with the sample project should provide enough information about how to use it. I am not exactly sure whether you need this though, as you have already experienced, using trigger control is much easier. So it always better if you can rely on that.
|
|
Rank: Member Groups: Member
Joined: 10/1/2007 Posts: 17
|
Heh, I just wrapped both tables in the first callbackpanel and it works.
I must say, you guys have gone above and beyond with your support today, thank you.
Chris.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Chris wrote:Heh, I just wrapped both tables in the first callbackpanel and it works.
I must say, you guys have gone above and beyond with your support today, thank you.
Chris. We like to hear that! Thanks for the compliment and do not forget to spread the word!
|
|