English 中文(简体)
ASP. NET 海关控制——习俗财产不持有后退值
原标题:ASP.NET custom controls - custom property doesn t hold the assigned value on postaback

我拥有一种习俗网控制,从另一个公司继承其作品和预期的作品,尽管这些财产只有在直接贴上标识时才能妥善确定,例如,如果需要在经营时设定某种动态价值的财产,这种价值永远不会被设定,或者某种损失。

标识代码:

<!--related form-->
<fw:advancedformdisplay id="formDisp" runat="server" captchaenabled="true" EmailEnabled="true" EnableViewState="true" captchaprivatekey="xxxxxxxxxxxxxxxxxxxx" captchapublickey="xxxxxxxxxxxxx" captchatheme="white" SourceType="MenuItem" SourceMainId="Auto">
</fw:advancedformdisplay> 

这是控制守则:

    [DefaultProperty("CaptchaEnabled"),ToolboxData("<{0}:AdvancedFormDisplay runat=server></{0}:AdvancedFormDisplay>"), Description("This is an enhanced FormDisplay control that inlcudes Googles Captcha control is enabled")]
public class AdvancedFormDisplay :SiteBuilder.WebControls.FormDisplay
{
    bool _CaptchaEnabled = false, sendEmail = false;
    string captchaErrorMessage = "The verification code entered is not valid. Please try again!";
    RecaptchaControl captchaControl = null;
    string captchaPrivateKey = "", captchaPublicKey = "", captchaTheme = "clean";
    string originalFormHtml = string.Empty;
    string afterText = string.Empty, beforeText = string.Empty;
    Literal litHtmlForm = null;
    string captchaErrorClass = "errorCaptcha";

    public string EmailBeforeText
    {
        get { return beforeText; }
        set { beforeText = value; }
    }

    public string EmailAfterText
    {
        get { return afterText; }
        set { afterText = value; }
    }

    public string CaptchaErrorClass
    {
        get { return captchaErrorClass; }
        set { captchaErrorClass = value; }
    }

    public bool CaptchaEnabled
    {
        get { return _CaptchaEnabled; }
        set { _CaptchaEnabled = value; }
    }

    public bool EmailEnabled
    {
        get { return sendEmail; }
        set { sendEmail = value; }
    }

    public string CaptchaErrorMessage
    {
        get { return captchaErrorMessage; }
        set { captchaErrorMessage = value; }
    }

    /// <summary>
    /// red,white,blackglass,clean
    /// </summary>
    public string CaptchaTheme
    {
        get { return captchaTheme; }
        set { captchaTheme = value; }
    }

    public string CaptchaPrivateKey
    {
        get { return captchaPrivateKey; }
        set { captchaPrivateKey = value; }
    }

    public string CaptchaPublicKey
    {
        get { return captchaPublicKey; }
        set { captchaPublicKey = value; }
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
    }


    public override void OnSaved(FormDisplayEventArgs e)
    {
        //If captcha control is enabled we need to adda  bit of code to redirect form properly
        if (CaptchaEnabled && e.Redirect && !e.SendMail)
        {
            //Do Stuff
        }

        if(sendEmail)
        {
            //Send email
        }

        base.OnSaved(e);
    }

    public override void OnSaving(FormDisplayEventArgs e)
    {
        if (CaptchaEnabled)
        {
            //Validate and do stuff
        }

        base.OnSaving(e);
    }
}

然后,在我用标记代码建立的控制网页上,“Load()”一页试图将某些价值分配给某些财产和价值正确设定,意思是,如果已经设定了遗嘱,则“BeforeText” = “somthing”这一价值不会被分配。

protected void Page_Load(object sender, EventArgs e)
{
    //2: Get the language of menuitem - Based on current culture setting (for by dropdownbox - change logic)
    try
    {
        currentCulture = Thread.CurrentThread.CurrentCulture.ToString();

        // Redirect if domain does not match rootnode.
        DomainChecker.CheckURL(this.Request, this.Response, currentCulture);

        if (footerArticle != null)
            footerArticle.SourceMenuId = Digimaker.Config.Custom.Get("FooterID_" + currentCulture).ToString();
    }
    catch
    {
        currentCulture = "en-GB";

        if( footerArticle != null )
            footerArticle.SourceMenuId = Digimaker.Config.Custom.Get("FooterID_" + currentCulture).ToString();
    }

这里没有什么想法?

感谢你们的阅读!

Regards, byte_slave

最佳回答

简短回答:用观点坚持你的习俗价值!

编辑:阅读白皮书显然是一件实事:

Each control is responsible for storing its own state, which is accomplished by adding its changed state to its ViewState property. The ViewState property is defined in the System.Web.UI.Control class, meaning that all ASP.NET server controls have this property available. (When talking about view state in general I ll use lower case letters with a space between view and state; when discussing the ViewState property, I ll use the correct casing and code-formatted text.)

If you examine the simple properties of any ASP.NET server control you ll see that the properties read and write directly to the view state. (You can view the decompiled source code for a .NET assembly by using a tool like Reflector.) For example, consider the HyperLink Web control s NavigateUrl property. The code for this property looks like so:

public string NavigateUrl
{
  get
  {
    string text = (string) ViewState["NavigateUrl"];
    if (text != null)
       return text;
    else
       return string.Empty;
  }
  set
  {
    ViewState["NavigateUrl"] = value;
  }
}

As this code sample illustrates, whenever a control s property is read, the control s ViewState is consulted. If there is not an entry in the ViewState, then the default value for the property is returned. When the property is assigned, the assigned value is written directly to the ViewState.

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签