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

Need to click twice after postback

1 Answer 80 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ben Foster
Top achievements
Rank 1
Ben Foster asked on 18 Jul 2010, 01:55 PM
Hi guys,

i'm having an issue with a page where clicking a RadTreeNode shows the details of the clicked node.

If you then click a different node, the details relating to that node will show, etc.

This all works correctly, and the various components exist inside an update panel.

The problem occurs when a full-page postback occurs... (ie. not just the update panel)... after a full page postback, the treeview can still be seen, however the first time you click a node, that node becomes selected momentarily then becomes unselected again, and the details for that node don't show up as they should. You then have to click that node again to get the desired behaviour.

So basically after a full page postback you have to click the RadTreeNode twice instead of once to get its desired behaviour.

Any advice appreciated. Code shown below:

<%

@ Page Language="C#" MasterPageFile="~/Member.master" Title="Fylebase :: Professional Content Management System" %>

 

<%

@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>

 

<%

@ Import Namespace="System.Data" %>

 

<

 

script runat="server">

 

 

protected void Page_Load(object sender, EventArgs e)

 

{

loadGalleries();

}

 

public override void DataBind()

 

{

 

base.ChildControlsCreated = false;

 

}

 

protected void btnAddGallery_Click(object sender, EventArgs e)

 

{

 

dbGALLERIES.addGallery(svars.user_id);

 

loadGalleries();

}

 

private void loadGalleries()

 

{

Accordion1.Panes.Clear();

 

DataSet ds = dbGALLERIES.getGalleries(svars.user_id);

 

 

foreach (DataRow dr in ds.Tables[0].Rows)

 

{

 

AccordionPane ap = new AccordionPane();

 

 

Literal lit = new Literal();

 

lit.Text = dr[

"gallery_name"].ToString();

 

ap.HeaderContainer.Controls.Add(lit);

Telerik.Web.UI.

RadTreeView rtv = new Telerik.Web.UI.RadTreeView();

 

Telerik.Web.UI.

RadTreeViewContextMenu menu = new Telerik.Web.UI.RadTreeViewContextMenu();

 

menu.ID =

"rtvcMenu1";

 

Telerik.Web.UI.

RadMenuItem rmi = new Telerik.Web.UI.RadMenuItem("Add Image");

 

menu.Items.Add(rmi);

rtv.ContextMenus.Add(menu);

 

 

//.. Start image menu

 

Telerik.Web.UI.

RadTreeViewContextMenu imgmenu = new Telerik.Web.UI.RadTreeViewContextMenu();

 

imgmenu.ID =

"rtvcMenu2";

 

Telerik.Web.UI.

RadMenuItem rmi2 = new Telerik.Web.UI.RadMenuItem("Add Image");

 

imgmenu.Items.Add(rmi2);

rmi2 =

new Telerik.Web.UI.RadMenuItem("Publish / Unpublish");

 

imgmenu.Items.Add(rmi2);

rmi2 =

new Telerik.Web.UI.RadMenuItem("Move Up");

 

imgmenu.Items.Add(rmi2);

rmi2 =

new Telerik.Web.UI.RadMenuItem("Move Down");

 

imgmenu.Items.Add(rmi2);

rtv.ContextMenus.Add(imgmenu);

 

//.. End image menu

 

 

rtv.ContextMenuItemClick +=

new Telerik.Web.UI.RadTreeViewContextMenuEventHandler(menuItem_click);

 

rtv.NodeClick +=

new Telerik.Web.UI.RadTreeViewEventHandler(rtv_NodeClick);

 

Telerik.Web.UI.

RadTreeNode node = new Telerik.Web.UI.RadTreeNode("Gallery Settings", "g" + dr["gallery_id_pk"].ToString());

 

node.ContextMenuID = menu.ID;

node.ForeColor = System.Drawing.

Color.FromName("#937e28");

 

node.Font.Bold =

true;

 

node.ToolTip =

"Right-click to add an image";

 

rtv.Nodes.Add(node);

 

DataSet imagesDS = dbGALLERIES.getImages(Convert.ToInt32(dr["gallery_id_pk"].ToString()));

 

 

foreach (DataRow imageDR in imagesDS.Tables[0].Rows)

 

{

Telerik.Web.UI.

RadTreeNode imageNode = new Telerik.Web.UI.RadTreeNode(imageDR["image_name"].ToString(),

 

imageDR[

"image_id_pk"].ToString());

 

imageNode.ContextMenuID = imgmenu.ID;

 

if (imageDR["image_isPublished"].ToString().Equals("Y"))

 

{

imageNode.ForeColor = System.Drawing.

Color.Black;

 

}

 

else

 

{

imageNode.ForeColor = System.Drawing.

Color.Red;

 

}

imageNode.ToolTip =

"Right-click for more options";

 

rtv.Nodes.Add(imageNode);

}

rtv.ExpandAllNodes();

ap.ContentContainer.Controls.Add(rtv);

Accordion1.Panes.Add(ap);

}

}

 

