473,385 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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
Nov 17 '05 #1
1 1958
> 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));
}
}
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: theyas | last post by:
How can I get my code to NOT display two "Open/Save/Cancel/More Info" dialog boxes when using the "Response.WriteFile" method to download a file to IE I've asked about this before and didn't get a...
2
by: Jensen bredal | last post by:
I'am trying to change the style of my LinkButton control . I have a set of five control and i need to hilight the selected one. I want to achive this by setting MyLinkButton.CssClass="newStyle"...
1
by: Tim::.. | last post by:
Hi can someone please explain to me why I get the following error when I place the following code into a server control. It worked fine until I created the control??? Error:...
2
by: Alan Silver | last post by:
Hello, I'm having rather a problem with user control. It is a fairly simple affair (see my other threads for more details) that shows a date and time in five drop down controls. I had private...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
5
by: Dinsdale | last post by:
I have an application that recieves text data via external input (i.e. serial) and displays it on the screen (we use carraige return as a delimiter). At this point I use a regular old text box and...
1
by: emailseshu | last post by:
Hi, Iam trying to check the Client Side CallBack Feature in ASP.NET Iam able to call th RaiseCallbackEvent from the Client Side Javascript Function but when I go to the debug mode to check the...
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
6
by: SenthilVel | last post by:
hi all, i am running a ASP.Net 2.0 application. in one of the pages i have a text box which is set as PASSWORD mode. when the page is submitted or transfered , am not able to get the contents of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.