when i put the method only in page_load, which i dont want to control gets added and when i add anothe one the control does not dispear but a new one doesnt get added. i thought the problem was because my i++ is not actually working. I set the i=0 in page_load()
if(!this.ispostback){ i=0}
bacause ii thought when client request for a page it creates an object page then with i=0. then when user does a call back it uses this same object and uses the same i. But it seems as though it increments it from 0 -> 1 again.
heres some code. Would ther be a better way in doing what im trying to do. maybe im not understanding the concept correctly. an i do not want to call the method in page_load as I have varu\ious updatePanel on my page.
Now it adds the whilst running the method below to add content to panel. But doing this adds the first time u click button. the second button i click wants to validate the form.
-I have RequiredFieldValidator. but i set the validation group for them to "a". because they conflicted with my buttons before.
Therefore in the code below i set the validation group to "b". when i do not initialise this it still tries to validate the formjust as if i would not initialise it. so btn.validationgroup doesnt seem to be initialising.
All of this code is in a big registration form
I would like to know how i would get the newly created code by my addRowToPanel to panel methods. retrieve their vali\ues in c#
ControlCollection controls = Page.Controls
?
would that work. im not there yet, but i just want to know when i get there how i would do it.
Guculuma
Member
13 Points
36 Posts
Re: Updating a panel inside an updatePanel via a button click
Feb 21, 2012 02:58 PM|LINK
page postback?
you mean in the page_load?
when i put the method only in page_load, which i dont want to control gets added and when i add anothe one the control does not dispear but a new one doesnt get added. i thought the problem was because my i++ is not actually working. I set the i=0 in page_load() if(!this.ispostback){ i=0}
bacause ii thought when client request for a page it creates an object page then with i=0. then when user does a call back it uses this same object and uses the same i. But it seems as though it increments it from 0 -> 1 again.
heres some code. Would ther be a better way in doing what im trying to do. maybe im not understanding the concept correctly. an i do not want to call the method in page_load as I have varu\ious updatePanel on my page.
I tried -
taking everything out of the updatePanel -
like this
<table class="registrationTabel" >
<tr >
<td></td><td><asp:Label ID="Label9" runat="server" Text="Type" /></td><td><asp:Label ID="Label10" runat="server" Text="Subject Category" /></td><td><asp:Label ID="Label13" runat="server" Text="Subject" /></td><td></td>
</tr>
<tr>
<td style="text-align:right;"><asp:Label ID="Label16" runat="server" Text="Register 1:"/></td>
<td><asp:DropDownList ID="DropDownList3" Width="130" runat="server" /></td>
<td><asp:DropDownList Width="130" ID="DropDownList4" runat="server" /></td>
<td><asp:DropDownList Width="130" ID="DropDownList5" runat="server" /></td>
<td><asp:ImageButton ID="ImageButton2" OnClick="addASubjectType_Click" runat="server" /></td>
</tr>
<asp:PlaceHolder runat="server" ID="PlaceHolder1" >
</asp:PlaceHolder>
</table>
Now it adds the whilst running the method below to add content to panel. But doing this adds the first time u click button. the second button i click wants to validate the form.
-I have RequiredFieldValidator. but i set the validation group for them to "a". because they conflicted with my buttons before.
Therefore in the code below i set the validation group to "b". when i do not initialise this it still tries to validate the formjust as if i would not initialise it. so btn.validationgroup doesnt seem to be initialising.
All of this code is in a big registration form
I would like to know how i would get the newly created code by my addRowToPanel to panel methods. retrieve their vali\ues in c#
ControlCollection controls = Page.Controls
?
would that work. im not there yet, but i just want to know when i get there how i would do it.
protected void Page_Load(object sender, EventArgs e)
{
datareturner = new DataReturner();
if (!this.IsPostBack)
{
i = 0;
}
else {
addRowToPanel();
}
private void addRowToPanel()
{
i++;
Label label = new Label();
label.ID = "RegisterLabel" + i;
label.Text = "Register " + i + ": ";
DropDownList addDropListType = new DropDownList();
DropDownList addDropListSubjectCategory = new DropDownList();
DropDownList addDropListSubject = new DropDownList();
ImageButton imageBtn = new ImageButton();
imageBtn.ID = "addTypeSubject" + i;
imageBtn.Click += new ImageClickEventHandler(addASubjectType_Click);
imageBtn.ValidationGroup = "b";
myPlaceHolder.Controls.Add(new LiteralControl("<tr>"));
myPlaceHolder.Controls.Add(new LiteralControl("<td>"));
myPlaceHolder.Controls.Add(label);
myPlaceHolder.Controls.Add(new LiteralControl("</td>"));
myPlaceHolder.Controls.Add(new LiteralControl("<td>"));
myPlaceHolder.Controls.Add(addDropListType);
myPlaceHolder.Controls.Add(new LiteralControl("</td>"));
myPlaceHolder.Controls.Add(new LiteralControl("<td>"));
myPlaceHolder.Controls.Add(addDropListSubjectCategory);
myPlaceHolder.Controls.Add(new LiteralControl("</td>"));
myPlaceHolder.Controls.Add(new LiteralControl("<td>"));
myPlaceHolder.Controls.Add(addDropListSubject);
myPlaceHolder.Controls.Add(new LiteralControl("</td>"));
myPlaceHolder.Controls.Add(new LiteralControl("<td>"));
myPlaceHolder.Controls.Add(imageBtn);
myPlaceHolder.Controls.Add(new LiteralControl("</td>"));
myPlaceHolder.Controls.Add(new LiteralControl("</tr>"));
AsyncPostBackTrigger a = new AsyncPostBackTrigger();
a.ControlID = imageBtn.ID;
a.EventName = "Click";
UpdatePanelSubjectType.Triggers.Add(a);
// ImageButton1.Click -= new ImageClickEventHandler(addASubjectType_Click);
ImageButton1.Enabled = false;
// ImageButton1.Visible = false;
//addDropList.ID = ""
}
Thanx your help is greatly appreciated