Ektron Multiview not switching views - c#

Completly stumped here, Im creating a widget in ektron that was working fine 2 days ago and all the sudden all events stopped working for no reason. Ive been trying to track down the culprit to no avail.
My aspx file is a basic multiview with two views, one for edit settings and the other for content.
<%# Control Language="C#" AutoEventWireup="true" CodeFile="ContentPlus.ascx.cs" Inherits="widget_ContentPlus" Debug="true" %>
<asp:multiview ID="contentPlusWidget" runat="server">
<asp:View ID="vEdit" runat="server">
<table>
<tr>
<td class="label">Content: </td>
<td><asp:DropDownList ID="ddlContentType" runat="server" class='displayType'></asp:DropDownList></td>
</tr>
<tr>
<td><asp:Button ID="btnSave" runat="server" Text="Save" /></td>
<td><asp:Button ID="btnCancel" runat="server" Text="Cancel" /></td>
</tr>
</table>
</asp:View>
<asp:View ID="vContent" runat="server">
<!-- Content Code -->
</asp:View>
</asp:multiview>
Then in the contentplus.ascx.cs file I have my page events and then my btn events
protected void Page_Init() {
_host = Ektron.Cms.Widget.WidgetHost.GetHost(this);
_host.Title = "My Widget";
_host.Edit += new EditDelegate(EditEvent);
_host.ExpandOptions = Expandable.ExpandOnEdit;
btnSave.Click += new EventHandler(btnSave_Click);
btnCancel.Click += new EventHandler(btnCancel_Click);
}
protected void Page_Load() {
if(!this.IsPostBack)
ChangeViewTo(vContent);
}
protected void btnSave_Click(object sender, EventArgs e) {
Javascript.Alert("SAVED!");
SaveSelectedIndex();
ChangeViewTo(vContent);
}
protected void btnCancel_Click(object sender, EventArgs e) {
Javascript.Alert("CANCEL!");
ChangeViewTo(vContent);
}
public void EditEvent(string settings) {
Javascript.Alert("EDIT!");
ChangeViewTo(vEdit);
PopulateDropDownBoxWithAvailableContent();
}
void ChangeViewTo(View view) {
Javascript.ConsoleLog(view.ID);
contentPlusWidget.SetActiveView(view);
if(view.Equals(vEdit))
PopulateDropDownBoxWithAvailableContent();
}
Several things are not working, first when the settings button is clicked, the screen turns grey with the spinning icon and when it comes back nothing has happened. This usually happens when the _host.Edit += new EditDelegate(EditEvent); delegate has not been set, but as you see it has been. Second, When I set the settings view to default, and I press the save or cancel buttons, you get the spinning dialog and then nothing. The event code is never triggered. But you can see that I assigned the event delegate in Page_Init()
I feel like Im missing something obvious but Ive been stumped for a day. Any ideas?
Edit: changed title to reflect current understanding of the issue

OK found the solution and ill post it for anyone else.
When Ektron does a ajax postback it expects the response to be in the format
1|#||4|6696|updatePanel|ctl00_cphBillBoard_dzLeft_updatepanel|
<div id="ctl00_cphBillBoard_dzLeft_dzcontainer" class="dropzone PBClear" EditMode="true">....<the rest of your content>.....
Those pipes in the beginning are very important, in several places in my code I was dynamically injecting javascript for debugging inside the browser purposes, I was also logging some error messages to the screen using Response.Write();
these got injected before my pipes so it messed up the ajax request. When I realized this and removed all my logging, everything worked!

Related

Button_Click method no longer works

