Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > AutopostBack for a TextBox

Reply
Thread Tools

AutopostBack for a TextBox

 
 
=?Utf-8?B?Vmk=?=
Guest
Posts: n/a
 
      10-28-2004
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)sender).ID == "myTextBox" )
myDropDownList.DataBind();
}

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

Thank you,
 
Reply With Quote
 
 
 
 
=?Utf-8?B?SGFhY2tlZA==?=
Guest
Posts: n/a
 
      10-28-2004
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)sender).ID == "myTextBox" )
> myDropDownList.DataBind();
> }
>
> I receive an error "Specified cast is not valid" in the if(
> ((TextBox)sender).ID == "myTextBox" ) line.
> What am I doing wrong?
>
> Thank you,

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Vmk=?=
Guest
Posts: n/a
 
      10-28-2004
sender.GetType().FullName returns "ASP.WebOrderForm_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)sender).ID == "myTextBox" )
> > myDropDownList.DataBind();
> > }
> >
> > I receive an error "Specified cast is not valid" in the if(
> > ((TextBox)sender).ID == "myTextBox" ) line.
> > What am I doing wrong?
> >
> > Thank you,

 
Reply With Quote
 
=?Utf-8?B?SGFhY2tlZA==?=
Guest
Posts: n/a
 
      10-28-2004
(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 "TextChanged".

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

private void InitializeComponent()
{
this.TextBox1.TextChanged += new System.EventHandler(this.OnTextChanged);
this.Load += new System.EventHandler(this.Page_Load);

}

And

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

private void OnTextChanged(object sender, System.EventArgs e)
{
myDropDownList.DataBind();
}

"Vi" wrote:

> sender.GetType().FullName returns "ASP.WebOrderForm_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)sender).ID == "myTextBox" )
> > > myDropDownList.DataBind();
> > > }
> > >
> > > I receive an error "Specified cast is not valid" in the if(
> > > ((TextBox)sender).ID == "myTextBox" ) line.
> > > What am I doing wrong?
> > >
> > > Thank you,

 
Reply With Quote
 
=?Utf-8?B?Vmk=?=
Guest
Posts: n/a
 
      10-28-2004
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 "TextChanged".
>
> In the code behind, you should see that the method InitializeComponent has
> changed to add a line that attaches an event handler to the TextChanged event
> of the TextBox:
>
> private void InitializeComponent()
> {
> this.TextBox1.TextChanged += new System.EventHandler(this.OnTextChanged);
> this.Load += new System.EventHandler(this.Page_Load);
>
> }
>
> And
>
> Now in the method called by the TextChanged event handler, you can bind your
> dropdown.
>
> private void OnTextChanged(object sender, System.EventArgs e)
> {
> myDropDownList.DataBind();
> }
>
> "Vi" wrote:
>
> > sender.GetType().FullName returns "ASP.WebOrderForm_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)sender).ID == "myTextBox" )
> > > > myDropDownList.DataBind();
> > > > }
> > > >
> > > > I receive an error "Specified cast is not valid" in the if(
> > > > ((TextBox)sender).ID == "myTextBox" ) line.
> > > > What am I doing wrong?
> > > >
> > > > Thank you,

 
Reply With Quote
 
Matt Berther
Guest
Posts: n/a
 
      10-29-2004
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)sender).ID == "myTextBox" )
> myDropDownList.DataBind();
> }
> I receive an error "Specified cast is not valid" in the if(
> ((TextBox)sender).ID == "myTextBox" ) line.
> What am I doing wrong?
> Thank you,
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autopostback for Textbox in a DataList milbrand@gmail.com ASP .Net 0 02-02-2009 05:22 PM
TextBox AutoPostBack=false question (bug?) =?Utf-8?B?UmVuYXVkIExhbmdpcw==?= ASP .Net 4 06-05-2007 05:59 PM
AutoPostBack on TextBox loses Focus - Steve - ASP .Net 3 06-29-2004 08:52 PM
ValidatonSummary control not working on an autopostback textbox Neo ASP .Net 1 06-24-2004 04:59 AM
TextBox AutoPostBack event not firing correctly Ben Fidge ASP .Net 2 01-30-2004 12:32 PM



Advertisments