protected void menuItem_click(object sender, Telerik.Web.UI.RadTreeViewContextMenuEventArgs e)

 

{

Telerik.Web.UI.

RadTreeNode clickedNode = e.Node;

 

 

switch(e.MenuItem.Text)

 

{

 

case "Add Image":

 

 

int newImageID = dbGALLERIES.insertImage(Convert.ToInt32(clickedNode.TreeView.Nodes[0].Value.Substring(1)));

 

clickedNode.TreeView.Nodes.Add(

new Telerik.Web.UI.RadTreeNode("New Image", newImageID.ToString()));

 

 

break;

 

 

case "Publish / Unpublish":

 

 

if (clickedNode.ForeColor.Equals(System.Drawing.Color.Red))

 

{

 

dbGALLERIES.publishImage(Convert.ToInt32(clickedNode.Value));

 

 

if (clickedNode.Equals(clickedNode.TreeView.SelectedNode))

 

{

chkImageShowOnWebsite.Checked =

true;

 

}

clickedNode.ForeColor = System.Drawing.

Color.Black;

 

}

 

else

 

{

 

dbGALLERIES.unpublishImage(Convert.ToInt32(clickedNode.Value));

 

 

if (clickedNode.Equals(clickedNode.TreeView.SelectedNode))

 

{

chkImageShowOnWebsite.Checked =

false;

 

}

clickedNode.ForeColor = System.Drawing.

Color.Red;

 

}

 

break;

 

 

case "Move Up":

 

 

RadTreeView rtv = clickedNode.TreeView;

 

 

int index = rtv.Nodes.IndexOf(clickedNode);

 

 

 

if (index > 1)

 

{

 

RadTreeNode aboveNode = rtv.Nodes[index - 1];

 

 

 

String clickedValue = clickedNode.Value;

 

 

String aboveText = aboveNode.Text;

 

 

String aboveValue = aboveNode.Value;

 

System.Drawing.

Color aboveColor = aboveNode.ForeColor;

 

aboveNode.Text = clickedNode.Text;

aboveNode.Value = clickedNode.Value;

clickedNode.Text = aboveText;

clickedNode.Value = aboveValue;

aboveNode.ForeColor = clickedNode.ForeColor;

clickedNode.ForeColor = aboveColor;

 

 

dbGALLERIES.swapImageOrder(Convert.ToInt32(clickedValue), Convert.ToInt32(aboveValue));

 

 

if (clickedNode.Selected)

 

{

aboveNode.Selected =

true;

 

}

 

else if (aboveNode.Selected)

 

{

clickedNode.Selected =

true;

 

}

}

 

 

break;

 

 

case "Move Down":

 

 

RadTreeView rtv2 = clickedNode.TreeView;

 

 

int index2 = rtv2.Nodes.IndexOf(clickedNode);

 

 

if (index2 < (rtv2.Nodes.Count - 1))

 

{

 

RadTreeNode belowNode = rtv2.Nodes[index2 + 1];

 

 

String clickedValue = clickedNode.Value;

 

 

String belowText = belowNode.Text;

 

 

String belowValue = belowNode.Value;

 

System.Drawing.

Color belowColor = belowNode.ForeColor;

 

belowNode.Text = clickedNode.Text;

belowNode.Value = clickedNode.Value;

clickedNode.Text = belowText;

clickedNode.Value = belowValue;

belowNode.ForeColor = clickedNode.ForeColor;

clickedNode.ForeColor = belowColor;

 

dbGALLERIES.swapImageOrder(Convert.ToInt32(clickedValue), Convert.ToInt32(belowValue));

 

 

if (clickedNode.Selected)

 

{

belowNode.Selected =

true;

 

}

 

else if (belowNode.Selected)

 

{

clickedNode.Selected =

true;

 

}

}

 

break;

 

}

}

 

