Showing posts with label controls. Show all posts
Showing posts with label controls. Show all posts

Wednesday, March 28, 2012

Treeview & UpdatePanel - Assertion failed - cant find last / in base url

Hi,

I am using a TreeView and couple of server controls. The treeview children are dynamically added on click of a node. I have the treeview control inside an update panel. Everything works if I access the page in a normal IE window. When I try to access the same page through a modal dialog, during postback, it opens a new window. To avoid that, I've added<base target = "_self" />.

Now I'm getting another error with Atlas. On click of tree node, it says "Assertion Failed : Can't find last / in base url. If I remove the <base..> it doesn't work.

Looking for an immediate solution. I've spent almost a day in googling. But no luck yet.

Many Thanks,
Mani.

hello.

you can also try using an iframe inside your popup page (ie, put only an iframe inside your popoup window which loads the page that shows the content)...maybe it'll solve that problem.


Mani,

Add:<basetarget="_self"href="http://localhost/***/***/"runat="server"/>

because our dear js function check if u have base tag , then try to concat with href value. in your case you don't have it.

T.


what if i'm using a Master Page - i can't hard code a path in the href. Is there any way to accomplish this? Plus - even if i hard code, the paging on my grid view does not work now.

trans642:

Mani,

Add:<basetarget="_self"href="http://localhost/***/***/"runat="server"/>

because our dear js function check if u have base tag , then try to concat with href value. in your case you don't have it.

T.

GOOD THANKS !


trans642:

Mani,

Add:<basetarget="_self"href="http://localhost/***/***/"runat="server"/>

because our dear js function check if u have base tag , then try to concat with href value. in your case you don't have it.

T.

GOOD THANKS !


Try this, without hard code urlSmile
 <base target="_self" href="<%=Request.Url.OriginalString%>" />

works perfect ... Thanks.

Monday, March 26, 2012

Treeview inside update panel adds nodes when expanded/collapsed

Hi all,

I have something weird going on with a page with 3 treeview controls. I have them set to be expanded by default, but when I click on the collapse (or expand) image on any of the 3 treeviews, a new node is added in my second treeview with repeating data, ie:

TreeView1

1.01.11.22.02.1

TreeView2

3.03.13.2

Now, if I click on 2.0 to collapse it, a new node in TreeView2 will appear, same as 3.0. If I expand 2.0 again, or collapse another node, 3.0 is added again to TreeView2. I'm getting the data from a database table.

Here is the page behind:

protected void Page_Load(object sender, EventArgs e) {if (!Page.IsPostBack) PopulateRootLevel(); PopulateRootLevel_OD(); PopulateRootLevel_RO(); }//TreeView 1//private void PopulateRootLevel() { SqlConnection objConn =new SqlConnection("Data Source=##;Initial Catalog=##;Integrated Security=True"); SqlCommand objCommand =new SqlCommand("select *,(select count(*) FROM ccForum_Posts WHERE parentid=sc.id) childnodecount FROM ccForum_Posts sc where parentID='0' AND status='ac' AND sticky='1' ORDER BY DateTime", objConn); SqlDataAdapter da =new SqlDataAdapter(objCommand); DataTable dt =new DataTable(); da.Fill(dt); PopulateNodes(dt, TreeView1.Nodes); }private void PopulateSubLevel(int parentid, TreeNode parentNode) { SqlConnection objConn =new SqlConnection("Data Source=##;Initial Catalog=##;Integrated Security=True"); SqlCommand objCommand =new SqlCommand("select *,(select count(*) FROM ccForum_Posts WHERE parentid=sc.id) childnodecount FROM ccForum_Posts sc where parentID=@dotnet.itags.org.parentID AND status='ac' ORDER BY sticky, DateTime", objConn); objCommand.Parameters.Add("@dotnet.itags.org.parentID", SqlDbType.Int).Value = parentid; SqlDataAdapter da =new SqlDataAdapter(objCommand); DataTable dt =new DataTable(); da.Fill(dt); PopulateNodes(dt, parentNode.ChildNodes); }protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e) { PopulateSubLevel(Int32.Parse(e.Node.Value), e.Node); }private void PopulateNodes(DataTable dt, TreeNodeCollection nodes) {foreach (DataRow drin dt.Rows) { TreeNode tn =new TreeNode(); tn.ToolTip = dr["Message"].ToString(); tn.Text = dr["subject"].ToString() +" - <span style=font-size:xx-small;> by " + dr["Author"].ToString() +" on " + dr["DateTime"].ToString() +"</span>"; tn.Value = dr["id"].ToString(); tn.NavigateUrl ="~/Post.aspx?MID=" + dr["id"].ToString() +"&PID=" + dr["PostID"].ToString(); nodes.Add(tn);//If node has child nodes, then enable on-demand populating tn.PopulateOnDemand = ((int)(dr["childnodecount"]) > 0); } }protected void Button_Command(Object sender, CommandEventArgs e) {switch (e.CommandName) {case"Expand": TreeView1.ExpandAll();break;case"Collapse": TreeView1.CollapseAll();break;default:// Do nothing.break; } }//TreeView 2//private void PopulateRootLevel_OD() { SqlConnection objConn_OD =new SqlConnection("Data Source=##;Initial Catalog=##;Integrated Security=True"); SqlCommand objCommand_OD =new SqlCommand("select *,(select count(*) FROM ccForum_Posts WHERE parentid=sc.id) childnodecount FROM ccForum_Posts sc where parentID='0' AND status='ac' AND sticky='2' ORDER BY DateTime", objConn_OD); SqlDataAdapter da_OD =new SqlDataAdapter(objCommand_OD); DataTable dt_OD =new DataTable(); da_OD.Fill(dt_OD); PopulateNodes_OD(dt_OD, TreeView2.Nodes); }private void PopulateSubLevel_OD(int parentid, TreeNode parentNode) { SqlConnection objConn =new SqlConnection("Data Source=##;Initial Catalog=##;Integrated Security=True"); SqlCommand objCommand =new SqlCommand("select *,(select count(*) FROM ccForum_Posts WHERE parentid=sc.id) childnodecount FROM ccForum_Posts sc where parentID=@dotnet.itags.org.parentID AND status='ac' ORDER BY sticky, DateTime", objConn); objCommand.Parameters.Add("@dotnet.itags.org.parentID", SqlDbType.Int).Value = parentid; SqlDataAdapter da =new SqlDataAdapter(objCommand); DataTable dt =new DataTable(); da.Fill(dt); PopulateNodes_OD(dt, parentNode.ChildNodes); }protected void TreeView2_TreeNodePopulate(object sender, TreeNodeEventArgs e) { PopulateSubLevel_OD(Int32.Parse(e.Node.Value), e.Node); }private void PopulateNodes_OD(DataTable dt, TreeNodeCollection nodes) {foreach (DataRow drin dt.Rows) { TreeNode tn =new TreeNode(); tn.ToolTip = dr["Message"].ToString(); tn.Text = dr["subject"].ToString() +" - <span style=font-size:xx-small;> by " + dr["Author"].ToString() +" on " + dr["DateTime"].ToString() +"</span>"; tn.Value = dr["id"].ToString(); tn.NavigateUrl ="~/Post.aspx?MID=" + dr["id"].ToString() +"&PID=" + dr["PostID"].ToString(); nodes.Add(tn);//If node has child nodes, then enable on-demand populating tn.PopulateOnDemand = ((int)(dr["childnodecount"]) > 0); } }protected void Button_Command_OD(Object sender, CommandEventArgs e) {switch (e.CommandName) {case"Expand": TreeView2.ExpandAll();break;case"Collapse": TreeView2.CollapseAll();break;default:// Do nothing.break; } }//TreeView 3//private void PopulateRootLevel_RO() { SqlConnection objConn =new SqlConnection("Data Source=##;Initial Catalog=##;Integrated Security=True"); SqlCommand objCommand =new SqlCommand("select *,(select count(*) FROM ccForum_Posts WHERE parentid=sc.id) childnodecount FROM ccForum_Posts sc where parentID='0' AND status='ro' ORDER BY sticky, DateTime", objConn); SqlDataAdapter da =new SqlDataAdapter(objCommand); DataTable dt =new DataTable(); da.Fill(dt); PopulateNodes_RO(dt, TreeView3.Nodes); }private void PopulateSubLevel_RO(int parentid, TreeNode parentNode) { SqlConnection objConn =new SqlConnection("Data Source=##;Initial Catalog=##;Integrated Security=True"); SqlCommand objCommand =new SqlCommand("select *,(select count(*) FROM ccForum_Posts WHERE parentid=sc.id) childnodecount FROM ccForum_Posts sc where parentID=@dotnet.itags.org.parentID ORDER BY DateTime", objConn); objCommand.Parameters.Add("@dotnet.itags.org.parentID", SqlDbType.Int).Value = parentid; SqlDataAdapter da =new SqlDataAdapter(objCommand); DataTable dt =new DataTable(); da.Fill(dt); PopulateNodes_RO(dt, parentNode.ChildNodes); }protected void TreeView3_TreeNodePopulate(object sender, TreeNodeEventArgs e) { PopulateSubLevel_RO(Int32.Parse(e.Node.Value), e.Node); }private void PopulateNodes_RO(DataTable dt, TreeNodeCollection nodes) {foreach (DataRow drin dt.Rows) { TreeNode tn =new TreeNode(); tn.ToolTip = dr["Message"].ToString(); tn.Text = dr["subject"].ToString() +" - <span style=font-size:xx-small;> by " + dr["Author"].ToString() +" on " + dr["DateTime"].ToString() +"</span>"; tn.Value = dr["id"].ToString(); tn.NavigateUrl ="~/Post.aspx?MID=" + dr["id"].ToString() +"&PID=" + dr["PostID"].ToString(); nodes.Add(tn);//If node has child nodes, then enable on-demand populating tn.PopulateOnDemand = ((int)(dr["childnodecount"]) > 0); } }protected void Button_Command_RO(Object sender, CommandEventArgs e) {switch (e.CommandName) {case"Expand": TreeView3.ExpandAll();break;case"Collapse": TreeView3.CollapseAll();break;default:// Do nothing.break; } }