I am modifying a large (11 page) web form that I inherited from a previous employee. I am new at ASP and HTML5, etc. I modified many lines of code, but I haven't touched the button code in either HTML or C#. The Button_Click method used to work, in that clicking the button would run the form validation code and the data saving code. Here is the HTML:
<div style="position: relative; float: right">
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" class="btn btn-primary" />
</div>
And here is the code-behind for Button_Click:
protected void Button1_Click(object sender, EventArgs e)
{
if (ValidationForm())
{
SaveData();
}
}
I put breakpoints inside Button1_Click and the function is never entered. Is there another way to debug to see what's going on?
Here's the top of the aspx page:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="smacklabProject._default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
...
I have not changed the inherits. I don't even know what inherits does.
Here's the top of the aspx.cs (below using):
namespace smacklabProject
{
public partial class _default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (ValidationForm())
{
SaveData();
}
}
private void SaveData()
{
string study = Study_Dropdown.SelectedValue;
...
OK this happened to me once.
So if you're using visual studio, click the button at the top that has the start sign to run it and start debugging.
If you run it by right-clicking it from the solution explorer and selecting the view in browser option, it would not consider the back-end code.
I can't comment yet Sadly that's why i had to post this as an answer.
A co-worker solved the problem for me. There was a hidden text box that had a range validator and a default value that was outside of the range. So it would always fail validation, but the failure text was hidden.
For reference, never do this:
<p>
<asp:RangeValidator runat="server" ID="RangeValidator1" ControlToValidate="IPAQ_Q2_Days" MinimumValue="1" MaximumValue="7" Type="Double" Text="The value must be from 1 to 7" Font-Size="Large" ForeColor="Red" />
</p>
<asp:Label ID="IPAQ_Q2_Days_Label" AssociatedControlID="IPAQ_Q2_Days" ForeColor="White" Font-Size="11" Font-Weight="Normal" Text="Please indicate the number of days you performed vigorous activities at work." runat="server">
<asp:TextBox ID="IPAQ_Q2_Days" runat="server" class="form-control" placeholder="___ days per week" Width="200" value="0"></asp:TextBox>
</asp:Label>

Data not bound for ListView on postbacks

I am writing some message panel as a user control. The code looks like this (shortened for clarity)
protected void Page_PreRender(object sender, EventArgs e)
{
BindMessages(MessageType.Error, ErrListView);
}
private void BindMessages(MessageType type, ListView target)
{
List<string> messages = Session.PopMessages(type);
target.DataSource = messages;
target.DataBind();
}
ascx:
<asp:ListView runat="server" ID="ErrListView">
<ItemTemplate><li><%# Container.DataItem %></li></ItemTemplate>
</asp:ListView>
The code gets executed on each request (initial page load and postback) as it should, and the messages come out of the SessionState correctly. However, if the request is a postback, the messages are not actually updated (as if the DataBind() would not happen).
Anyone got a clue whats going on?
The reason I failed here was that my content did not contain an UpdatePanel. Changing my ascx file to include said control resolved my issues.
<asp:UpdatePanel runat="server" ID="StatusUpdatePanel">
<ContentTemplate>
<ul Class="Errors">
<asp:ListView runat="server" ID="ErrListView">
<ItemTemplate><li><%# Container.DataItem %></li></ItemTemplate>
</asp:ListView>
</ul>
</ContentTemplate>
</asp:UpdatePanel>

Add onclick to div for page redirect from code behind without use of anchor

I feel like this is a very simple solution that I am overlooking somehow. Basically I have a web page (using asp.net webforms) with a datalist. Inside my datalist, and inside the datalist items I have a div that I want the user to be able to click to cause a page redirect. I would like to do this without use of an anchor or javascript if possible. My datalist:
<asp:DataList ID="DataList1" ..etc >
<HeaderTemplate>
..etc
</HeaderTemplate>
<ItemTemplate>
<table >
<tr >
<td>..etc</td>
<td>..etc</td>
<td ><div id="clr_div" runat = "server"></div></td> <-- this is the div to be clicked
</tr>
</table>
</ItemTemplate>
And then in my code behind
protected void on_item_databound(object sender, DataListItemEventArgs e)
{
System.Web.UI.HtmlControls.HtmlGenericControl div = (System.Web.UI.HtmlControls.HtmlGenericControl)e.Item.FindControl("clr_div");
div.Attributes.Add("onclick", "**What goes here??**");
}
I have tried to put in the 'what goes here' section:
window.location.href = \"default.aspx\" **doesn`t work, the quotes don`t render properly in html
window.location.href = default.aspx **doesn`t work
return Response.Redirect(default.aspx); **doesn`t work
Any help is welcome. Thanks
The answers listed should help you out once you fix your div issues. I have experienced event firing issues in non-fixed divs when using static positioning, so you might want to try specifying position:relative on your containing div in question if you have fixed divs elsewhere.
Difference between static and relative positioning
Also, TMTOWTDI. If you have an empty div, you could just also turn it into a button for an insignificant markup cost
as explained here
Just add an ItemCommand event to your datalist
<asp:DataList ID="DataList1" onitemcommand="on_item_Command" ..etc..
and change this
<div id="clr_div" runat = "server"></div>
to this
<asp:Button id="clr_div" CommandName="nav-to-page" runat="server" CommandArgument='<%# Eval("field to eval if this came from a datasource") %>' />
and in code behind
protected void on_item_Command(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "nav-to-page")
{
string s = (string)e.CommandArgument;
Response.Redirect("NewPage.aspx?" + s);
}
}

