Manually get the text that a certain control posted when in IsPostBack mode...

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Manually get the text that a certain control posted when in IsPostBack mode...

    I have a page with EnableViewState="false".
    That page contains a DropDownList with dynamic items and a submit Button.

    I need to get the SelectedIndex of the DropDownList on postback however all
    I ever get is -1. This makes sense since on postback, the DropDownList is
    now empty (ViewState data is responsible for maintaining the items).

    Now the only way I can think of to get the SelectedIndex is to somehow get
    the text that the DropDownList posted to the server and perform an IndexOf()
    or FindByText().

    My question is how do I manually get the text that a certain control posted
    when in IsPostBack mode?
    Is there a Collection somewhere of posted data?
    Do controls expose raw posted data somewhere?


    Cheers
    Nathan


    Nathan Baulch Guest

  2. Similar Questions and Discussions

    1. resize control inherited from System.Web.UI.Control in design mode
      How I can resize control inherited from System.Web.UI.Control in design mode. Thanks a lot.
    2. Not IsPostBack
      I have a problem. I have a function Load_Info where I am generating dymanic table. On a first load is it fine however after the refresh because it...
    3. Executing code that is part of a control after it gets posted back from the form in the users browser.
      Hello dear .NET'rs, I have made a simple RememberingTextBox control which looks in the session for a session variable with the same name as the...
    4. [PHP] Text boxes posted to MySQL record that contain quotes
      wow i've had this issue aswell only yesterday , like in my search page of the project i've just done i stored the search values of each option so...
    5. Text boxes posted to MySQL record that contain quotes
      I know that using stripslashes will remove \ using php but I'm having trouble with posting quotation marks in a text record field. Anyone know how...
  3. #2

    Default Re: Manually get the text that a certain control posted when in IsPostBack mode...

    > My question is how do I manually get the text that a certain control
    > posted when in IsPostBack mode?
    > Is there a Collection somewhere of posted data?
    > Do controls expose raw posted data somewhere?
    My solution was to subclass the DropDownList control and use the
    LoadPostData method to save the postback data to a property. Here is the
    code for anybody who is interested:

    public class CustomDDL : DropDownList,IPostBackDataHandler
    {
    private string postedText;
    private string text;

    public string PostedText {
    get {
    return postedText;
    }
    }
    public string Text {
    set {
    text = value;
    }
    }

    public virtual bool LoadPostData(
    string postDataKey,NameValueCollection values) {
    postedText = values[postDataKey];
    return false;
    }
    protected override void OnDataBinding(EventArgs e) {
    base.OnDataBinding(e);
    SelectedIndex = Items.IndexOf(Items.FindByText(text));
    }
    }


    Nathan Baulch Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139