private void deselectAllExcept(AccordionPane ap)

 

{

 

foreach (AccordionPane acp in Accordion1.Panes)

 

{

 

if (acp.Equals(ap).Equals(false))

 

{

 

RadTreeView rtv = (RadTreeView)acp.Controls[1].Controls[0];

 

rtv.ClearSelectedNodes();

}

}

}

 

protected void rtv_NodeClick(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e)

 

{

Telerik.Web.UI.

RadTreeNode clickedNode = e.Node;

 

 

AccordionPane ap = findAccordionPaneContainingNode(clickedNode.Value);

 

deselectAllExcept(ap);

 

if (clickedNode.Text.Equals("Gallery Settings"))

 

{

loadGallerySettings(

Convert.ToInt32(clickedNode.Value.Substring(1)));

 

 

svars.selected_value = Convert.ToInt32(clickedNode.Value.Substring(1));

 

}

 

else

 

{

loadImageDetails(

Convert.ToInt32(clickedNode.Value));

 

 

svars.selected_value = Convert.ToInt32(clickedNode.Value);

 

}

}

 

 

private void loadImageDetails(int imageID)

 

{

pnlGallery.Visible =

false;

 

pnlImage.Visible =

true;

 

 

DataSet ds = dbGALLERIES.getImageDetails(imageID);

 

txtImageName.Text = ds.Tables[0].Rows[0][

"image_name"].ToString();

 

chkImageShowOnWebsite.Checked =

func.charToBoolean(ds.Tables[0].Rows[0]["image_isPublished"].ToString());

 

txtImageDescription.Text = ds.Tables[0].Rows[0][

"image_description"].ToString();

 

lblImageError.Text =

"";

 

 

String filename = "" + ds.Tables[0].Rows[0]["image_filename"].ToString();

 

 

if (filename.Trim().Length > 0)

 

{

imgImage.ImageUrl =

"~/uploads/" + svars.user_id + "/galleries/" + filename;

 

}

 

else

 

{

imgImage.ImageUrl =

"~/images/noimage.gif";

 

}

}

 

private void loadGallerySettings(int galleryID)

 

{

pnlImage.Visible =

false;

 

pnlGallery.Visible =

true;

 

 

DataSet ds = dbGALLERIES.getGalleryDetails(galleryID);

 

txtGalleryName.Text = ds.Tables[0].Rows[0][

"gallery_name"].ToString();

 

chkGalleryShowOnWebsite.Checked =

func.charToBoolean(ds.Tables[0].Rows[0]["gallery_isPublished"].ToString());

 

txtGalleryDescription.Text = ds.Tables[0].Rows[0][

"gallery_description"].ToString();

 

lblGalleryError.Text =

"";

 

}

 

protected void btnSaveGallery_Click(object sender, EventArgs e)

 

{

lblGalleryError.Text =

"";

 

 

if (txtGalleryName.Text.Trim().Length < 1)

 

{

lblGalleryError.Text =

"Gallery name is required";

 

}

 

else

 

{

 

dbGALLERIES.updateGallery(svars.selected_value, txtGalleryName.Text.Trim(), txtGalleryDescription.Text.Trim(), chkGalleryShowOnWebsite.Checked);

 

lblGalleryError.Text =

"Gallery settings saved";

 

 

AccordionPane ap = findAccordionPaneContainingNode("g" + svars.selected_value.ToString());

 

 

Literal lit = (Literal)ap.HeaderContainer.Controls[0];

 

lit.Text = txtGalleryName.Text.Trim();

}

}

 

private Telerik.Web.UI.RadTreeNode findNode(String nodeValue)

 

{

 

RadTreeNode returnable = new RadTreeNode();

 

 

foreach (AccordionPane ap in Accordion1.Panes)

 

{

 

RadTreeView rtv = (RadTreeView)ap.Controls[1].Controls[0];

 

 

try

 

{

 

RadTreeNode rtn2 = rtv.FindNodeByValue(nodeValue);

 

 

if (rtn2 != null)

 

{

returnable = rtn2;

}

}

 

catch

 

{

}

}

 

return returnable;

 

}

 

private AccordionPane findAccordionPaneContainingNode(String nodeValue)

 

