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

  • SEARCH
  • Home
  • 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 75833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:34:41+00:00 2026-05-10T20:34:41+00:00

This works, but is it the proper way to do it??? I have a

  • 0

This works, but is it the proper way to do it???

I have a custom server control that has an [input] box on it. I want it to kinda mimic the ASP.NET TextBox, but not completely. When the textbox is rendered i have a javascript that allows users to select values that are then placed in that input box.

I have a public text property on the control. In the get/set i get/set the viewstate for the control – that part is easy, but when the control is populated via the javascript, the Text get is not actually called, what is the proper way to set this exposed property using JavaScript (or even if the user just types in the box) ?

Edit: In the OnInit i ensure the state is maintained by reaching into the form values.

    protected override void OnInit(EventArgs e)     {         base.OnInit(e);          if (HttpContext.Current.Request.Form['MyInputBoxValue'] != '')         {             ViewState['MyInputBoxValue']                 = HttpContext.Current.Request.Form['MyInputBoxValue'];         }     } 

Then to get the value actually back in place in the HtmlTextWrite, i do this:

protected override void RenderContents(HtmlTextWriter output) {          // There is an input control here and i set its value property         // like this using the Text internal defined.         output.Write('<input value=' + Text + '>.....  } 

thanks

  • 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. 2026-05-10T20:34:42+00:00Added an answer on May 10, 2026 at 8:34 pm

    I find using IStateManager works the best.

    For example:

    partial class MyControl : System.Web.UI.UserControl, IStateManager {     [Serializable()]     protected struct MyControlState     {         public bool someValue;         public string name;     }      protected MyControlState state;      public bool someValue {         get { return state.someValue; }         set { state.someValue = value; }     }      public bool IsTrackingViewState {         get { return true; }     }      protected override void LoadViewState(object state)     {         if ((state != null) && state is MyControlState) {             this.state = state;         }     }      protected override object SaveViewState()     {         return state;     }      protected override void TrackViewState()     {         base.TrackViewState();     } } 

    getDefaultState() would just load some sane defaults into a new state struct. state gets tracked in the viewstate of the page, and ASP will take care of bring it in/out for you.

    (above code ported from VB and not checked, hopefully I didn’t make any errors but it should get the point across anyways)

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

Sidebar

Related Questions

I have a custom control that has several text boxes and combo boxes in
I'm sure this works in VS2010 but is there any way to get snippets
This works perfectly fine on localhost but doesn't work on my server, could anyone
Sorry, I don't have the exact code with me, but hopefully this works with
I am using Delphi TApplication.OnException Event to catch unhandled exceptions This works well but
(Citing source at: http://jqueryui.com/demos/dialog/#modal-form ) As an example, this works great but each time
I use the line below in my C# winform app, this works great but
$.post($(this).attr(action), $(this).serialize(), function(json) { alert('red'); AddItemAjax(json); }, json); This works in Chrome but not
Why doesn't this work <script src=jquery.js/> But this works <script src=jquery.js></script> ? Firefox 3.5.8
This works perfectly in Firefox but doesnt work in ie i get the following

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.