This is a migrated thread and some comments may be shown as answers.

multiple rad menus dynamically in sharepoint

0 Answers 93 Views
Menu
This is a migrated thread and some comments may be shown as answers.
ravi
Top achievements
Rank 1
ravi asked on 08 Mar 2009, 02:42 PM

Hi,

I am working on a webpart where i need to create multiple controls dynamically. I need to create one table structure with rows and columns dynamically and i need to give Telerik RAD menu in every cell and in every cell there can be more than one different values and with different context menus (Telerik RAD menu).

So, my problem is that i created two rows and on click of either of the row (+, - Image button), there are inside row also. So, if i click on 1st row (or you can say + sign) i need to show the contents in that row with the context menu on each item.

If i click on 1st row (+ sign, to open inside row contents) i can create dynamic menus by defining it outside my Image Button Click event and it is working fine for me. But when i click on 2nd row (+ sign), it is doing the wrong thing for me. Because it is overwriting the 1st one row. It mean that if there are two RAD menu and there are two menu items in each menu. Then when i click on 1st row (+ sign), it is showing me correctly the 1st menu item. But if i click on 2nd row (+ sign) it is not showing me the 2ns menu items.

Can anyone suggest me any kind of solution. I think the problem with this is that every time when it calls the createchildcontrols function then for every click it is calling the (+,- click event) and oeverwriting the 1st menu.

So, please suggese me how to handle it.


Below is the code :----

 

namespace

 

Test

 