And here is the control:

<%@dotnet.itags.org. Control Language="C#" AutoEventWireup="true" CodeFile="ct_forum_2.ascx.cs" Inherits="ccforum_ct_forum" %><asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <h3>TreeView1 - <asp:ImageButton ID="ExpandButton" runat="server" ImageUrl="~/images/expandall.jpg" CommandName="Expand" OnCommand="Button_Command" AlternateText="Open All Conversations" />   <asp:ImageButton ID="CollapseButton" runat="server" ImageUrl="~/images/collapseall.jpg" CommandName="Collapse" OnCommand="Button_Command" AlternateText="Close All Conversations" /></h3> <asp:TreeView ID="TreeView1" ExpandDepth="10" runat="server" OnTreeNodePopulate="TreeView1_TreeNodePopulate" ImageSet="Inbox" EnableClientScript="False" Width="100%" BackColor="White" BorderColor="#404040" LineImagesFolder="~/TreeLineImages" ShowLines="True" > <ParentNodeStyle Font-Bold="False" /> <HoverNodeStyle Font-Underline="True" /> <SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px" VerticalPadding="0px" BackColor="#404040" /> <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" /> </asp:TreeView><br /> <h3>TreeView2 - <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/expandall.jpg" CommandName="Expand" OnCommand="Button_Command_OD" AlternateText="Open All Conversations" />   <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/collapseall.jpg" CommandName="Collapse" OnCommand="Button_Command_OD" AlternateText="Close All Conversations" /></h3> <asp:TreeView ID="TreeView2" ExpandDepth="10" runat="server" OnTreeNodePopulate="TreeView2_TreeNodePopulate" ImageSet="Inbox" EnableClientScript="False" Width="100%" BackColor="White" BorderColor="#404040" LineImagesFolder="~/TreeLineImages" ShowLines="True" > <ParentNodeStyle Font-Bold="False" /> <HoverNodeStyle Font-Underline="True" /> <SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px" VerticalPadding="0px" BackColor="#404040" /> <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" /> </asp:TreeView> <br /> <h3>TreeView3 - <asp:ImageButton ID="ImageButton3" runat="server" ImageUrl="~/images/expandall.jpg" CommandName="Expand" OnCommand="Button_Command_RO" AlternateText="Open All Conversations" />   <asp:ImageButton ID="ImageButton4" runat="server" ImageUrl="~/images/collapseall.jpg" CommandName="Collapse" OnCommand="Button_Command_RO" AlternateText="Close All Conversations" /></h3> <asp:TreeView ID="TreeView3" ExpandDepth="10" runat="server" OnTreeNodePopulate="TreeView3_TreeNodePopulate" ImageSet="Inbox" EnableClientScript="False" Width="100%" BackColor="White" BorderColor="#404040" LineImagesFolder="~/TreeLineImages" ShowLines="True" > <ParentNodeStyle Font-Bold="False" /> <HoverNodeStyle Font-Underline="True" /> <SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px" VerticalPadding="0px" BackColor="#404040" /> <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" /> </asp:TreeView> </ContentTemplate></asp:UpdatePanel>

Any help will be truly appreciated.

Jose

Well, I hate to answer my own posts, but I guess stepping out of the office gave me a fresh set of eyes. My problem lied in the IsPostBack property:

protected void Page_Load(object sender, EventArgs e) {if (!Page.IsPostBack) PopulateRootLevel(); PopulateRootLevel_OD(); PopulateRootLevel_RO(); }

It should be:

if (!Page.IsPostBack) { PopulateRootLevel(); PopulateRootLevel_OD(); PopulateRootLevel_RO(); }
Hope it helps someone.

Treeviw within an Accordion Pane

I have mocked up some code to illustrate my point.
The pane hides the expanded treeview (or doesn't expand along with it)
and any controls under the treeview this may be considered a bug.
I would like some input on how I could get around this.

To see my point in action, expand the treeview in the code below, notice the textbox disappears.
click the pane 2 header, then the pane 1 header to reveal the whold treeview.
collapse the treeview and see a gap between the panes.

1<%@dotnet.itags.org. Page Language="VB" %>23<%@dotnet.itags.org. Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit" %>4<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">56<script runat="server">7 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)8 Dim tree As TreeView = Pane1.ContentContainer.FindControl("treeview")9 Dim node As TreeNode10 Dim root As New TreeNode11 root.Text = "root"12 tree.Nodes.Add(root)13 Dim x As Integer14 For x = 1 To 1015 node = New TreeNode16 node.Text = "Data " & x.ToString17 root.ChildNodes.Add(node)18 Next19 tree.CollapseAll()20 End Sub21</script>2223<html xmlns="http://www.w3.org/1999/xhtml">24<head runat="server">25 <title>Accordion/Treeview Test</title>26</head>27<body>28 <form id="form1" runat="server">29 <div>30 <atlas:ScriptManager ID="Script" runat="server" />31 <atlasToolkit:Accordion ID="acc" runat="server" Width="300" FadeTransitions="true"32 FramesPerSecond="40" TransitionDuration="250">33 <atlasToolkit:AccordionPane ID="Pane1" runat="server" BorderColor="black">34 <Header>35 <table width="100%" bgcolor="silver">36 <tr>37 <td>Pane 1</td>38 </tr>39 </table>40 </Header>41 <Content>42 <asp:TreeView ID="treeview" runat="server" ShowLines="true" />43 <asp:TextBox ID="txt" runat="server" />44 </Content>45 </atlasToolkit:AccordionPane>46 <atlasToolkit:AccordionPane ID="Pane2" runat="server" BorderColor="black">47 <Header>48 <table width="100%" bgcolor="olive">49 <tr>50 <td>Pane 2</td>51 </tr>52 </table>53 </Header>54 <Content>Content Here</Content>55 </atlasToolkit:AccordionPane>56 </atlasToolkit:Accordion>57 </div>58 </form>59</body>60</html>

Hi Chris,

This isissue 1560 and we're hoping to get it fixed by the next release.

Thanks,
Ted

Ted,

Is this issue fixed in the latest release?

My current workaround is to add a panel with a vertical scrollbar. I would like it to look cleaner without the panel..

Chris


Hi Ted,

