Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7059769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:16:19+00:00 2026-05-28T04:16:19+00:00

I have a custom asp-net control that inherits from another one and its works

  • 0

I have a custom asp-net control that inherits from another one and its works as expected, though the properties are only set properly if i code them in the markup directly, so for instance if i need set a property at runtime that is some dynamic value, this value is never set or somehow lost.

Here’s the markup code:

<!--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> 

This is the code of the control:

    [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);
    }
}

And then in my asp.net page that is using control, created by markup code, in the Page_Load() i try to assign some values to some properties and and the values aren’t set properly, meaning that if i have set for isntance, the property EmailBeforeText = “somthing” this value will not be assigned..

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();
    }

Any ideas what i’m missing here?

Thanks a lot for your reading!

Regards,
byte_slave

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:16:20+00:00Added an answer on May 28, 2026 at 4:16 am

    short answer: use viewstate to persist your custom values!

    • Understanding ASP.NET ViewState whitepaper (see example with NavigateUrl)

    edit: as reading the white-paper is obviously a really hard thing:

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed an asp.net control that inherits from the gridview and its called
I'm attempting to create a custom calendar control that inherits from ASP.Net's built in
I have a custom ASP.NET user control that is added to a panel on
I've written a custom ASP.net control that descends from LinkButton and overrides the Render()
I have an ASP.NET user control that is used in another use control. The
I have a custom control that mimics to some extent the built in ASP.Net
We have an ASP.NET custom control that lets users enter HTML (similar to a
I have a custom control that inherits from WebControl and implements IValidator, but I
I have a custom control that extends ASP.NET Update panels. On the server side
I have a custom ASP.NET control. In its Init handler I add a delegate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.