Friday 15 April 2011

c# - Input text control disappears on postback -


I have some input controls (text) that have been created as part of the code-behind such a dynamic radiobutanist (So ​​that a textbox is next to Radiobootton):

  Radio button list radiooption = new radio button list (); Radiobuttonlist.Items.Add (new listing ITM (DT.ROS [I] [9] .restring () + "input id = \" + + + name + "\" runat = \ "server \" type = \   

All controls are within the update panel.

Every time there is a postback, " Text within the input

Any thoughts? Very much appreciated!

control tree Must be rebuilt on every postback, in which partial postbay - or allow it to be regenerated through the controlstate / viewstate. In this case, in the later postback

For such cases, I will contact it like this:

  1. Enable ViewStat on the radio button list and make sure it does not add more than load 1 , or
  2. Container control Store a viewstate of a proper collection on it and then the consumer databa Nd G control - to set it see a clear way. I like this approach because it is consistent, easy to predict and control.

    1 it should work but it probably is not. I am generally confused about which control actually supports the viewstate, and to what extent does the use kill me as usual .. Incompatible. In any case, this will not be will not - remember that disabling the viewstrate for page (or parent control) disables ViewState all the way down Additionally, and should control and in the control with the same control path / id (usually init or load) in order to ensure that it works correctly.


    Any ideas for # 2:

    Save the visual control in that user control (this control should be vestostat enabled): < Pre> // ListItem is a proper serial and // works well for automatic binding for various list controls. & Lt; ListItem & gt; Name {// May receive return tap {return (list & lt; ListItem & gt;) ViewState ["name"]; } Set {ViewState ["name"] = Value; }}

    In the GenericDataSourceControl (if it is a good id, put the GDS in the markup) Select the event:

      Zero SelectEvent (Sender E, GenericSelectArgs Args) {args.SetData (name); }   

    Dynamically add a radio button list (say, in Control.OnLoad ):

      // Unless it Do not need to be dynamic, move it into declarative markup // dynamic control * should be added to the same place * it was before // postback or ugly invalid control tree construction will be exceptions. Var radio list = new radio button list ; SomeControl.Controls.Add (radioList); // This should be unusual for reducing the problem of making the control tree and // should be consistent for the dynamic control. Radio list.id = "radio list"; // The binding for DS "declarative" usually works better I've got a radio list. DataSourceID = "idOfTheGDS"; // You - Databank is required based on certain factors - I will usually call Databank in the prerenders, but generally the load is fine / liked. // If it already binds, do not call it manually radioList.DataBind ();   

    If databanding is working correctly, it is possible for the radio button to disable disable viewstate. But occasionally the use of the viewtest When the controlstate was supposed to be done, so make sure it works as desired.

No comments:

Post a Comment