I saw that this issue was marked as closed. But my example running on IE7 with today's release (12/14) still yields the same result.

Thanks,
Chris

Ted, here is an updated version of the code that works with the RTM.

this is still not working correctly. open the treeview and you'll see what I mean.

<%@. Page Language="VB" %>
<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim tree As TreeView = Pane1.ContentContainer.FindControl("treeview")
Dim node As TreeNode
Dim root As New TreeNode
root.Text = "root"
tree.Nodes.Add(root)
Dim x As Integer
For x = 1 To 10
node = New TreeNode
node.Text = "Data " & x.ToString
root.ChildNodes.Add(node)
Next
tree.CollapseAll()
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Accordion/Treeview Test</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="Script" runat="server" />
<ajaxToolkit:Accordion ID="acc" runat="server" Width="300" FadeTransitions="true"
FramesPerSecond="40" TransitionDuration="250">
<panes>
<ajaxToolkit:AccordionPane ID="Pane1" runat="server" BorderColor="black">
<Header>
<table width="100%" bgcolor="silver">
<tr>
<td>Pane 1</td>
</tr>
</table>
</Header>
<Content>
<asp:TreeView ID="treeview" runat="server" ShowLines="true" />
<asp:TextBox ID="txt" runat="server" />
</Content>
</ajaxToolkit:AccordionPane>
<ajaxToolkit:AccordionPane ID="Pane2" runat="server" BorderColor="black">
<Header>
<table width="100%" bgcolor="olive">
<tr>
<td>Pane 2</td>
</tr>
</table>
</Header>
<Content>Content Here</Content>
</ajaxToolkit:AccordionPane>
</panes>
</ajaxToolkit:Accordion>
</div>
</form>
</body>
</html>


Im having the same problems with the latest release but with the new calendar extender - when i click into my textbox and the calendar pops up it is hidden behind the accordion. It looks like the same problem as the treeview bug in that anything dynamic and the accordion panes dont re-size.

Does anyone have a workaround for this problem??

TIA


Ive found that if you remove the cssclass from the calendar extender the problem goes away and the calendar pops up outside the accordion.


I have the exact same issue as CConchel describes, however with a CollapsiblePanelExtender. There seem to be quite some issues, even on this Forum, regarding dynamic resizing of the AccordionControl where content is just truncated. However, I still have found no solution for this problem. I found a similar issue with a javascript solution but have no clue on how to implement this.

Ted:
It doesn't seem to be fixed in the latest release of the toolkit (Release 10201 - feb-01-2007)

Omen:
For me, removing the CssClass from all elements does not seem to work in this case.

Does anyone have asolution - or workaround - for this?


This seems to be fixed in theupcoming 10301 release of the toolkit. I have compiled the development build from CodePlex and it works, along side with many other fixes (such as IE crash and such).

Well done, guys!


Hi,

Yes, we've completely reworked the Accordion so its layout will be a lot more flexible - thanks mostly to feedback generated via these forums and CodePlex. We just shipped the latest release, so try it if you haven't already.

Thanks,
Ted

Trigger design-time error

At the begin, is all ok: when I open my project the controls was showed normally.
After first run, when I switch from html view to design-view the updatepanel control show this error:

Error Creating Control - Content1
'Triggers' could not be initialized. Details: 'Triggers' could not be added to the collection. Details: Object does not match target type.

This is my code:

<%

@dotnet.itags.org.PageLanguage="VB"MasterPageFile="~/MasterPage.master"AutoEventWireup="false"CodeFile="Ricerche.aspx.vb"Inherits="Ricerche"title="Ricerche" %>
<asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"runat="Server">
<atlas:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering="true"EnableScriptGlobalization="false"></atlas:ScriptManager>
<asp:TextBoxID="TxtSearch"runat="server"></asp:TextBox>
<asp:ImageButtonID="ImageButton1"runat="server"ImageUrl="~/Images/Cerca.gif"/><br/><atlas:UpdatePanelID="UpdatePanel1"runat="server"Mode="Conditional">
<ContentTemplate>
<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="True"DataKeyNames="ID"></asp:GridView>
</ContentTemplate>
<Triggers>
<atlas:ControlEventTriggerControlID="ImageButton1"EventName="Click"/>
</Triggers>
</atlas:UpdatePanel>
</asp:Content>

I must say that I use April CTP of Atlas and Atlas controlToolkit too.
Now i try to delete triggers section and change update panel mode to always, and the page was displayed correctly. But if I insert again triggers section the error come back.
What I can do? thanks


I also just started getting the same design time error ..

Error Creating Control - Content1
'Triggers' could not be initialized. Details: 'Triggers' could not be added to the collection. Details: Object does not match target type.

And in my specific case, I have:

And .. I've been using pages that have a very similar setup for like 2 weeks without problems like this.
Then today, I started getting the 'Error Creating Control' message when I went from Source view of the asp page to the Design view.

<asp:Content id="content1"> <atlas:UpdatePanel id="updatePanel1" runat="server" mode="Conditional"> <ContentTemplate> ... <asp:GridView ... /> ... </ContentTemplate> <Triggers> <atlas:ControlEventTrigger ControlID="button1" EventName="Click" /> <atlas:ControlValueTrigger ControlID="ddl1" PropertyName="SelectedValue" /> </Triggers> </atlas:UpdatePanel> ... <asp:Button id="button1" runat="server" Text="Huh?"> ... <asp:DropDownList id="ddl1" runat="server" /> ...</asp:Content>
Need assistance with this problem .. thanks!
Hmm .. interesting, so .. I open up the project this morning. The problem I was having yesterday isn't occurring anymore. Not much has changed from yesterday to today, other than I've added more content to the page.
I believe this is a bug with the IDE not handeling the trigger well in design mode. I have had this exact same problem and fix it by restarting VS 2005.

For some reason, the error went away for me when I hit "Save"...

if that's any help

Trigger full postback from the server during a partial postback.

Well, I have a dialog user control (ajax popup) which can again contain other user asp user controls as content. The content of the dialog is created inside an UpdatePanel, so that the dialog content can postback. All of that works OK.

On the web page I have now some information visible inside a GridView which is not in an UpdatePanel and should not be, because I need the browser forward/backward button to work. A link on that web page lets one of these dialog controls pop up. The dialog contains a user control which can manipulate the data which is visible inside the GridView. If the user presses a button inside the dialog, the dialog does an asynchronous postback as the user control/dialog content is inside an update panel and the dialog closes. That gives the user the impression that nothing happened as the data visible in the GridView did not change. I do already have the code to refresh the gridview, but how can I change the behavior during the postback from being an asynchronous postback to a full postback?

So just to clarify some pseudo code:

In the user control contained inside the dialog I would have some code like:

void OnOK(...)
{
// check if any data changed
if (textBox.Text != record.Text)
{
// do a database update
// and
// update cached data which the datagrid is bound to
// call a method on the page to rebind the datagrid only

// ? Force a full page refresh
}
else
{
// do nothing
// asynchronous postback is OK, no full page refresh needed
}
}

The force of a full page refresh is what I would need. In a fat environment like Windows Forms, I would just call Invalidate on the Form. Or IF the DataGrid would be inside an UpdatePanel I would search for it and call Update() on it, but then I would loose the browser caching during back and forward movements. So I was searching through all of the classes if there is something like ScriptManager.UpdatePage or something similar, but have found nothing so far.

So what is the solution here? How can inform the ajax client side script, that it should just go ahead and rerender the whole page instead of just extracting the update panel portions?

Thanks

In the <Triggers> collection of your updatepanel, just add whatever control you want to cause a full refresh as a PostBackTrigger instead of as a AsynchPostBackTrigger.

<asp:UpdatePanel ...>
<Triggers>
<asp:PostBackTrigger ControlID="whateverID" />
</Triggers>
<ContentTemplate>
...
</ContentTemplate>
</asp:UpdatePanel>


Well, that does not work:

a) the UserControl is designed separatly and does not have an update panel and vice versa the dialog is a generic control which just adds a UserControl as a content, so it cannot hardcode if there is any control ID inside which should trigger a full postback

b) I do not want a full postback to occur all the time when the button is pressed, the logic of the button on the server side should determine if a full postback is necessary or not, if not then a partial postback is OK.