{

 

AccordionPane returnable = new AccordionPane();

 

 

foreach (AccordionPane ap in Accordion1.Panes)

 

{

 

RadTreeView rtv = (RadTreeView)ap.Controls[1].Controls[0];

 

 

try

 

{

 

RadTreeNode rtn2 = rtv.FindNodeByValue(nodeValue);

 

 

if (rtn2 != null)

 

{

returnable = ap;

}

}

 

catch

 

{

}

}

 

return returnable;

 

}

 

protected void btnSaveImage_Click(object sender, EventArgs e)

 

{

lblImageError.Text =

"";

 

 

if (txtImageName.Text.Trim().Length < 1)

 

{

lblImageError.Text =

"Image name is required";

 

}

 

else if(radUpload1.InvalidFiles.Count > 0)

 

{

lblImageError.Text =

"File is too large.<br/>(max 300kb)";

 

}

 

else

 

{

 

if (radUpload1.UploadedFiles.Count > 0)

 

{

 

String filename = radUpload1.UploadedFiles[0].FileName;

 

 

String userFolder = Server.MapPath("uploads\\" + svars.user_id);

 

 

String galleryFolder = userFolder + "\\galleries";

 

 

if (System.IO.Directory.Exists(userFolder).Equals(false))

 

{

System.IO.

Directory.CreateDirectory(userFolder);

 

}

 

if (System.IO.Directory.Exists(galleryFolder).Equals(false))

 

{

System.IO.

Directory.CreateDirectory(galleryFolder);

 

}

 

String newFilename = DateTime.Now.ToString("yyyyMMddHHmmss") + radUpload1.UploadedFiles[0].GetExtension();

 

 

String newFileLocation = galleryFolder + "\\" + newFilename;

 

radUpload1.UploadedFiles[0].SaveAs(newFileLocation);

 

dbGALLERIES.updateImage(svars.selected_value, txtImageName.Text.Trim(),

 

txtImageDescription.Text.Trim(), chkImageShowOnWebsite.Checked, newFilename);

imgImage.ImageUrl =

"~/uploads/" + svars.user_id + "/galleries/" + newFilename;

 

System.Drawing.

Image photoImg = System.Drawing.Image.FromFile(newFileLocation);

 

System.Drawing.

Image thumbPhoto = photoImg.GetThumbnailImage(100, 100, null, new System.IntPtr());

 

thumbPhoto.Save(newFileLocation +

"_th.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

 

}

 

else

 

{

 

dbGALLERIES.updateImage(svars.selected_value, txtImageName.Text.Trim(),

 

txtImageDescription.Text.Trim(), chkImageShowOnWebsite.Checked);

}

 

lblImageError.Text =

"Image settings saved";

 

loadGalleries();

}

}

 

protected void btnDeleteGallery_Click(object sender, EventArgs e)

 

{

 

int galleryID = svars.selected_value;

 

 

dbGALLERIES.deleteGallery(galleryID);

 

pnlGallery.Visible =

false;

 

loadGalleries();

}

 

</

 

script>

 

<

 

asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

 

</

 

asp:Content>

 

<

 

asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

 

 

<asp:UpdatePanel runat="server">

 

 

<ContentTemplate>

 

 

 

<table border=0 cellpadding=0 cellspacing=0 width="100%">

 

 

<tr>

 

 

<td style="vertical-align:top; width:200px;">

 

 

<ajax:Accordion ID="Accordion1" Width="200px" runat="server" SelectedIndex="0" HeaderCssClass="accordionHeader"

 

 

HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent" AutoSize="None"

 

 

FadeTransitions="true" TransitionDuration="250" FramesPerSecond="40"

 

 

RequireOpenedPane="true" SuppressHeaderPostbacks="true" >

 

 

</ajax:Accordion>

 

 

 

<div style="text-align:center; padding-top:15px;">

 

 

<asp:Button runat="server" Text="Add Gallery" ID="btnAddGallery" Height="30px" OnClick="btnAddGallery_Click" />

 

 

</div>

 

 

</td>

 

 

<td style="vertical-align:top; width:800px;">

 

 

<asp:Panel runat="server" ID="pnlGallery" Visible="false">

 

 

<table border=0 cellpadding="10px" cellspacing=0>

 

 

<tr>

 

 

<td>Gallery Name:</td>

 

 

<td><asp:TextBox runat="server" CssClass="fbTextBox" ID="txtGalleryName"></asp:TextBox></td>

 

 

</tr>

 

 

<tr>

 

 

<td>Show on Website?</td>

 

 

<td><asp:CheckBox runat="server" ID="chkGalleryShowOnWebsite" /></td>

 

 

</tr>

 

 

<tr>

 

 

<td>Description:</td>

 

 

<td><asp:TextBox runat="server" ID="txtGalleryDescription" CssClass="fbTextBox" TextMode="MultiLine" Width="400px" Height="60px"></asp:TextBox></td>

 

 

</tr>

 

 

<tr>

 

 

<td>&nbsp;</td>

 

 

<td style="text-align:left;">

 

 

<asp:Button runat="server" ID="btnSaveGallery" OnClick="btnSaveGallery_Click" Text="Save Changes"

 

 

Width="120px" Height="30px" />

 

 

&nbsp;

 

 

<asp:Button runat="server" ID="btnDeleteGallery" Text="Delete Gallery" Width="120px" Height="30px"

 

 

OnClick="btnDeleteGallery_Click"

 

 

OnClientClick="return confirm('Are you sure you want to delete this gallery?');" />

 

 

<div style="font-size:12px;">&nbsp;</div><asp:Label runat="server" ID="lblGalleryError" ForeColor="Red"

 

 

Font-Bold="true" Font-Size="12px"></asp:Label>

 

 

</td>

 

 

</tr>

 

 

</table>

 

 

</asp:Panel>

 

 

<asp:Panel runat="server" ID="pnlImage" Visible="false">

 

 

<table border=0 cellpadding="10px" cellspacing=0>

 

 

<tr>

 

 

<td>Image Name:</td>

 

 

<td><asp:TextBox runat="server" CssClass="fbTextBox" ID="txtImageName"></asp:TextBox></td>

 

 

</tr>

 

 

<tr>

 

 

<td>Show on Website?</td>

 

 

<td><asp:CheckBox runat="server" ID="chkImageShowOnWebsite" /></td>

 

 

</tr>

 

 

<tr>

 

 

<td>Description:</td>

 

 

<td><asp:TextBox runat="server" ID="txtImageDescription" CssClass="fbTextBox" TextMode="MultiLine" Width="400px" Height="60px"></asp:TextBox></td>

 

 

</tr>

 

 

<tr>

 

 

<td>Upload Image:</td>

 

 

<td>

 

 

<telerik:RadUpload ControlObjectsVisibility="None" InitialFileInputsCount="1" MaxFileSize="300000"

 

 

id="radUpload1" runat="server" ></telerik:RadUpload>

 

 

</td>

 

 

</tr>

 

 

<tr>

 

 

<td>&nbsp;</td>

 

 

<td style="text-align:left;">

 

 

<table border=0 cellpadding=0 cellspacing=0 width="100%">

 

 

<tr>

 

 

<td style="text-align:left; vertical-align:top; width:160px;">

 

 

<asp:Button runat="server" ID="btnSaveImage" OnClick="btnSaveImage_Click" Text="Save Changes"

 

 

Height="30px" /><div style="font-size:12px;">&nbsp;</div><asp:Label runat="server"

 

 

ID="lblImageError" ForeColor="Red" Font-Bold="true" Font-Size="12px"></asp:Label>

 

 

</td>

 

 

<td style="padding-left:20px; text-align:left; vertical-align:top;">

 

 

<asp:Image runat="server" ID="imgImage" Width="230px" BorderColor="#666666"

 

 

BorderStyle="Solid" BorderWidth="1px" ImageUrl="~/images/noimage.gif" />

 

 

</td>

 

 

</tr>

 

 

</table>

 

 

</td>

 

 

</tr>

 

 

</table>

 

 

</asp:Panel>

 

 

</td>

 

 

</tr>

 

 

</table>

 

 

 

</ContentTemplate>

 

 

 

<Triggers>

 

 

<asp:PostBackTrigger ControlID="btnSaveImage" />

 

 

</Triggers>

 

 

</asp:UpdatePanel>

 

</

 

asp:Content>

 


1 Answer, 1 is accepted

Sort by
0
Helen
Telerik team
answered on 22 Jul 2010, 12:53 PM
Hi Ben,

Could you please send us a sample project which demonstrates the issue to examine it locally?


Regards,
Helen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TreeView
Asked by
Ben Foster
Top achievements
Rank 1
Answers by
Helen
Telerik team
Share this question
or