本文整理汇总了C#中System.Web.UI.HtmlTextWriter.IsValidFormAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlTextWriter.IsValidFormAttribute方法的具体用法?C# HtmlTextWriter.IsValidFormAttribute怎么用?C# HtmlTextWriter.IsValidFormAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.HtmlTextWriter
的用法示例。
在下文中一共展示了HtmlTextWriter.IsValidFormAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderAttributes
protected override void RenderAttributes(HtmlTextWriter writer)
{
ArrayList list = new ArrayList();
foreach (string str in base.Attributes.Keys)
{
if (!writer.IsValidFormAttribute(str))
{
list.Add(str);
}
}
foreach (string str2 in list)
{
base.Attributes.Remove(str2);
}
bool enableLegacyRendering = base.EnableLegacyRendering;
Page page = this.Page;
if (writer.IsValidFormAttribute("name"))
{
if ((((page != null) && (page.RequestInternal != null)) && (this.RenderingCompatibility < VersionUtil.Framework40)) && ((page.RequestInternal.Browser.W3CDomVersion.Major == 0) || (page.XhtmlConformanceMode != XhtmlConformanceMode.Strict)))
{
writer.WriteAttribute("name", this.Name);
}
base.Attributes.Remove("name");
}
writer.WriteAttribute("method", this.Method);
base.Attributes.Remove("method");
writer.WriteAttribute("action", this.GetActionAttribute(), true);
base.Attributes.Remove("action");
if (page != null)
{
string clientOnSubmitEvent = page.ClientOnSubmitEvent;
if (!string.IsNullOrEmpty(clientOnSubmitEvent))
{
if (base.Attributes["onsubmit"] != null)
{
string s = base.Attributes["onsubmit"];
if (s.Length > 0)
{
if (!StringUtil.StringEndsWith(s, ';'))
{
s = s + ";";
}
if (page.ClientSupportsJavaScript || !s.ToLower(CultureInfo.CurrentCulture).Contains("javascript"))
{
page.ClientScript.RegisterOnSubmitStatement(typeof(HtmlForm), "OnSubmitScript", s);
}
base.Attributes.Remove("onsubmit");
}
}
if (page.ClientSupportsJavaScript || !clientOnSubmitEvent.ToLower(CultureInfo.CurrentCulture).Contains("javascript"))
{
if (enableLegacyRendering)
{
writer.WriteAttribute("language", "javascript", false);
}
writer.WriteAttribute("onsubmit", clientOnSubmitEvent);
}
}
if (((page.RequestInternal != null) && (page.RequestInternal.Browser.EcmaScriptVersion.Major > 0)) && ((page.RequestInternal.Browser.W3CDomVersion.Major > 0) && (this.DefaultButton.Length > 0)))
{
Control button = this.FindControl(this.DefaultButton);
if ((button == null) && (this.Page != null))
{
char[] anyOf = new char[] { '$', ':' };
if (this.DefaultButton.IndexOfAny(anyOf) != -1)
{
button = this.Page.FindControl(this.DefaultButton);
}
}
if (!(button is IButtonControl))
{
throw new InvalidOperationException(System.Web.SR.GetString("HtmlForm_OnlyIButtonControlCanBeDefaultButton", new object[] { this.ID }));
}
page.ClientScript.RegisterDefaultButtonScript(button, writer, false);
}
}
base.EnsureID();
base.RenderAttributes(writer);
}
示例2: RenderAttributes
/// <internalonly/>
/// <devdoc>
/// </devdoc>
protected override void RenderAttributes(HtmlTextWriter writer) {
ArrayList invalidAttributes = new ArrayList();
foreach (String key in Attributes.Keys) {
if (!writer.IsValidFormAttribute(key)) {
invalidAttributes.Add(key);
}
}
foreach (String key in invalidAttributes) {
Attributes.Remove(key);
}
bool enableLegacyRendering = EnableLegacyRendering;
Page page = Page;
if (writer.IsValidFormAttribute("name")) {
// DevDiv 27328 Do not render name attribute for uplevel browser
if (page != null && page.RequestInternal != null &&
RenderingCompatibility < VersionUtil.Framework40 &&
(page.RequestInternal.Browser.W3CDomVersion.Major == 0 ||
page.XhtmlConformanceMode != XhtmlConformanceMode.Strict)) {
writer.WriteAttribute("name", Name);
}
Attributes.Remove("name");
}
writer.WriteAttribute("method", Method);
Attributes.Remove("method");
// Encode the action attribute - ASURT 66784
writer.WriteAttribute("action", GetActionAttribute(), true /*encode*/);
Attributes.Remove("action");
// see if the page has a submit event
if (page != null) {
string onSubmit = page.ClientOnSubmitEvent;
if (!String.IsNullOrEmpty(onSubmit)) {
if (Attributes["onsubmit"] != null) {
// If there was an onsubmit on the form, register it as an onsubmit statement and remove it from the attribute collection
string formOnSubmit = Attributes["onsubmit"];
if (formOnSubmit.Length > 0) {
if (!StringUtil.StringEndsWith(formOnSubmit, ';')) {
formOnSubmit += ";";
}
if (page.ClientSupportsJavaScript || !formOnSubmit.ToLower(CultureInfo.CurrentCulture).Contains("javascript")) {
page.ClientScript.RegisterOnSubmitStatement(typeof(HtmlForm), "OnSubmitScript", formOnSubmit);
}
Attributes.Remove("onsubmit");
}
}
// Don't render the on submit if it contains javascript and the page doesn't support it
if (page.ClientSupportsJavaScript || !onSubmit.ToLower(CultureInfo.CurrentCulture).Contains("javascript")) {
if (enableLegacyRendering) {
writer.WriteAttribute("language", "javascript", false);
}
writer.WriteAttribute("onsubmit", onSubmit);
}
}
if ((page.RequestInternal != null) &&
(page.RequestInternal.Browser.EcmaScriptVersion.Major > 0) &&
(page.RequestInternal.Browser.W3CDomVersion.Major > 0)) {
if (DefaultButton.Length > 0) {
// Find control from the page if it's a hierarchical ID.
// Dev11 bug 19915
Control c = FindControlFromPageIfNecessary(DefaultButton);
if (c is IButtonControl) {
page.ClientScript.RegisterDefaultButtonScript(c, writer, false /* UseAddAttribute */);
}
else {
throw new InvalidOperationException(SR.GetString(SR.HtmlForm_OnlyIButtonControlCanBeDefaultButton, ID));
}
}
}
}
// We always want the form to have an id on the client
// base.RenderAttributes takes care of actually rendering it.
EnsureID();
base.RenderAttributes(writer);
}