Showing posts with label wrapper. Show all posts
Showing posts with label wrapper. Show all posts

Saturday, March 24, 2012

Wrapper control for Slider Extender and Properties

I've written a control and that inherits from Panel and ITextControl. In CreateChildControls I create a table containing a text box and label, then I create the slider extender and properties pointing to the appropriate controls. The control loads properly (visually), but when I click the slider I get a series of javascript errors (Invalid Argument). If anyone has any suggestions they would be helpful.

Hi,

could you post the code that instantiates the slider extender?


/// <summary>
/// This web control class renders a Centralpoint console textbox.
/// </summary>
[ValidationProperty("Text")]
public class ConsoleSlider : Panel, ITextControl
{
private TextBox tbxSlider = null;
private Label lblTarget = null;
private SliderExtender seExtender = null;
private SliderProperties seProperties = null;

public ConsoleSlider() : base()
{
}

/// <summary>
/// This method is overridden to create the child controls of the console editor.
/// </summary>
protected override void CreateChildControls()
{
base.CreateChildControls();

HtmlTable table = new HtmlTable();
this.Controls.Add(table);

HtmlTableRow row = new HtmlTableRow();
table.Rows.Add(row);

HtmlTableCell left = new HtmlTableCell();
row.Cells.Add(left);

HtmlTableCell right = new HtmlTableCell();
row.Cells.Add(right);

tbxSlider = new TextBox();
tbxSlider.ID = this.ID + "_Slider";
left.Controls.Add(tbxSlider);

lblTarget = new Label();
lblTarget.ID = this.ID + "_Target";
right.Controls.Add(lblTarget);

seExtender = new SliderExtender();
seExtender.ID = this.ID + "_Extender";

seProperties = new SliderProperties();
seProperties.ID = this.ID + "_Properties";
seProperties.Minimum = 0;
seProperties.Maximum = 100;
seProperties.Steps = 1;
seProperties.Length = 300;
seProperties.EnableHandleAnimation = true;
seProperties.Orientation = SliderOrientation.Horizontal;

seProperties.TargetControlID = tbxSlider.ID;
seProperties.BoundControlID = lblTarget.ClientID;
seExtender.TargetProperties.Add(seProperties);

this.Controls.Add(seExtender);
}

/// <summary>
/// Gets or sets the control text.
/// </summary>
public string Text
{
get { this.EnsureChildControls(); return lblTarget.Text; }
set { this.EnsureChildControls(); lblTarget.Text = value; }
}
}


Hi,

mkerchenski:

seProperties.Steps = 1;

the problem is in the above statement, since it has no sense to set 1 step (it means 1 possible value, so there would be no need for a slider).

However, this is a "pathological" case that causes a bug since the slider extender is not able to handle this situation at the moment. I'll make sure to fix this for the next release.

Since the number of steps is the number of possible values, try to set steps > 1 and let me know if it solves the problem.

You can found a related threadhere.


I've tried a few different values for the Steps property and it doesn't seem to make any difference at all. If you disable script debugging (in IE) the control doesn't slide, and if you enable script debugging you get the error described initially. In the firefox javascript console I get the following errors:
Error: Found unclosed string '"'. Selector expected. Ruleset ignored due to bad selector.
Error: Unexpected end of file while searching for closing } of invalid rule set.
I'm not entirely sure they're related, but they're not there when the slider is not present.

Wrapper for getElementsByTagName?

Does the client reference have a wrapper for document.getElementsByTagName like it does with ById/$get ?

Sorry the current version as well as the future does not not have any shortcut. But the future has a new shortcut which works on the css selector.


Is there some way through the client stack to check if a dom element has had a certain handler already added? Say I want to check if a textbox already has a handler {focus:SomeFunction} before I add the handler?


No, client reference doesn't have a wrapper for document.getElementsByTagName like it does with ById/$get


There's no 'wrapper' for ~ByTagName but you could easily write your own and put it in a utils file that you pull down. e.g.:

function $getTags(tagName){
return document.getElementsByTagName(tagName);
}

you can get a list of event handlers by calling get_events() on your element. To do what you're asking, you could say something like, var focusHandler = el.get_events().getHandler('focus'); if focusHandler is null, then you know you don't have anything handling focus yet.