473,586 Members | 2,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AutopostBack for a TextBox

Vi
Hello,
I want to be able to reload a DropDownList when a TextBox changes its value.
So I set the AutopostBack property of the TextBox to true and in the code
behind I do something like:

if(IsPostBack)
{
if( ((TextBox)sende r).ID == "myTextBox" )
myDropDownList. DataBind();
}

I receive an error "Specified cast is not valid" in the if(
((TextBox)sende r).ID == "myTextBox" ) line.
What am I doing wrong?

Thank you,
Nov 18 '05 #1
5 2583
Try printing out the value of sender.GetType( ).FullName.

"Vi" wrote:
Hello,
I want to be able to reload a DropDownList when a TextBox changes its value.
So I set the AutopostBack property of the TextBox to true and in the code
behind I do something like:

if(IsPostBack)
{
if( ((TextBox)sende r).ID == "myTextBox" )
myDropDownList. DataBind();
}

I receive an error "Specified cast is not valid" in the if(
((TextBox)sende r).ID == "myTextBox" ) line.
What am I doing wrong?

Thank you,

Nov 18 '05 #2
Vi
sender.GetType( ).FullName returns "ASP.WebOrderFo rm_aspx", which is the
name of the page.
Is there a way to determine that it was the TextBox that generated the
postback?
Thanks.
"Haacked" wrote:
Try printing out the value of sender.GetType( ).FullName.

"Vi" wrote:
Hello,
I want to be able to reload a DropDownList when a TextBox changes its value.
So I set the AutopostBack property of the TextBox to true and in the code
behind I do something like:

if(IsPostBack)
{
if( ((TextBox)sende r).ID == "myTextBox" )
myDropDownList. DataBind();
}

I receive an error "Specified cast is not valid" in the if(
((TextBox)sende r).ID == "myTextBox" ) line.
What am I doing wrong?

Thank you,

Nov 18 '05 #3
(Assuming VS.NET 2003) In the designer select the TextBox control and in the
properties window, click on the yellow lightning bold. Type in OnTextChanged
next to the Action "TextChange d".

In the code behind, you should see that the method InitializeCompo nent has
changed to add a line that attaches an event handler to the TextChanged event
of the TextBox:

private void InitializeCompo nent()
{
this.TextBox1.T extChanged += new System.EventHan dler(this.OnTex tChanged);
this.Load += new System.EventHan dler(this.Page_ Load);

}

And

Now in the method called by the TextChanged event handler, you can bind your
dropdown.

private void OnTextChanged(o bject sender, System.EventArg s e)
{
myDropDownList. DataBind();
}

"Vi" wrote:
sender.GetType( ).FullName returns "ASP.WebOrderFo rm_aspx", which is the
name of the page.
Is there a way to determine that it was the TextBox that generated the
postback?
Thanks.
"Haacked" wrote:
Try printing out the value of sender.GetType( ).FullName.

"Vi" wrote:
Hello,
I want to be able to reload a DropDownList when a TextBox changes its value.
So I set the AutopostBack property of the TextBox to true and in the code
behind I do something like:

if(IsPostBack)
{
if( ((TextBox)sende r).ID == "myTextBox" )
myDropDownList. DataBind();
}

I receive an error "Specified cast is not valid" in the if(
((TextBox)sende r).ID == "myTextBox" ) line.
What am I doing wrong?

Thank you,

Nov 18 '05 #4
Vi
it worked,
thanks a lot.

"Haacked" wrote:
(Assuming VS.NET 2003) In the designer select the TextBox control and in the
properties window, click on the yellow lightning bold. Type in OnTextChanged
next to the Action "TextChange d".

In the code behind, you should see that the method InitializeCompo nent has
changed to add a line that attaches an event handler to the TextChanged event
of the TextBox:

private void InitializeCompo nent()
{
this.TextBox1.T extChanged += new System.EventHan dler(this.OnTex tChanged);
this.Load += new System.EventHan dler(this.Page_ Load);

}

And

Now in the method called by the TextChanged event handler, you can bind your
dropdown.

private void OnTextChanged(o bject sender, System.EventArg s e)
{
myDropDownList. DataBind();
}

"Vi" wrote:
sender.GetType( ).FullName returns "ASP.WebOrderFo rm_aspx", which is the
name of the page.
Is there a way to determine that it was the TextBox that generated the
postback?
Thanks.
"Haacked" wrote:
Try printing out the value of sender.GetType( ).FullName.