I tried to work around now, kind of using your approach by doing this in the OnPreRender or OnChildControlsCreated of the UserControl:

System.Web.UI.WebControls.WebControl btnOK =this.Parent.Parent.FindControl("btnOK")as System.Web.UI.WebControls.WebControl;
if (btnOK !=null)
{
System.Web.UI.Control control = btnOK;
UpdatePanel updatePanel = control.ParentasUpdatePanel;
while ((updatePanel ==null) && (control !=null))
{
control = control.Parent;
updatePanel = controlasUpdatePanel;
}
if (updatePanel !=null)
{
PostBackTrigger pbTrigger =newPostBackTrigger();
pbTrigger.ControlID ="btnOK";
updatePanel.Triggers.Add(pbTrigger);
}
}

So I do find the OK button and I do find the UpdatePanel that contains the button, but it has no effect whatsoever.
The control ID must be right, otherwise I would not be able to find the button with it, but still no PostBack and the Dialog itself is not inside an UpdatePanel.

trigger is causing the user controls OnInit to fire

I have a TextBox inside an UserControl which triggers an update panel on TextChanged. Works really well, but I noticed a problem. When AJAX makes the call back to the server to execute the TextChanged event, it is actually firing the UserControl's overridden OnInit beforehand. Is this normal behavior? I would think that for a page, OnInit should only get called once - when the page is created. There is a good deal of initialization code in my OnInit that really should not be executed again if it does not have to. Is there a way to make the UpdatePanel trigger not fire OnInit?

AJAX postbacks are executed at the server like normal postbacks (the entire page lifecycle is processed from the beginning), so Page.IsPostback = True for AJAX postbacks.

Saturday, March 24, 2012

Trigger set to a userControl controls event

Hi Everyone,

I am pretty new to atlas and I am trying to figure out if it can do what i want it to do. I have a gridview control and a user control on a page. The user control has a button that I would like to have trigger the update panel on the aspx webform for the gridview.

When I do this I get a control ID not valid exception on the page. Is there a way to do this or am i only dreaming of better days?

Thanks

Calvin X

Is this not possible or nobody knows?

Were you able to figure this out? I am contemplating performing the same task, so I am interested if you have had some success.

Thank you!

trigger update panel without using controls

I have a bunch of links which I generate as a string and output to a label control. (its a database generated tag cloud). I want to update a gridview in an update panel when one of these tags/links is clicked. All these links exist outside of the update panel. How do I trigger such an update on the update panel??

Thanks in advance!

Andles

Hey Anderloo

I think these forum threads have the answer your looking for

http://forums.asp.net/thread/1645424.aspx

Triggering Dynamic Controls

Hi,

I got several Textboxes which are being created dynamically.

private TextBox CreateTextBoxes(int i)
{
TextBox tb = new TextBox();
tb.Width = 30;
tb.Height = 20;
tb.CssClass = "inputfield";
tb.ID = "TextBoxID" + i.ToString();
tb.Text = i.ToString();

Microsoft.Web.UI.ControlEventTrigger trig = new Microsoft.Web.UI.ControlEventTrigger();
trig.ControlID = this.FindControl(tb.ID.ToString()).ToString();
trig.EventName = "CheckChanged";
UpdatePanel1.Triggers.Add(trig);

return tb;
}

Throws an Error at FindControl:Object reference not set to an instance of an object.

When I don't use FindControl it compiles but the Event is never triggered. The dynamic Controls are wrapped in a static UpdatePanel1 via the designer.

Is that possible at all with Atlas yet?

The problem with this code is that you never added the dynamically created text box to any control collections. FindControl() works by traversing the controls collections, and control are only rendered (unless you call RenderControl() yourself) if they appear somewhere in the control collection tree for a page.

Actually, you have no reason in the code segment above to call FindControl(), because you have the class instance local to that scope. You would only use FindControl() to retrieve a control instance where you have no local variable assigned or had no way to retrieve the instance using other means.

The reason you never see the trigger is because the control you created in the code was never attached to anything that would have ended up visible on the client. If you added the control to the collection for after this code segment, you have no guarantee that the actual control ID generated once the page is rendered would be the same as you assume in this code, since control ID's actual values depend on their placement within the naming container "tree" starting from the page down.

My suggestion would be to never do anything that assumes a consistent control ID (and UpdatePanels depend on this for handling a variety of things on the client side) with a dynamic control until you have added it to a control collection that is attached to a page already. Then all the things that need to be wired to make your triggers (or commands or events) work will work.


The textbox method is called in a foreach loop, mostly about 4-6 textboxes are being created.

Is this maybe possible with the new Dynamic UpdatePanel featured in the new Atlas build?
The new UpdatePanel in the June CTP certainly does change the dynamics of the problem you described.

Triggering modal popup with javascript causes popup controls to be disabled and popup disa

I'm triggering a modal popup to popup in a javascript:

document.getElementById('ModalPopupTrigger').click();

The element specified is set as the TargetControl for the modal popup.

The popup does popup but the control's on it can't be used and the popup disappears automatically after ~ 2 seconds...

Any clues as to what's going on here?

Define the BehaviorID property of your ModalPopupExtender control and use its show() method. For example (taken from the toolkit sample):

<ajaxToolkit:ModalPopupExtender runat="server" ID="programmaticModalPopup" BehaviorID="programmaticModalPopupBehavior" TargetControlID="hiddenTargetControlForModalPopup" PopupControlID="programmaticPopup"
BackgroundCssClass="modalBackground" DropShadow="True" PopupDragHandleControlID="programmaticPopupDragHandle" >

Given that declaration, you can show the popup by calling $find('programmaticModalPopupBehavior').show()


Ok, both methods actually work. The problem turned out to be that the javascript was triggered by a link button in an update panel which was causing the panel with the popup to refresh. Changed it to a label and it works fine...

Triggering UpdatePanel with controls inside TabPanel

I have a TabContainer with several TabPanels inside, and several of the TabPanels contain Button controls.

<ajaxToolkit:TabContainer ID="InstructionTabs" runat="server" Height="300px">
<ajaxToolkit:TabPanel ID="XLSInstructions" runat="server" HeaderText="Excel">
<ContentTemplate>
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" />
</ContentTemplate>
</ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer>

Elsewhere on the page, I have an UpdatePanel (not contained inside theTabContainer or TabPanels), and I want to trigger this UpdatePanelusing one of the controls inside the TabPanels.

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
...
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSubmit" />
</Triggers>
</asp:UpdatePanel>

When I hardcode the Trigger, i get an error:

A control with ID 'btnSubmit' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.

Also, using the designer to set the Triggers collection on he UpdatePanel, none of the controls inside the TabPanels are visible, just the TabContainer control itself. Any ideas how to get the UpdatePanel to trigger off a control in a TabPanel?


What you can do is, trigger your UpdatePanel with a javascript function or call UpdatePanel1.Update() inside your btnSubmit_Click() function.

triggers for programmatically added controls

Hi!

I almos get crazy in here :-)

I have a Button and an UpdatePanel with a table in it. When the Button is pressed, the UpdatePanel fills up with MANY programmatically auto generated LinkButtons:

example:

void mybutton_Click(object sender, EventArgs e)

 {
LinkButton mylinkbutton =new LinkButton();
mylinkbutton.Text ="hallo";
mylinkbutton.ID ="mylinkbutton";
mylinkbutton.Click +=new EventHandler(mylinkbutton_Click);
mycell.Controls.Add(mylinkbutton);
}

where mycell is part of the Updatepanel and mybutton is a AsyncPostBackTrigger of the UpdatePanel.

The problem is the EventHandler of the several link buttons (mylinkbutton_Click). The Event doesnt get fired.

I already tried tons of solutions like

ScriptManager.RegisterAsyncPostBackControl(mylinkbutton);

within the mybutton_Click. Didnt work...

