/    Sign up×
Community /Pin to ProfileBookmark

add dynamic panels in ajax

Hi i am using ajax in asp.net

i am using tab container and tap panel controls.
i am trying to add tab panels dynamically on button click.
my form code is

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<%@ Register Assembly=”System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″
Namespace=”System.Web.UI” TagPrefix=”asp” %>
<%@ Register Assembly=”AjaxControlToolkit” Namespace=”AjaxControlToolkit” TagPrefix=”cc1″ %>

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

<html xmlns=”http://www.w3.org/1999/xhtml” >
<head runat=”server”>
<title>Untitled Page</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
&nbsp;</div>
<asp:ScriptManager ID=”ScriptManager1″ runat=”server”>
</asp:ScriptManager>
<cc1:TabContainer ID=”TabContainer1″ runat=”server” Width=”600″>
<cc1:TabPanel ID=”TabPanel1″ runat=”server” HeaderText=”tab1″>
<ContentTemplate>
<asp:Button ID=”asd” runat=”server” Width=”30″ />
</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID=”TabPanel2″ runat=”server” HeaderText=”tab2″>
</cc1:TabPanel>

</cc1:TabContainer>
<asp:Button ID=”Button1″ runat=”server” OnClick=”Button1_Click” Text=”Button” />

</form>

</body>
</html>

page code: (.cs file)

public partial class _Default : System.Web.UI.Page
{
int i = 0;
AjaxControlToolkit.TabPanel tp;

protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
i = i + 1;
tp = new AjaxControlToolkit.TabPanel();
tp.ID = “tp” + i.ToString();
Button b = new Button();
b.ID = “b” + i.ToString();
tp.Controls.Add(b);
tp.HeaderText = “i am new” + i.ToString();
TabContainer1.Controls.Add(tp);
}

}

i am able to add one tab dynamically but when i click the buttion second time, i am getting

“Specified argument was out of the range of valid values.
Parameter name: index “

error.

any help?

Thank you
Ravindar

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @ravindarjobs spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...