Repeater's Item command event is not firing on linkbutton click

I am having problem with my repeater's OnItemCommand event.
When I click the Link Button, its not firing.
Am I missing any environment variable
ASPX code
<table>
<!-- repResearchers begin, 0=display name, 1=url -->
<asp:Repeater ID="repExtResearchers" Runat="server" OnItemCommand="deleteResearcher">
<ItemTemplate>
<tr>
<td>
<a href="<%# ((System.String[])Container.DataItem)[1] %>">
<%# ((System.String[])Container.DataItem)[0] %></a>
</td>
<td>
<asp:LinkButton ID="lbDelete" runat="server" CommandName="del"
CommandArgument = "<%# ((System.String[])Container.DataItem)[1]%>"
OnClientClick="if (!confirm('Are you sure do you want to delelte it?')) return false;">Delete</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
CS
protected void deleteResearcher(object sender, RepeaterCommandEventArgs e)
{
string a;
lblError.Text = e.CommandArgument.ToString();
lblError.Visible = true;
}
Make sure you dont rebind the repeater at every postback.
If (Page.IsPostBack)
return;
repExtResearchers.DataSource = ...
repExtResearchers.DataBind();
Hope that helps.
I'm sure - as this is an EXTREMELY old question - that this has been answered already, but for people who may be running into what I was running into...
If you're using any of the Ajax Controls, they all require a validation group. I had a really long page that I was trying to shorten by doing this, so I wasn't noticing that the ajax controls from the Ajax Control Toolkit were throwing errors and not validating. I set the LinkButton's validation group to something that was nowhere anywhere and it started firing.
Hopefully, that helps someone out.
It won't fix your ptoblem but change
OnClientClick="if (!confirm('Are you sure do you want to delelte it?')) return false;"
to
OnClientClick="return confirm('Are you sure do you want to delelte it?')"
Your code is using a double negative to confirm a positive.
I had this issue using OnCommand in a LinkButton and I had an empty href="". When I removed the extra attribute, it posted back.

Accessing Code Behind for a Control in a Master Page

I need to display a control consistently across a set of pages. So I'm using a MasterPage to do that in ASP.NET/C#. However I also need to programmatically access this control, mostly provide options to view/hide depending on whether the controls checkbox is clicked.
Here is the Source for the MasterPage
<div id="verifyInitial" runat="server">
<asp:CheckBox ID="chkInitialVerify" runat="server"
oncheckedchanged="chkInitialVerify_CheckedChanged" />
I agree that my initial data is correct.
</div>
<div id="verifyContinuous" runat="server">
<asp:CheckBox ID="chkContinuousVerify" runat="server"
oncheckedchanged="chkContinuousVerify_CheckedChanged" />
I agree that my continuous data is correct
</div>
Now in the code behind I want to perform the following operations. Basically if a person clicks on the checkbox for the initial div box, then the initial box disappears and the continous box shows up. However it seems that the code behind for the MasterPage does not activate whenver I click on the checkbox. Is that just the way MasterPages are designed? I always thought you could do add some sort of control functionality beyond utilizing the Page Load on the Master Page.
protected void chkInitialVerify_CheckedChanged(object sender, EventArgs e)
{
verifyContinuous.Visible = true;
verifyInitial.Visible = false;
}
protected void chkContinuousVerify_CheckedChanged(object sender, EventArgs e)
{
verifyContinuous.Visible = false;
}
If you're expecting the two controls to trigger a change for that page immediately then you'll need to set the AutoPostBack property to true for both of them:
<div id="verifyInitial" runat="server">
<asp:CheckBox ID="chkInitialVerify" runat="server" oncheckedchanged="chkInitialVerify_CheckedChanged" AutoPostBack="true" />
I agree that my initial data is correct.
</div>
<div id="verifyContinuous" runat="server">
<asp:CheckBox ID="chkContinuousVerify" runat="server" oncheckedchanged="chkContinuousVerify_CheckedChanged" AutoPostBack="true" />
I agree that my continuous data is correct
</div>
Otherwise, you need an <asp:button /> or some other control on the page to trigger a postback and cause your event handlers to run. The button, or other control, can either be on your masterpage or on your content page, the choice is entirely yours.

Categories

Resources