This page (http://ajax.asp.net/docs/tutorials/UsingUpdatePanelControls.aspx) tells me that I have to place the .RegisterAsynPostBackControl in the Page_Load() function, but how should I do this at runtime?

Any ideas? need help!

TIA

J

Try this:

ScriptManager.GetCurrent(Page).RegisterAsyncPostBackControl(mylinkbutton)

Thanks a lot, but I already tried that!

I use a usercontrol and therefore call the postbackcontrol like that:

ScriptManager.GetCurrent(Parent.Page).RegisterAsyncPostBackControl(mylinkbutton);

But it still doesnt work :(

i do it like that:

void mybutton_Click(object sender, EventArgs e) { LinkButton mylinkbutton =new LinkButton(); mylinkbutton.Text ="hallo"; mylinkbutton.ID ="mylinkbutton"; mylinkbutton.Click +=new EventHandler(mylinkbutton_Click); mycell.Controls.Add(mylinkbutton); ScriptManager mymanager = ScriptManager.GetCurrent(Parent.Page); mymanager.RegisterAsyncPostBackControl(mylinkbutton); }

Microsoft says that I should call RegisterAsyncPostBackControl() in Page_Load() but I cannot write it there because I dont know my LinkButtons at design time! :-(

any ideas?

thx Joe


Hi,

like every dynamic controls, your LinkButtons must be recreated on every postback (either synchronous or asynchronous).

When you click one of the dynamic LinkButtons, you fire an asynchronous postback but the corresponding control doesn't exist on the server side, because you've created it in a handler (mybutton_Click) that now doesn't get called.

Triggers for update panel

I have a web page (aspx) that has on it 2 controls (ascx) - one of the controls has an update panel with functionality for it etc. - I want to trigger the update function from the second control that has a linkbutton on it.

Is this possible?

TIA

Yes. Update panel has Triggers element which can be used as follows
 <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="lnkButton" EventName="Click"/> </Triggers> </asp:UpdatePanel>

It would seem so - but if the trigger and the update panel are in different ascx files they can not see each other - even if those ascx files exist as controls on the same aspx page

You can explicitly call Update method of another UpdatePanel like this:

UpdatePanel1.Update() ;

Assumption: LinkButton is in UpdatePanel2 and the above code is written in event handler for LinkButton click event.

Generally, you have this kind of scenario in Master-Detail relationship. There is tutorial onhttp://ajax.asp.net site about this.


Okay I dont think you are looking at what the question says - because this doesnt work - unless you can point me to the specific tutorial I cant find the one you are talking about

here is a simple picture that diagrams what I am trying to do

Page1.aspx has two controls on it - both controls are ascx files (Control1.ascx and Control2.ascx)

Control1.ascx has an image button that when clicked is to trigger the UpdatePanel on Control2.ascx

Example

Trouble Adding Toolkit Controls

When I attempt to add a toolkit control, my site crashes. I have non-toolkit ajax controls working just fine, but as soon as I add an extender(always visible) my site crashes.

If I preview it on my developing machine, it works fine, but then I get the following on the production machine:

Unable to cast object of type 'System.Web.Configuration.ScriptingScriptResourceHandlerSection' to type 'System.Web.Configuration.ScriptingScriptResourceHandlerSection'.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.InvalidCastException: Unable to cast object of type 'System.Web.Configuration.ScriptingScriptResourceHandlerSection' to type 'System.Web.Configuration.ScriptingScriptResourceHandlerSection'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[InvalidCastException: Unable to cast object of type 'System.Web.Configuration.ScriptingScriptResourceHandlerSection' to type 'System.Web.Configuration.ScriptingScriptResourceHandlerSection'.] System.Web.Configuration.ApplicationSettings.EnsureSectionLoaded() +70 System.Web.Handlers.ScriptResourceHandler.IsCompressionEnabled(HttpContext context) +7 System.Web.Handlers.RuntimeScriptResourceHandler.System.Web.Handlers.IScriptResourceHandler.GetScriptResourceUrl(Assembly assembly, String resourceName, CultureInfo culture, Boolean zip, Boolean notifyScriptLoaded) +30 System.Web.UI.ScriptReference.GetUrlFromName(ScriptManager scriptManager, IControl scriptManagerControl, Boolean zip) +293 System.Web.UI.ScriptReference.GetUrl(ScriptManager scriptManager, IControl scriptManagerControl, Boolean zip) +237 System.Web.UI.ScriptManager.RegisterScripts() +507 System.Web.UI.ScriptManager.OnPagePreRenderComplete(Object sender, EventArgs e) +111 System.EventHandler.Invoke(Object sender, EventArgs e) +0 System.Web.UI.Page.OnPreRenderComplete(EventArgs e) +2052172 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2247



Version Information: Microsoft .NET Framework Version:2.0.50727.1378; ASP.NET Version:2.0.50727.1378

As always, thanks again for all of your helpGeeked

I'm thinking it has something to do with IIS. If I preview it though VS2008's development server, it works fine, but when I run it through IIS is when my heartaches begin...

Wednesday, March 21, 2012

Trouble Retaining values entered or selected for controls inside an update panel

Hi,

Trouble in retaining values of dropdownlist, textboxes, and other controls when dropdownlist selectedindexchanged event is triggered, the controls are inside a user
control and this user control inside a parent user control with an update panel. Can you guys help me hwo to retain the values. I have set EnableViewState to true. Where
is correct page event to store entered and selected values before the values on controls are re-intialized. Please provide some codes and please eb specific unto which is best to use (Session variables, hiddenfields or others). Thanks in advanced.

den2005

Can you please actually provide code you are using and getting the issue with. Otherwise here are some links:

http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx


Hi jodywbcb,

I am working on 5 dropdownlist controls (these codes are created by a co-worker) and they are some how interdependent, first dropdown and second dropdown and third dropdown determines the data for fourth and fifth dropdown, now second dropdown determines the data for third dropdown. The thing is if the first dropdown is set to item 2, and second dropdown is set to to item2 and data selected on third dropdown remains set after postback.

Here at some data I am working on...So what mistake I have made..

protected override void OnLoad(EventArgs e){...this.UpdateContent();base.OnLoad(e);if (multiView.GetActiveView().ID =="viewInputForm"){if (Session["id"] !=null)ShowAssessmentDetails(Session["id"].ToString());DisplayProcessedIconImage();}}//All Dropdown SelectedIndexChanged Eventprotected void DropDown_SelectedIndexChanged(object sender, EventArgs e){if (sender ==this.ddlEmployee){...}else if (sender ==this.ddlCategory){FillSubCategoryList();FillCompetencyList();}else if (sender ==this.ddlSubCategory){if (ddlSubCategory.SelectedIndex != 0){int subcat = Int32.Parse(ddlSubCategory.SelectedValue);ddlCategory.SelectedValue = oAssessment.GetCategoryID(subcat);FillSubCategoryList();ddlSubCategory.SelectedValue = subcat.ToString();if (subcat.ToString() !=string.Empty && subcat.ToString() !="0")ViewState["ddlSubCategory"] = subcat.ToString();}FillCompetencyList();}else if (sender ==this.ddlCompetencyCode){UpdateCompetencyList(1);DoCourseCodeMatching();}else if (sender ==this.ddlCompetency){UpdateCompetencyList(2);DoCourseCodeMatching();}else if (sender ==this.ddlCourseCode){ClearSuggestedTrainingData();//FillTrainingData();DoCourseCodeMatching();}else if (sender ==this.ddlYear){...}else if (sender ==this.ddlCompetencyModel){FillCategoryList();FillSubCategoryList();FillCompetencyList();}...}private void ShowAssessmentDetails(string idVal){oAssessment.ID = Convert.ToInt32(idVal);if (oAssessment.Get()){InitializeControls();...FillCompetencyModelList();//First Dropdown...FillEmployeeData();try { ddlCompetencyModel.SelectedValue = oAssessment.CompetencyModelID.ToString(); }catch { ddlCompetencyModel.SelectedIndex = 0; }FillCategoryList();//Second DropDownFillSubCategoryList();//Third DropdownFillCompetencyList();//Fourth DropdownFillCourseCode();ddlCompetency.SelectedValue = oAssessment.CompetencyID.ToString();UpdateCompetencyList(2);try { ddlCourseCode.SelectedValue = oAssessment.CatalogueCourseID.ToString(); }catch { ddlCourseCode.SelectedIndex = 0; }...FillSupervisorApproval(cbTrainingRequest.Checked);FillLocalApproval(cbTrainingRequest.Checked);ddlCSApproval.SelectedValue = oAssessment.CompetencySupervisorApprovalID.ToString();ddlCLApproval.SelectedValue = oAssessment.CompetencyLocalApprovalID.ToString();...try { ddlSuggLocalTrainingType.SelectedValue = oAssessment.SuggestedLocalTrainingType.ToString(); }catch { ddlSuggLocalTrainingType.SelectedIndex = 0; }tbLocalTrainingSuggest.Text = oAssessment.SuggestedLocalTraining;try{ddlSuggTrainingType.SelectedValue = oAssessment.SuggestedTrainingType.ToString();tbSuggestedTraining.Text = oAssessment.SuggestedTraining;}catch{ddlSuggTrainingType.SelectedIndex = 0;tbSuggestedTraining.Text = String.Empty;}...}}private void InitializeControls(){...FillCompetencyModelList();...FillCategoryList();FillSubCategoryList();FillCompetencyList();FillSupervisorApproval(false);FillLocalApproval(false);...FillCourseCode();...}private void FillCompetencyModelList(){try{using (DataAccessLayer objDAL =new DataAccessLayer("CompetencyModel_GetAllByYear")){objDAL.AddParameter("Year", ddlYear.SelectedValue);objDAL.ExecuteReader();ddlCompetencyModel.Items.Clear();ddlCompetencyModel.Items.Add(new ListItem("-- select model --","0"));while (objDAL.DataReader.Read()){ddlCompetencyModel.Items.Add(new ListItem(MultiLanguageField.GetFieldValue(Convert.ToString(objDAL.DataReader["Name"])), Convert.ToString(objDAL.DataReader["CompetencyModelID"])));}}}catch{ddlCompetencyModel.Items.Clear();ddlCompetencyModel.Items.Add(new ListItem("-- select model --","0"));}}private void FillCompetencyList(){if (ddlCompetencyModel.SelectedIndex != 0){try{ddlCompetencyCode.Items.Clear();ddlCompetency.Items.Clear();ddlCompetencyCode.Items.Add(new ListItem("-- select code --","0"));ddlCompetency.Items.Add(new ListItem("-- select competency --","0"));if (ddlCompetencyModel.SelectedIndex == 0){if ((ddlSubCategory.SelectedValue !=null) && (ddlSubCategory.SelectedValue !="0")){using (DataAccessLayer objDAL =new DataAccessLayer("Competency_GetBySubCategoryIDAndYear")){SqlParameter sqlparam =new SqlParameter("@.subcat", SqlDbType.Int);sqlparam.Value = ddlSubCategory.SelectedValue;objDAL.AddParameter(sqlparam);objDAL.AddParameter("year", ddlYear.SelectedValue);objDAL.ExecuteReader();while (objDAL.DataReader.Read()){ddlCompetencyCode.Items.Add(new ListItem(Convert.ToString(objDAL.DataReader["CompetencyCode"]), Convert.ToString(objDAL.DataReader["CompetencyID"])));ddlCompetency.Items.Add(new ListItem(MultiLanguageField.GetFieldValue(Convert.ToString(objDAL.DataReader["Name"])), Convert.ToString(objDAL.DataReader["CompetencyID"])));}}}else if ((ddlCategory.SelectedValue !=null) && (ddlCategory.SelectedValue !="0")){using (DataAccessLayer objDAL =new DataAccessLayer("Competency_GetByCategoryIDAndYear")){SqlParameter sqlparam =new SqlParameter("@.catid", SqlDbType.Int);sqlparam.Value = ddlCategory.SelectedValue;objDAL.AddParameter(sqlparam);objDAL.AddParameter("year", ddlYear.SelectedValue);objDAL.ExecuteReader();while (objDAL.DataReader.Read()){ddlCompetencyCode.Items.Add(new ListItem(Convert.ToString(objDAL.DataReader["CompetencyCode"]), Convert.ToString(objDAL.DataReader["CompetencyID"])));ddlCompetency.Items.Add(new ListItem(MultiLanguageField.GetFieldValue(Convert.ToString(objDAL.DataReader["Name"])), Convert.ToString(objDAL.DataReader["CompetencyID"])));}}}else{using (DataAccessLayer objDAL =new DataAccessLayer("Competency_GetAllByYear")){objDAL.AddParameter("year", ddlYear.SelectedValue);objDAL.ExecuteReader();while (objDAL.DataReader.Read()){ddlCompetencyCode.Items.Add(new ListItem(Convert.ToString(objDAL.DataReader["CompetencyCode"]), Convert.ToString(objDAL.DataReader["CompetencyID"])));ddlCompetency.Items.Add(new ListItem(MultiLanguageField.GetFieldValue(Convert.ToString(objDAL.DataReader["Name"])), Convert.ToString(objDAL.DataReader["CompetencyID"])));}}}}else if (ddlCompetencyModel.SelectedIndex > 0){if ((ddlSubCategory.SelectedValue !=null) && (ddlSubCategory.SelectedValue !="0")){using (DataAccessLayer objDAL =new DataAccessLayer("Competency_GetBySubCatIDModelYear")){SqlParameter sqlparam =new SqlParameter("@.subcat", SqlDbType.Int);sqlparam.Value = ddlSubCategory.SelectedValue;objDAL.AddParameter(sqlparam);objDAL.AddParameter("year", ddlYear.SelectedValue);sqlparam =new SqlParameter("@.compmodelid", SqlDbType.Int);sqlparam.Value = ddlCompetencyModel.SelectedValue;objDAL.AddParameter(sqlparam);objDAL.ExecuteReader();while (objDAL.DataReader.Read()){ddlCompetencyCode.Items.Add(new ListItem(Convert.ToString(objDAL.DataReader["CompetencyCode"]), Convert.ToString(objDAL.DataReader["CompetencyID"])));ddlCompetency.Items.Add(new ListItem(MultiLanguageField.GetFieldValue(Convert.ToString(objDAL.DataReader["Name"])), Convert.ToString(objDAL.DataReader["CompetencyID"])));}}}else if ((ddlCategory.SelectedValue !=null) && (ddlCategory.SelectedValue !="0")){using (DataAccessLayer objDAL =new DataAccessLayer("Competency_GetByCatIDModelYear")){SqlParameter sqlparam =new SqlParameter("@.catid", SqlDbType.Int);sqlparam.Value = ddlCategory.SelectedValue;objDAL.AddParameter(sqlparam);objDAL.AddParameter("year", ddlYear.SelectedValue);sqlparam =new SqlParameter("@.compmodelid", SqlDbType.Int);sqlparam.Value = ddlCompetencyModel.SelectedValue;objDAL.AddParameter(sqlparam);objDAL.ExecuteReader();while (objDAL.DataReader.Read()){ddlCompetencyCode.Items.Add(new ListItem(Convert.ToString(objDAL.DataReader["CompetencyCode"]), Convert.ToString(objDAL.DataReader["CompetencyID"])));ddlCompetency.Items.Add(new ListItem(MultiLanguageField.GetFieldValue(Convert.ToString(objDAL.DataReader["Name"])), Convert.ToString(objDAL.DataReader["CompetencyID"])));}}}else{using (DataAccessLayer objDAL =new DataAccessLayer("Competency_GetAllByModelYear")){objDAL.AddParameter("year", ddlYear.SelectedValue);SqlParameter sqlparam =new SqlParameter("@.compmodelid", SqlDbType.Int);sqlparam.Value = ddlCompetencyModel.SelectedValue;objDAL.AddParameter(sqlparam);objDAL.ExecuteReader();while (objDAL.DataReader.Read()){ddlCompetencyCode.Items.Add(new ListItem(Convert.ToString(objDAL.DataReader["CompetencyCode"]), Convert.ToString(objDAL.DataReader["CompetencyID"])));ddlCompetency.Items.Add(new ListItem(MultiLanguageField.GetFieldValue(Convert.ToString(objDAL.DataReader["Name"])), Convert.ToString(objDAL.DataReader["CompetencyID"])));}}}}}catch{ddlCompetencyCode.Items.Clear();ddlCompetency.Items.Clear();ddlCompetencyCode.Items.Add(new ListItem("-- select code --","0"));ddlCompetency.Items.Add(new ListItem("-- select competency --","0"));}}else{ddlCompetencyCode.Items.Clear();ddlCompetency.Items.Clear();ddlCompetencyCode.Items.Add(new ListItem("-- select code --","0"));ddlCompetency.Items.Add(new ListItem("-- select competency --","0"));}}private void FillSubCategoryList(){try{if ((ddlCategory.SelectedValue !=null) && (ddlCategory.SelectedValue !="0")){using (DataAccessLayer objDAL =new DataAccessLayer("CompetencySubCategory_GetByCategoryID")){SqlParameter sqlparam =new SqlParameter("@.CatID", SqlDbType.Int);sqlparam.Value = ddlCategory.SelectedValue;objDAL.AddParameter(sqlparam);objDAL.ExecuteReader();ddlSubCategory.Items.Clear();ddlSubCategory.Items.Add(new ListItem("-- select subcategory --","0"));if (ddlCompetencyModel.SelectedIndex != 0){while (objDAL.DataReader.Read()){ddlSubCategory.Items.Add(new ListItem(MultiLanguageField.GetFieldValue(Convert.ToString(objDAL.DataReader["Name"])), Convert.ToString(objDAL.DataReader["CompetencySubCategoryID"])));}}}}else{using (DataAccessLayer objDAL =new DataAccessLayer("CompetencySubCategory_GetAll")){objDAL.ExecuteReader();ddlSubCategory.Items.Clear();ddlSubCategory.Items.Add(new ListItem("-- select subcategory --","0"));if (ddlCompetencyModel.SelectedIndex != 0){while (objDAL.DataReader.Read()){ddlSubCategory.Items.Add(new ListItem(MultiLanguageField.GetFieldValue(Convert.ToString(objDAL.DataReader["Name"])), Convert.ToString(objDAL.DataReader["CompetencySubCategoryID"])));}}}}// Even with/without these codes below still the sameif (ViewState["ddlSubCategory"] !=null && ddlSubCategory.Items.Count > 1){ddlSubCategory.SelectedValue = ViewState["ddlSubCategory"].ToString();ddlSubCategory.SelectedIndex = ddlSubCategory.Items.IndexOf(ddlSubCategory.Items.FindByValue(ViewState["ddlSubCategory"].ToString()));}}catch{ddlSubCategory.Items.Clear();}}


The first thing that comes to mind is your InitializeControls() method...

I see alot of "..." so not sure what that is comenting out...and probably irrelevant

However:

I would do this:

private void InitializeControls()
{
...

If (!Page.IsPostback)

{
FillCompetencyModelList();
...
FillCategoryList();
FillSubCategoryList();
FillCompetencyList();
FillSupervisorApproval(false);
FillLocalApproval(false);
...
FillCourseCode();

}
...
}

It appears you are always re-initializing your data which is not necessary...and may be always setting all of your databound controls to the initial page load values...

However your viewstate issue - you are never actually setting any viewstate values so:

// Even with/without these codes below still the same
if (ViewState["ddlSubCategory"] !=null && ddlSubCategory.Items.Count > 1)
{
ddlSubCategory.SelectedValue = ViewState["ddlSubCategory"].ToString();
ddlSubCategory.SelectedIndex = ddlSubCategory.Items.IndexOf(ddlSubCategory.Items.FindByValue(ViewState["ddlSubCategory"].ToString()));

}

1. You do not need to set the ddlSubCategory.Selected Value and SelectedIndex both at the same time...

2. Do not use the Viewstate of the control to try and re-select the controls select item - it may work but the whole point of the Events when the ddl is selectedindex changed is to already give you that value (in otherwords it is already selected)...in other words that code is not warranted or needed and nor will it ever actually do anything...

now if you were selecting a value in the ddlSubCategory based on say ddlSubCategory_Other then you would do this:

ddlSubCategory.SelectedValue = ddlSubCategory_Other.SelectedValue (if they matched values wise otherwise you would have to loop through the items and determine what should be selected..based on whatever matching criteria you have.)

Suggestions:

Do not reference viewstate for your selected index or values and definately do not try to use both SelectedIndex and SelectedValue...

Code Sample:

For instance here is a simple DDL that populates a string with a mode name:

modeName = dropFilterBy.SelectedValue.ToString();

{do something with it}

Now if I want to keep the modeName in viewstate this is what I would do...

publicstring modeName

{

get

{

return (string)ViewState["modeName"] !=null ?

(

string)ViewState["modeName"] :"Unknown";

}

set { ViewState["modeName"] =value; }

}

That allows me to use the ModeName in code to reference values and not call the dropFilterBy.SelectedValue.ToString(); for proccessing in other areas of the code where I may need the value...

Again the infinitesloop link I responded with earlier - he has two great series on viewstate and understading controls - easy to read and will shed even more info on how to properly use viewstate....and how the page life cycle all works...


jodywbcb:

The first thing that comes to mind is your InitializeControls() method...

I see alot of "..." so not sure what that is comenting out...and probably irrelevant

I think for this part of problem the values of 5 dropdownlist control they are irrelevant, because they are for other sections of the user control.

jodywbcb:

However:

I would do this:

private void InitializeControls()
{
...

If (!Page.IsPostback)

{
FillCompetencyModelList();
...
FillCategoryList();
FillSubCategoryList();
FillCompetencyList();
FillSupervisorApproval(false);
FillLocalApproval(false);
...
FillCourseCode();

}
...
}

It does not work, the data is still not retain, no change in situation

jodywbcb:

It appears you are always re-initializing your data which is not necessary...and may be always setting all of your databound controls to the initial page load values...

Hmmm...the child user control is inside an update panel control(Atlas control) of the parent user control, if I do not repopulate the data then after postback there will be no data.

jodywbcb:

However your viewstate issue - you are never actually setting any viewstate values so:

// Even with/without these codes below still the same
if (ViewState["ddlSubCategory"] !=null && ddlSubCategory.Items.Count > 1)
{
ddlSubCategory.SelectedValue = ViewState["ddlSubCategory"].ToString();
ddlSubCategory.SelectedIndex = ddlSubCategory.Items.IndexOf(ddlSubCategory.Items.FindByValue(ViewState["ddlSubCategory"].ToString()));

}

1. You do not need to set the ddlSubCategory.Selected Value and SelectedIndex both at the same time...

2. Do not use the Viewstate of the control to try and re-select the controls select item - it may work but the whole point of the Events when the ddl is selectedindex changed is to already give you that value (in otherwords it is already selected)...in other words that code is not warranted or needed and nor will it ever actually do anything...

now if you were selecting a value in the ddlSubCategory based on say ddlSubCategory_Other then you would do this:

ddlSubCategory.SelectedValue = ddlSubCategory_Other.SelectedValue (if they matched values wise otherwise you would have to loop through the items and determine what should be selected..based on whatever matching criteria you have.)

Suggestions:

Do not reference viewstate for your selected index or values and definately do not try to use both SelectedIndex and SelectedValue...

Don't follow you here, I just trying both lines of code to solve the problem..no difference.

jodywbcb:

Code Sample:

For instance here is a simple DDL that populates a string with a mode name:

modeName = dropFilterBy.SelectedValue.ToString();

{do something with it}

Now if I want to keep the modeName in viewstate this is what I would do...

publicstring modeName

{

get

{

return (string)ViewState["modeName"] !=null ?

(

string)ViewState["modeName"] :"Unknown";

}

set { ViewState["modeName"] =value; }

}

That allows me to use the ModeName in code to reference values and not call the dropFilterBy.SelectedValue.ToString(); for proccessing in other areas of the code where I may need the value...

Again the infinitesloop link I responded with earlier - he has two great series on viewstate and understading controls - easy to read and will shed even more info on how to properly use viewstate....and how the page life cycle all works...

Don't exactly follow you on this, are you telling not to use viewstate of control but use a ViewState object? Any other ideas?

This part of page appears when a user clicks a button either add/edit "item" link inside a Gridview.

Thanks for the reply..

Dennis


Forgot to add..

CompetencyModel

Category

SubCategory

2 more data

When Category is set to Item2, Item 1 is "-- select a category --", when I change the selected value on SubCategory, the value is retain after postback, but when Category is set to any other values or other dropdown values changes, the values is not being retain..

Please advise for ideas.


Correction previous issues, it seems when Dropdown 1 is set to a default value not item1 and so as Dropdown 2, values are being retain after postback, otherwise no values are retain... So, how do I retain values?

Trouble with Accordion Panel inside a Modal Popup

When I use modal popup to show the tab control and other controls, the modal popup resizes correctly. Granted, the shadow behind does not, but this is avoidable by removing the drop shadow. The problem comes when I try to use an accordion panel inside a modal popup. The accordion panel doesn't respond well to clicks and the modal popup window does not resize to compensate for the dynamic panel. I encased the accordion panel in a regular panel so I could give the modalpopup extender's popupcontrolID something to play with.

I'm sure I'm doing something wrong here, but I cannot figure out what is happening exactly. Anyone experienced anything similar to this or know of a solution? Thanks!Big Smile

Bump?Angel

Trouble with code-behind accessing form controls

Hey everyone. I'm having a problem in VS2008 and the toolkit. It's kind of hard to explain but I will do my best.

I'm having trouble with accessing properties from an AJAX entended ASP.NET control in the code-behind file. It happens on both my own project and in every project that uses code-behind in the SampleWebSite.

I'm using the Toolkit 3.5, no custom build, using the binary from the 3.5 SampleWebSite bin directory.

I took several screenshots to help show what I mean.

This first screen just shows the panel (login panel) that i want to have popup in the Modal extender.

There is a ScriptManager and a ModalPopupExtender in the HTML code (see below)

<ajaxToolkit:ToolkitScriptManagerID="ScriptManager1"runat="server"/>

<ajaxToolkit:ModalPopupExtenderID="ScriptManager1_ModalPopupExtender"

runat="server"TargetControlID="btnSignIn"

PopupControlID="pnlLoginModal"CancelControlID="btnModalCancel"

DropShadow="True"OkControlID="btnModalOk"

BackgroundCssClass="modalBackground"PopupDragHandleControlID="pnlModalDrag">

</ajaxToolkit:ModalPopupExtender>

The second screenshot shows what happens when I try to get the "Text" property of the Textbox inside the modal panel (not in run time, in code)

Notice the tooltip. Is this a normal behavior for AJAX or am I doing something wrong? I don't understand because every time the code-behind files in the SampleWebSite try and use a property is shows as an invalid symbol also.

Thanks for any help.

--Matt

I don't know if there is any signifigance to this but, I tried and opened the SampleWebSite for the .NET 2.0 runtime and the code-behind works fine. Is there something in the 3.5 reference list that needs to be changed when working with 3.5 and the toolkit designed for 3.5 or what?

Here is another screenshot with the Control toolkit solution opened and the CascadingDropDown code-behind showing (unaltered by myself). Notice all the invalid symbols..

I'm using VS2008 with all .NET runtimes installed on XP sp2. I really need to figure out what's going on so any suggestions would be great. Thanks,

--Matt


Nevermind; I found out what was going on after researching for a few hoursAngry It turns out ReSharper from Jetbrains doesn't like AJAX in the current build hence it flags its properties as illegal. It builds fine but still annoying.

Thanks to all who read my post..

--Matt

Trouble with Control Toolkit

Hello,

I am using the ASP.NET Ajax Control Toolkit with Visual Web Developer. I am not able to see the controls from the toolkit when I drag and drop. The only way to see the object is to find them in the properties box and adjust properties but not be able actually see them.

It would be appreciated if someone could explain how to install the control toolkit in Visual Web Developer. B/c i feel i have installed in the wrong manner.

Hi,

Everything sounds like it was setup correctly. Most of the components in the Toolkit areExtenderControls which just add new properties to the controls they extend in the designer.

Thanks,
Ted

Thank You that is what I was looking for!


Thanks that was what I was looking for!

Trying to hide controls on UpdatePanel

I have an UpdatePanel on which there sits a dropdownlist of providers and two labels that show the providers AU and Activity #. When the selectedIndex of the dropdown is zero, I want to hide the labels. I have tried both asp:panel controls with height=0 set in the code behind SelectedIndexChanged event and html div with style.visibility = 'hidden' in a javascript onchange event for the dropdown, and neither does anything. No errors, it just doesn't do anything. Here is my page code.

<asp:UpdatePanel id="UpdatePanel1" runat="server">
<contenttemplate>
<asp:DropDownList id="ddlProviders" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlProviders_SelectedIndexChanged"></asp:DropDownList>
<BR />
<DIV style="WIDTH: 100%; HEIGHT: 100%" id="divProviderDetail" noWrap>
<asp:Label id="Label1" runat="server" Text="AU#: " __designer:wfdid="w20"></asp:Label>
<asp:Label id="lblProviderAU" runat="server" __designer:dtid="844424930132022" __designer:wfdid="w17"></asp:Label> <BR />
<asp:Label id="Label2" runat="server" Text="Activity #: " __designer:wfdid="w21"></asp:Label>
<asp:Label id="lblActivityNumber" runat="server" __designer:dtid="844424930132024" __designer:wfdid="w18"></asp:Label>
</DIV>
<BR />
</contenttemplate>
</asp:UpdatePanel>

Any ideas? Thanks.

Protected Sub ddlProviders_SelectedIndexChanged(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles ddlProviders.SelectedIndexChanged
If (ddlProviders.SelectedIndex = 0)Then
lblProviderAU.Visible =False
lblActivityNumber.Visible =False
Else
lblProviderAU.Visible =True
lblActivityNumber.Visible =True
End If
End Sub

Or you could use a panel and set Visible = False for that.


whats the code you using at ddlProviders_SelectedIndexChanged

coz the aspx looks fine here


When I used a panel, I set height=0 so as to not leave a big blank spot. That didn't do anything, height was still the same.


If you don't want anything to move, then just change their text to "" rather than changing their height or visibility.


Setting an element's display CSS property to 'none' is a good way to hide elements on the client side. It has the advantage of not removing them from the DOM or rendered HTML (as is the case with those other methods), so you can still manipulate them on the client side later if need be.


document.getElementById('lblAU').class = 'none';

gave me an error when VS scanned the .js file at start. What is the correct syntax?


document.getElementById('lblAU').style.display = 'none';

or if you have a css class

.hide {display: none;}

document.getElementById('lblAU').className = 'hide';

Two-way data binding problem with Atlas UpdatePanel

I have an existing ASP 2.0 page which utilizes a SQLDataSouce and a FormView with bound controls. The page has a "save" button which saves the contents of the bound controls to the database. It works fine when not using Atlas.

One of the textboxes on the form is a date field. I want to use Atlas and the .Net Calendar control to provide a popup calendar. I implemented the calander based upon some simple example code I found in the Atlas tutorial. The popup works great and the value from the calendar is correctly placed into the target textbox.

The problem I am having is that wrapping the UpdatePanel around the textbox causes it to lose two-way databinding.It correctly displays the initial value from the current database record but, when attempting to do and update the value is always NULL. Does anyone know what I may be missing. Below is the Atlas markup wrapped around the textbox:

Thanks,

Tony

<atlas:updatepanel id="upCallReportDateTime" runat="server" mode="Conditional" rendermode="Inline"
<triggers>
<atlas:controleventtrigger controlid="calDatePicker" eventname="SelectionChanged" />
</triggers>

<contenttemplate>
<asp:textbox id="txtCallReportDateTime" runat="server"
Width="150px"
Text='<%# Bind("CallReportDateTime") %>'
CssClass="EditTextBox"
ontextchanged="txtCallReportDateTime_TextChanged"
autopostback="true"/>
<asp:imagebutton id="cmdPickDate_CallReportDateTime" runat="server"
onclick="cmdPickDate_CallReportDateTime_Click"
imageurl="graphics/calendar.gif"
height="20px"
width="20px"
CausesValidation="false" />
</contenttemplate>
</atlas:updatepanel>

Were you ever able to solve this problem? I am having the exact same problem.

The only way I've solved it so far is to add the missing parameter in the FormView_ItemInserting event.

This works well but it seems like I shouldn't have to do that.