"Vi" wrote:

> Hello,
> I want to be able to reload a DropDownList when a TextBox changes its value.
> So I set the AutopostBack property of the TextBox to true and in the code
> behind I do something like:
>
> if(IsPostBack)
> {
> if( ((TextBox)sende r).ID == "myTextBox" )
> myDropDownList. DataBind();
> }
>
> I receive an error "Specified cast is not valid" in the if(
> ((TextBox)sende r).ID == "myTextBox" ) line.
> What am I doing wrong?
>
> Thank you,

Nov 18 '05 #5
Hello Vi,

Why would you not just catch the TextChanged event on the text box in question?

--
Matt Berther
http://www.mattberther.com
Hello,
I want to be able to reload a DropDownList when a TextBox changes its
value.
So I set the AutopostBack property of the TextBox to true and in the
code
behind I do something like:
if(IsPostBack)
{
if( ((TextBox)sende r).ID == "myTextBox" )
myDropDownList. DataBind();
}
I receive an error "Specified cast is not valid" in the if(
((TextBox)sende r).ID == "myTextBox" ) line.
What am I doing wrong?
Thank you,

Nov 18 '05 #6

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

Similar topics

4
9017
by: Scott M. | last post by:
If I put RequiredFiledValidators on a page and set them up with corresponding TextBoxes everything works just fine. If I add a DropDownList and set its AutoPostBack to True, I am able to post data to the server WITHOUT the validators invoking their validation. It seems that the easiest solution would have been for MS to simply give the...
1
8373
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What I want to do is to allow the user to click on the row that corresponds to the correct address, and have the code behind populate the form's...
1
1481
by: Neo | last post by:
I put a textbox on the page.The textbox only accepts integer value. I also added a comparevalidator control to check the data entered in that textbox and a validationsummary control on the page. The comparevalidator worked find and showed the error message.But page still postback to server.So it seemed that validationsummary control didn't...
0
1841
by: rmccinc | last post by:
I have a dropdownlist in a datagrid and it has autopostback set to true. I need to get the new value of that dropdown to fill a textbox in the same datagrid row. I have set the databind event on the gridview to fire on pageload (including postbacks) because I need to change the value of the textbox at each of the dropdownlists autopostback...
2
11591
by: Tom Edelbrok | last post by:
Question: Why does a button event (ie: Button1_Click) get executed on the first click for a textbox control which has 'autopostback=false', but doesn't get executed until a second click when 'autopostback=true'? For example, I set up a textbox control with autopostback=false, and a command button. If I run my page (main.aspx) I can type data...
3
4027
by: Brad | last post by:
The first text on my form is a numeric field. I have a javascript that runs on this field for onkeyup (validate the key strokes and modifies fields on the screen) but when I do this and have the autopostback on, the autopostback does not trigger. The autopostback will trigger if I hit the enter key while in the textbox but not when I leave...
2
5280
by: rn5a | last post by:
Assume that a user control has a TextBox (Page1.ascx) <asp:TextBox ID="txtName" runat="server"/> I am encapsulating the above user control in a ASPX page named Page1.aspx i.e. the ASPX page displays a single TextBox. There's also a CheckBox in this ASPX page within the <formtags. Note that the CheckBox IS NOT a part of the user control....
1
2093
by: danyeungw | last post by:
I get the following from the link http://support.microsoft.com/kb/314206. I need to have both work - the page stays where it is and set focus to next control. Does anyone have solution? I have been working on this for days. I am using ASP.NET 2003. Thanks. DanYeung PRB: Controls Lose Focus When You Enable SmartNavigation and...
4
5946
by: =?Utf-8?B?UmVuYXVkIExhbmdpcw==?= | last post by:
Hello, I have a strange yet very simple problem with the asp.net Textbox web control. On an empty asp.net page, add a single asp:TextBox control with Autopostback=false with nothing else on the page. according to the doc, hitting Enter while the TextBox has focus should do nothing since Autopostback=false. The problem i have is that it...
6
4838
by: Peter | last post by:
ASP.NET 2.0 Visual Studio 2008 I have the following code and when the textbox displays and I press Enter while in the text box I get AutoPostBack, how do I stop AutoPostBack? TextBox txt = new TextBox(); txt.MaxLength = parm.MaxLength; txt.ID = parm.ParameterNameID; txt.Text = "12345";
0
7911
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8200
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7954
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
3836
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.