I have a .NET question. For my particular application which is catoring to mobile devices (specifically blackberry at the moment), I am using validators (required field validator to be exact).
The problem is that I have disabled javascript from asp.net (by specifying ClientTarget="ie4", but setting EnableClientScript="False" on the validator tags has the same effect). The actual issue is that when the validator is invisible, it emits "nbsp;" instead of nothing, is there some way to override this unwanted result?
Please do not reply solutions that include css or javascript, as I am unable to use either in my particular situation.
Thank you.
Display=Static means that a single nonbreaking space (" ") is emitted. This last behavior exists so that table cells containing only validators do not collapse to nothing when valid.
From here.
As Frédéric Hamidi said, you could try Display=Dynamic instead, but if you're insistent on using Display=Static, I think your only option is to extend the validator and override the Render method.
protected override void Render(HtmlTextWriter writer)
{
if (this.Display == ValidatorDisplay.Static && this.IsValid)
{
writer.Write(String.Empty);
}
else
{
base.Render(writer);
}
}
Static validators will indeed render an entity when hidden.
Try using dynamic validators instead, by setting their Display property to ValidatorDisplay.Dynamic.
Related
I want to change the update mode like here. This is my code:
this.datePicker.On<iOS>().SetUpdateMode(UpdateMode.WhenFinished);
The first part is marked as wrong this.datePicker.On<iOS>() and it is referencing an object in the xaml. On other places the same code is working fine. Don't know what's wrong here. The error message is:
Returns the platform-specific instance of this DatePicker, on which a platform-specific method may be called.
'IPlatformElementConfiguration' does not contain a definition for 'SetUpdateMode' and the best extension method overload 'Picker.SetUpdateMode(IPlatformElementConfiguration, UpdateMode)' requires a receiver of type 'IPlatformElementConfiguration'.
Any suggestion?
Edit:
It seems that the desired behavior (updateMode) is only available for Picker and not DatePicker. See here or here. Is there a way to enable the feature also for Datepicker? How?
Using Xamarin Forms 4.6 here. Inside your custom renderer use this code:
protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e)
{
base.OnElementChanged(e);
if (e.NewElement != null && Control != null)
{
...
Element.On<Xamarin.Forms.PlatformConfiguration.iOS>().SetUpdateMode(UpdateMode.WhenFinished);
...
}
}
Sadly, UpdateMode is not available for Date picker.
And the workaround i found,is to create a custom calendar(which i did).Custom calendar looks tough to create,but is quite simple to implement(of basic functionalities) .
With only 1 month of experience in xamarin, i've created it.
You can check out the complete code here:
https://medium.com/#bhavyajoshi2793/custom-calendar-in-xamarin-for-android-ios-windows-578f1136daec?source=friends_link&sk=9b1c97e0021da2e48ec84b5b6d4ff8e4
In trying to make my ASP.Net 4.0 site validate to HTML5 the best I can with the current specification. I have a DataList that always adds cellspacing="0" I've tried different ways of removing the cellspacing="0". I have added a CSS style sheet which does flow over.
Anyone know how to make the DataList conform to the HTML 5 validation?
Actual Code:
Validation Error Message: The cellspacing attribute on the table element is obsolete. Use CSS instead.
Generated Code:
I am not a big fan of DataList - many time, the markup generates is table based and hence semantically incorrect. So I will suggest to use some alternate control such as Repeater or ListView if possible.
Now, if you are in situation where you have plenty of data lists... one of the solution would be to have your own custom DataList control to explicitly override cellspacing attribute such as
public class MyDataList : DataList
{
protected override Style CreateControlStyle()
{
var s = new TableStyle();
s.CellSpacing = -1;
return s;
}
}
You can then probably use ASP.NET Tag Mapping to substitute built-in data-list with your implementation across all pages from config.
I am generating XHTML for a non-standard browser (Polycom Microbrowser). I would like to use the XhtmlTextWriter, but it ignores the border attribute on table. This is mostly like the correct thing to do since you should be using CSS to set the border. Alas, Polycom doesn't support CSS.
So when I Render the beginning and ending table tags, I need to use HtmlTextWriter.WriteBeginTag/WriteEndTag instead of HtmlTextWriter.RenderBeginTag/RenderEndTag.
protected void RenderTableBegin(HtmlTextWriter writer)
{
//writer.AddAttribute(HtmlTextWriterAttribute.Border, "0");
//writer.RenderBeginTag(HtmlTextWriterTag.Table);
writer.WriteBeginTag("table");
writer.WriteAttribute("border", "0");
writer.Write(HtmlTextWriter.TagRightChar);
}
protected void RenderTableEnd(HtmlTextWriter writer)
{
writer.WriteEndTag("table");
//writer.RenderEndTag();
}
Other places in my code, I am using HtmlTextWriter.RenderBeginTag/RenderEngTag. Are there any known issues with mixing these? Am I OK as long as I used matching calls?
I don't believe so that there is an issue, but there is a difference in the way it renders tags. If you want control over the process, you could just render the entire HTML yourself in a writer.Write statement too.
writer.Write("<table border=\"0\">");
Just to ensure the final output if you are having issues with that. I know the big difference is the way that the rendering process happens (for render begin tag, attributes have to be added before, whereas writebegintag adds attributes after as you have).
HTH.
I used the following code in the cs file of the masterpage to fix the rendering issue of the safari and the asp:menu control. I was curious on why it actually fixes the problem. Here is the code:
protected override void AddedControl(Control control, int index)
{
if (Request.ServerVariables["http_user_agent"].IndexOf("Safari",
StringComparison.CurrentCultureIgnoreCase) != -1)
this.Page.ClientTarget = "uplevel";
base.AddedControl(control, index);
}
The problem is that ASP.NET erroneously recognizes Safari as a "downlevel" browser (e.g. ancient). Your fix is forcing it to recognize it as a more modern browser that is capable of handling some of the menu's javascript.
This will also work via a bunch of other techniques such as overriding Page_PreInit or adding a properly configured safari.browser to App_Browsers.
I'd like to force the consumer of a control to give a property a value when placing the control on a page.
In VisualStudio when you create an < img > tag without attributes SRC or ALT on a user control, it gets underlined saying that SRC and ALT are required attributes. I assume this is just a special handling of the tag by the editor, but is there a way to define a similar behavior for controls?
If the control had a property defined like this:
public object AProperty
{
get
{
if (ViewState["AProperty"] == null)
{
throw new Exception("AProperty is a required property of this control");
}
return ViewState["AProperty"];
}
set { ViewState["AProperty"] = value; }
}
Is there a way to use a Custom Attribute or something else that would flag in the designer?
You could use the Microsoft.Build.Framework.Required attribute. This would require a value to be set at build time or the build will fail with a message which indicates that the property does not have a value.
I don't believe there is an attribute to indicate that a specific tag must be included in a server control (or at least I don't see any such attribute on the System.Web.UI.HtmlControl.Image class). I believe that the litle underlines are part of the HTML validation of the IDE.
You could always create a custom attribute which throws a warning if a property is missing
While Microsoft.Build.Framework.Required is probably the best answer here, for others who stumble upon this and can't use .NET 4.0, you can also use this method:
http://forums.asp.net/t/1238319.aspx