{

[

 

Guid("")]

 

 

 

public class TestPath : Microsoft.SharePoint.WebPartPages.WebPart

 

{

 

 

private RadAjaxPanel apnlCareerPath;

 

 

 

private AjaxLoadingPanel pnlLoading;

 

 

 

private HtmlGenericControl imgdvinner;

 

 

 

private Image imgLoading;

 

 

 

private HtmlGenericControl tblMain;

 

 

 

private StringBuilder strArrFunctionName;

 

 

 

private StringBuilder strArrMenuName;

 

 

 

private string ExternalMenuScript = "<script type='text/javascript'> ";

 

 

 

private const string ExternalMenuScriptKey = "ExternalMenuScriptKey";

 

 

 

private const string ExternalJSScript = "<script type='text/javascript' src='JSScript.js'></script> ";

 

 

 

private const string ExternalJSScriptKey = "ExternalJSScriptKey";

 

 

 

private Random ran;

 

 

 

private RadMenu TDContextMenu;

 

 

 

private RadMenu TDContextMenu1;

 

 

 

private RadMenuItem itmJob_Desc;

 

 

 

private RadMenuItem itmJob_Desc1;

 

 

 

private bool blntest = false;

 

 

 

public TestPath()

 

{

 

 

this.ExportMode = WebPartExportMode.All;

 

 

 

this.PreRender += new EventHandler(TestPath_ClientScript_PreRender);
}

 

 

 

protected override void CreateChildControls()

 

{

 

 

//ChildControlsCreated = true;

 

 

 

base.CreateChildControls();

 

SPWeb oWeb =

 

null;

 

oWeb = SPContext.Current.Web;

CreateWebUIWithAjax();

 

}

 

 

private void lnkplus_Click(System.Object sender, System.EventArgs e)

 

{

 

 

this.EnsureChildControls();

 

SPWeb oWeb = SPContext.Current.Web;

 

 

ImageButton lnkbt = (ImageButton)sender;

 

lnkbt.AlternateText =

 

"Zero";

 

 

 

ImageButton imgbtn = (ImageButton)(sender);

 

 

 

foreach (Control tblMaintesto in apnlCareerPath.Controls)

 

{

 

 

if (tblMaintesto.GetType().ToString().Contains("Table"))

 

{

 

 

if (tblMaintesto.ID.ToString().Contains("0") && imgbtn.ID.Contains("0"))

 

{

 

 

Table tblMaintest1 = ((Table)(tblMaintesto));

 

tblMaintest1.Rows[0].Cells[0].Text =

 

"Hello Again";

 

 

 

if (lnkbt.ImageUrl.Contains("minus"))

 

{

lnkbt.ImageUrl = oWeb.Url +

 

"/images/plus.gif";

 

tblMaintest1.Rows[0].Visible =

 

false;

 

}

 

 

else

 

 

 

 

{

lnkbt.ImageUrl = oWeb.Url +

 

"/images/minus.gif";

 

tblMaintest1.Rows[0].Visible =

 

true;

 

}

 

 

HtmlGenericControl htmlo = new HtmlGenericControl("div id='tst" + tblMaintest1.ID + "' onClick=\"helloworld(event);\" ");

 

htmlo.InnerHtml =

 

"MenuShow";

 

 

 

HtmlGenericControl html1 = new HtmlGenericControl("div id='tst1" + tblMaintest1.ID + "' onClick=\"helloworld1(event);\" ");

 

html1.InnerHtml =

 

"MenuShow 1";

 

 

TDContextMenu =

 

new RadMenu();

 

TDContextMenu.Skin =

 

"Default";

 

TDContextMenu.ID =

 

"Test" + tblMaintest1.ID;

 

TDContextMenu.IsContext =

 

true;

 

TDContextMenu.RadControlsDir =

 

"/_wpresources/RadControls/";

 

TDContextMenu.Skin =

 

"WebBlue";

 

 

 

//TDContextMenu.ContextMenuElementID = "none";

 

 

 

 

itmJob_Desc =

 

new RadMenuItem("Job Desc");

 

itmJob_Desc.Target =

 

"_blank";

 

itmJob_Desc.NavigateUrl =

 

"http://www.yahoo.com";

 

TDContextMenu.Items.Add(itmJob_Desc);

htmlo.Controls.Add(TDContextMenu);

tblMaintest1.Rows[0].Cells[0].Controls.Add(htmlo);

 

TDContextMenu1 =

 

new RadMenu();

 

TDContextMenu1.Skin =

 

"Default";

 

TDContextMenu1.ID =

 

"Test1" + tblMaintest1.ID;

 

TDContextMenu1.IsContext =

 

true;

 

TDContextMenu1.RadControlsDir =

 

"/_wpresources/RadControls/";

 

TDContextMenu1.Skin =

 

"WebBlue";

 

 

 

//TDContextMenu.ContextMenuElementID = "none";

 

 

 

 

itmJob_Desc1 =

 

new RadMenuItem("Job Desc 1");

 

itmJob_Desc1.Target =

 

"_blank";

 

itmJob_Desc1.NavigateUrl =

 

"http://www.gmail.com";

 

TDContextMenu1.Items.Add(itmJob_Desc1);

html1.Controls.Add(TDContextMenu1);

tblMaintest1.Rows[0].Cells[0].Controls.Add(html1);

}

 

 

else if (tblMaintesto.ID.ToString().Contains("1") && imgbtn.ID.Contains("1"))

 

{

 

 

Table tblMaintest1 = ((Table)(tblMaintesto));

 

tblMaintest1.Rows[0].Cells[0].Text =

 

"Hello Again";

 

 

 

if (lnkbt.ImageUrl.Contains("minus"))

 

{

lnkbt.ImageUrl = oWeb.Url +

 

"/images/plus.gif";

 

tblMaintest1.Rows[0].Visible =

 

false;

 

}

 

 

else

 

 

 

 

{

lnkbt.ImageUrl = oWeb.Url +

 

"/images/minus.gif";

 

tblMaintest1.Rows[0].Visible =

 

true;

 

}

 

 

TextBox txtone = new TextBox();

 

txtone.ID =

 

"txtone" + tblMaintest1.ID;

 

txtone.Text =

 

"Gaon walo";

 

 

 

HtmlGenericControl htmlo = new HtmlGenericControl("div id='tst" + tblMaintest1.ID + "' onClick=\"helloworld(event);\" ");

 

htmlo.InnerHtml =

 

"MenuShow";

 

 

 

HtmlGenericControl html1 = new HtmlGenericControl("div id='tst1" + tblMaintest1.ID + "' onClick=\"helloworld1(event);\" ");

 

html1.InnerHtml =

 

"MenuShow 1";

 

 

TDContextMenu =

 

new RadMenu();

 

TDContextMenu.Skin =

 

"Default";

 

TDContextMenu.ID =

 

"Test" + tblMaintest1.ID;

 

TDContextMenu.IsContext =

 

true;

 

TDContextMenu.RadControlsDir =

 

"/_wpresources/RadControls/";

 

TDContextMenu.Skin =

 

"WebBlue";

 

 

 

//TDContextMenu.ContextMenuElementID = "none";

 

 

 

 

 

 

RadMenuItem itmJob_Desc = new RadMenuItem("Job Desc");

 

itmJob_Desc.Target =

 

"_blank";

 

itmJob_Desc.NavigateUrl =

 

"http://www.yahoo.com";

 

TDContextMenu.Items.Add(itmJob_Desc);

htmlo.Controls.Add(TDContextMenu);

tblMaintest1.Rows[0].Cells[0].Controls.Add(htmlo);

 

TDContextMenu1 =

 

new RadMenu();

 

TDContextMenu1.Skin =

 

"Default";

 

TDContextMenu1.ID =

 

"Test1" + tblMaintest1.ID;

 

TDContextMenu1.IsContext =

 

true;

 

TDContextMenu1.RadControlsDir =

 

"/_wpresources/RadControls/";

 

TDContextMenu1.Skin =

 

"WebBlue";

 

 

 

//TDContextMenu.ContextMenuElementID = "none";

 

 

 

 

 

 

RadMenuItem itmJob_Desc1 = new RadMenuItem("Job Desc 1");

 

itmJob_Desc1.Target =

 

"_blank";

 

itmJob_Desc1.NavigateUrl =

 

"http://www.gmail.com";

 

TDContextMenu1.Items.Add(itmJob_Desc1);

html1.Controls.Add(TDContextMenu1);

tblMaintest1.Rows[0].Cells[0].Controls.Add(html1);

}

}

}

 

 

 

#region

 

"PreRender"

 

 

 

/// <summary>

 

 

 

 

 

 

/// Handle the pre render for the javascript

 

 

 

 

 

 

/// </summary>

 

 

 

 

 

 

/// <param name="sender"></param>

 

 

 

 

 

 

/// <param name="e"></param>

 

 

 

 

 

 

private void HRCareerPath_ClientScript_PreRender(object sender, System.EventArgs e)

 

{

RegisterCommonScript();

}

 

 

 

#endregion

 

 

 

 

 

 

 

protected override void Render(HtmlTextWriter writer)

 

{

 

 

this.EnsureChildControls();

 

 

 

//RenderChildren(writer);

 

 

 

 

//apnlCareerPath.RenderControl(writer);

}

 

 

 

private

 

void CreateWebUIWithAjax()

 

{

SPWeb oWeb =

 

null;

 

SPSite oSite =

 

null;

 

 

 

try

 

 

 

 

{

oWeb = SPContext.Current.Web;

oSite =

 

new SPSite(oWeb.Url);

 

 

 

//creating ajaxpanel.

 

 

 

 

pnlLoading =

 

new AjaxLoadingPanel();

 

pnlLoading.ID =

 

"AjaxLoadingPanel";

 

imgLoading =

 

new Image();

 

imgLoading.AlternateText =

 

"testing";

 

imgLoading.ImageUrl =

 

"_wpresources/RadControls/AJAX/Skins/Default/loading1.gif";

 

pnlLoading.Controls.Add(imgLoading);

 

apnlCareerPath =

 

new RadAjaxPanel();

 

apnlCareerPath.ID =

 

"apnlCareerPath";

 

apnlCareerPath.RadControlsDir =

 

"/_wpresources/RadControls/";

 

apnlCareerPath.LoadingPanelID =

 

"AjaxLoadingPanel";

 

apnlCareerPath.Controls.Add(pnlLoading);

 

 

 

//tblMaintest = new HtmlGenericControl("table id='tblMaintest' CellPadding=0 CellSpacing=0 border=1 width='100%' ");

 

 

 

 

 

 

for (int i = 0; i < 2; i++)

 

{

 

 

ImageButton lnkplus;

 

lnkplus =

 

new ImageButton();

 

lnkplus.ID =

 

"lnkplus" + i;

 

lnkplus.ImageUrl = oWeb.Url +

 

"/images/plus.gif";

 

lnkplus.Click +=

 

new ImageClickEventHandler(lnkplus_Click);

 

 

 

Table tblMaintest = new Table();

 

tblMaintest.ID =

 

"tblMaintest" + i;

 

 

 

TableRow trHeadertest;

 

 

 

TableCell tdHeadertest;

 

trHeadertest =

 

new TableRow();

 

trHeadertest.Visible =

 

false;

 

trHeadertest.ID =

 

"trHeadertest" + i;

 

tblMaintest.Rows.Add(trHeadertest);

tdHeadertest =

 

new TableCell();

 

tdHeadertest.ID =

 

"tdHeadertest" + i;

 

trHeadertest.Cells.Add(tdHeadertest);

tdHeadertest.Text =

 

"This is testing" + i;

 

apnlCareerPath.Controls.Add(lnkplus);

apnlCareerPath.Controls.Add(tblMaintest);

}

 

 

 

this.Controls.Add(apnlCareerPath);

 

 

}

 

 

catch (Exception ex)

 

{

 

 

string objErrMgs = ex.Message;

 

}

 

 

finally

 

 

 

 

{

 

 

if (oSite != null) oSite.Dispose();

 

}

 

}

 

 

 

#region

 

"RegisterCommonScript"

 

 

 

protected void RegisterCommonScript()

 

{

 

 

Table tblMaintest1 = ((Table)(apnlCareerPath.Controls[2]));

 

 

 

if (tblMaintest1.Rows[0].Cells[0].Controls.Count > 0)

 

{

 

 

HtmlGenericControl htl = (HtmlGenericControl)(tblMaintest1.Rows[0].Cells[0].Controls[0]);

 

 

 

RadMenu objRadMenu1 = (RadMenu)(htl.Controls[1]);

 

 

 

string strFunctionName1 = string.Empty;

 

strFunctionName1 =

 

"helloworld";

 

ExternalMenuScript +=

 

"function " + strFunctionName1 + "(e)";

 

ExternalMenuScript +=

 

"{ ";

 

ExternalMenuScript +=

 

" var menu = null; ";

 

ExternalMenuScript +=

 

"menu = window['" + objRadMenu1.ClientID + "']; ";

 

ExternalMenuScript +=

 

" if (menu)";

 

ExternalMenuScript +=

 

"{";

 

ExternalMenuScript +=

 

" menu.Show(e);";

 

ExternalMenuScript +=

 

" e.cancelBubble = true;";

 

ExternalMenuScript +=

 

" if (e.stopPropagation)";

 

ExternalMenuScript +=

 

" {";

 

ExternalMenuScript +=

 

"e.stopPropagation();";

 

ExternalMenuScript +=

 

" }";

 

ExternalMenuScript +=

 

" e.returnValue = false;";

 

ExternalMenuScript +=

 

"if (e.preventDefault)";

 

ExternalMenuScript +=

 

" {";

 

ExternalMenuScript +=

 

" e.preventDefault();";

 

ExternalMenuScript +=

 

"}";

 

ExternalMenuScript +=

 

"}";

 

ExternalMenuScript +=

 

"}";

 

 

 

HtmlGenericControl htl1 = (HtmlGenericControl)(tblMaintest1.Rows[0].Cells[0].Controls[1]);

 

 

 

RadMenu objRadMenu12 = (RadMenu)(htl1.Controls[1]);

 

strFunctionName1 =

 

string.Empty;

 

strFunctionName1 =

 

"helloworld1";

 

ExternalMenuScript +=

 

"function " + strFunctionName1 + "(e)";

 

ExternalMenuScript +=

 

"{ ";

 

ExternalMenuScript +=

 

" var menu = null; ";

 

ExternalMenuScript +=

 

"menu = window['" + objRadMenu12.ClientID + "']; ";

 

ExternalMenuScript +=

 

" if (menu)";

 

ExternalMenuScript +=

 

"{";

 

ExternalMenuScript +=

 

" menu.Show(e);";

 

ExternalMenuScript +=

 

" e.cancelBubble = true;";

 

ExternalMenuScript +=

 

" if (e.stopPropagation)";

 

ExternalMenuScript +=

 

" {";

 

ExternalMenuScript +=

 

"e.stopPropagation();";

 

ExternalMenuScript +=

 

" }";

 

ExternalMenuScript +=

 

" e.returnValue = false;";

 

ExternalMenuScript +=

 

"if (e.preventDefault)";

 

ExternalMenuScript +=

 

" {";

 

ExternalMenuScript +=

 

" e.preventDefault();";

 

ExternalMenuScript +=

 

"}";

 

ExternalMenuScript +=

 

"}";

 

ExternalMenuScript +=

 

"}";

 

}

ExternalMenuScript +=

 

"</script>";

 

ExternalMenuScript +=

 

"<style media='screen' type='text/css'>";

 

ExternalMenuScript +=

 

"td {";

 

ExternalMenuScript +=

 

"border-left:0px #CCCCCC solid";

 

ExternalMenuScript +=

 

"}";

 

ExternalMenuScript +=

 

".headerText {";

 

ExternalMenuScript +=

 

"font-family:arial;";

 

ExternalMenuScript +=

 

"font-size:12px;";

 

ExternalMenuScript +=

 

"font-weight: bold;";

 

ExternalMenuScript +=

 

"text-align:center;";

 

ExternalMenuScript +=

 

"padding: 10px;";

 

ExternalMenuScript +=

 

"}";

 

ExternalMenuScript +=

 

".TitleText {";

 

ExternalMenuScript +=

 

"font-family:arial;";

 

ExternalMenuScript +=

 

"font-size:12px;";

 

ExternalMenuScript +=

 

"font-weight: bold;";

 

ExternalMenuScript +=

 

"text-align:center;";

 

ExternalMenuScript +=

 

"}";

 

ExternalMenuScript +=

 

".SubTitleText {";

 

ExternalMenuScript +=

 

"font-family:arial;";

 

ExternalMenuScript +=

 

"font-size:12px;";

 

ExternalMenuScript +=

 

"font-weight: bold;";

 

ExternalMenuScript +=

 

"text-align:center;";

 

ExternalMenuScript +=

 

"}";

 

ExternalMenuScript +=

 

".MainText {";

 

ExternalMenuScript +=

 

"font-family:arial;";

 

ExternalMenuScript +=

 

"font-weight: normal;";

 

ExternalMenuScript +=

 

"text-align:center;";

 

ExternalMenuScript +=

 

"}";

 

ExternalMenuScript +=

 

"</style>";

 

 

 

 

 

apnlCareerPath.Controls.Add(

new LiteralControl(ExternalMenuScript.ToString()));

 

apnlCareerPath.Controls.Add(

 

new LiteralControl(ExternalJSScript.ToString()));

 

}

 

 

 

#endregion

}

 

Thanks in advance,
Ravi

No answers yet. Maybe you can help?

Tags
Menu
Asked by
ravi
Top achievements
Rank 1
Share this question
or