Sunday, March 11, 2012

Nested Update Panels - I am getting an error "The control property of UpdatePanelD victimD

At a glance I think you are making this harder on yourself than is necessary. What you could do is place the form for each individual victim into a User Control which holds all of the TextBoxes and other controls. Then you place that User Control into a Repeater control which is databound to a collection of your victims, which may be a DataSet populated from the database.

I would set it up as a cascade. The parent would hold the repeater and bind a unique key to each row. I would do the databinding through an ObjectDataSource and use the OnSelecting event handler to set the input parameters.

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.selecting.aspx

The end result would look something like this...

<asp:Repeater ID="rpt1" runat="server"><Item><uc1:VictimControl ID="vc1" runat="server" /></Item><asp:Repeater><ObjectDataSource ID="ods1" runat="server" OnSelecting="ods1_OnSelecting">

The ods1_OnSelecting event handler would set a property on the User Control, perhaps a property named VictimID. Then in the User Control for the VictimControl the data can be set in the form when you need it. At this point you are just dealing with a single victim form at a time instead of trying to get tricky with IDs as you described. When you are all done you can safely wrap the Repeater inside of an UpdatePanel.

This is a lot of detail. I wanted to give you something before I head out. Let me know if you do have any questions.


Thank you Brennan, for looking into for me.

But, I must not have been clear... I don't know how many victims there will be, etc.
An officer clicks on the "add victim" linkbutton, and I update the update panel with the additional fields needed for that new victim, then the officer can click that 'add victim' button N number of times.

In side the form field/HTML content (controls) I dynamically create, now I need to have a dynamically created UpdatePanel in that content. So I am dynamically creating a child UpdatePanel, in a Parent Update Panel when the Parent Update Panel is updated, from the 'add victim' button click.

Let me know if you need more details.

thanks


and to be clear.. the child update panel is independent of the parent ...

So imagine you are creating N number of victims, and each victim could have N number of Complaints, so after the parent update creates the new victim content, in there is another link button that allows the officer to add N number of Complaints for that created victim, and same for each victim created.. etc

Thanks


Hi,

This is a very complex problem:)

But finally,I fix it as follow:

<%@. Page Language="VB" %>

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

<script runat="server">
Private num As Integer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Page.IsPostBack Then
num = Integer.Parse(Hidden1.Text)
If num > 0 Then
Dim i As Integer = 1
While i <= num
addupdatepanel(i, System.Web.HttpContext.Current.Request.Form.Item("victimDOBtxt" & i).ToString)
i = i + 1
End While
End If
Else
Hidden1.Text = 0
End If

End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
addupdatepanel(num + 1, "")
Hidden1.Text = num + 1
End Sub

Private Sub addupdatepanel(ByVal lblCount As Integer, ByVal datestr As String)
Dim vDOBUpanel As New UpdatePanel
vDOBUpanel.ID = "victimDOBuPanel" & lblCount.ToString

vDOBUpanel.UpdateMode = UpdatePanelUpdateMode.Conditional

vDOBUpanel.ContentTemplateContainer.ID = "vdobCTid" & lblCount.ToString
Dim upanelLBL1 As New Label()

upanelLBL1.ID = "upanellbl1" & lblCount.ToString
upanelLBL1.Text = "<strong><span style=""font-size: 8pt; font-family: Tahoma"">DOB<br /> </span></strong> "

vDOBUpanel.ContentTemplateContainer.Controls.Add(upanelLBL1)

Dim vDOB As New TextBox
vDOB.ID = "victimDOBtxt" & lblCount.ToString
vDOB.Font.Size = victimDOBtxt.Font.Size

vDOB.MaxLength = victimDOBtxt.MaxLength

vDOB.Width = victimDOBtxt.Width

vDOB.Text = victimDOBtxt.Text

vDOBUpanel.ContentTemplateContainer.Controls.Add(vDOB)

Dim vdobIBTN As New ImageButton
vdobIBTN.ID = "victimCalImage" & lblCount.ToString

vdobIBTN.ImageUrl = "./images/smallcalendar.gif"

vdobIBTN.AlternateText = "Click to show calendar"

vDOBUpanel.ContentTemplateContainer.Controls.Add(vdobIBTN)

Dim upanelLBL2 As New Label()
upanelLBL2.ID = "upanellbl2" & lblCount.ToString

upanelLBL2.Text = "<br>"

vDOBUpanel.ContentTemplateContainer.Controls.Add(upanelLBL2)

Dim vicDOBextender As New AjaxControlToolkit.CalendarExtender
vicDOBextender.ID = "victimCalExtender" & lblCount.ToString

vicDOBextender.TargetControlID = "victimDOBtxt" & lblCount.ToString
vicDOBextender.PopupButtonID = "victimCalImage" & lblCount.ToString
vDOBUpanel.ContentTemplateContainer.Controls.Add(vicDOBextender)

Dim dobtr As New AsyncPostBackTrigger
dobtr.ControlID = "victimCalImage" & lblCount.ToString
vDOBUpanel.Triggers.Add(dobtr)

DCPVictim.Controls.Add(vDOBUpanel)
lblCount = lblCount + 1
End Sub
</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:Button ID="Button1" runat="server" Text="add victim" OnClick="Button1_Click" />
<br />
<asp:TextBox ID="victimDOBtxt" runat="server"></asp:TextBox><br />
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="Hidden1" runat="server"></asp:TextBox><asp:PlaceHolder ID="DCPVictim"
runat="server"></asp:PlaceHolder>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

If this help you,don't forget mark it as a answer.Thanks!

Let me know if you need more info.

No comments:

Post a Comment