Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Using AutoPostBack with a TextBox in a Repeater

Reply
Thread Tools

Using AutoPostBack with a TextBox in a Repeater

 
 
Nathan Sokalski
Guest
Posts: n/a
 
      10-03-2009
I have a Repeater who's ItemTemplate contains a TextBox that has
AutoPostBack set to True. However, I am not sure where to handle this
postback. When I have a Button in the ItemTemplate, I simply use the
Repeater's ItemCommand event handler, but this event handler is not
triggered for what would normally be the TextBox's TextChanged event. Can
someone help me figure out how to handle this postback? Any help would be
appreciated. Thanks.
--
Nathan Sokalski
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.nathansokalski.com/


 
Reply With Quote
 
 
 
 
Patrice
Guest
Posts: n/a
 
      10-03-2009
Note sure to understand the problem. As you said it should be textbox
TextChanged event... Have you tried to handle this event ? At which point
are you stuck ? (you don't know where to start or you tried something and it
doesn't work ?)

BTW, which programming language do you use ? (lloks you'll need a sample)

--
Patrice
"Nathan Sokalski" <(E-Mail Removed)> a écrit dans le message de
news:(E-Mail Removed)...
>I have a Repeater who's ItemTemplate contains a TextBox that has
>AutoPostBack set to True. However, I am not sure where to handle this
>postback. When I have a Button in the ItemTemplate, I simply use the
>Repeater's ItemCommand event handler, but this event handler is not
>triggered for what would normally be the TextBox's TextChanged event. Can
>someone help me figure out how to handle this postback? Any help would be
>appreciated. Thanks.
> --
> Nathan Sokalski
> (E-Mail Removed)
> http://www.nathansokalski.com/
>


 
Reply With Quote
 
 
 
 
Phil Harvey
Guest
Posts: n/a
 
      10-03-2009
Hi Nathan,

A simple solution to this problem is to handle the TextChanged event on the
TextBox.

In your repeater, set the OnTextChanged property to an event handler method
in your code-behind.

<asp:Repeater ID="rptData" runat="server">
<ItemTemplate>
<asp:TextBox runat="server" Text=<%#
Container.DataItem.ToString() %> OnTextChanged="TextChanged"
AutoPostBack="true" />
</ItemTemplate>
</asp:Repeater>

In your code behind, have something like the following (I hope c# is ok).

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string[] data = new string[] { "s1", "s2" };
this.rptData.DataSource = data;
this.rptData.DataBind();
}
}

protected void TextChanged(object sender, EventArgs e)
{
TextBox textbox = sender as TextBox;
Debug.WriteLine("New text: " + textbox.Text);
}

Remember to only Databind the repeater if the request is not a postback,
otherwise the TextChanged won't be fired and the new value will be lost.

Regards,

--
Phil Harvey
www.anotherblog.com



"Nathan Sokalski" wrote:

> I have a Repeater who's ItemTemplate contains a TextBox that has
> AutoPostBack set to True. However, I am not sure where to handle this
> postback. When I have a Button in the ItemTemplate, I simply use the
> Repeater's ItemCommand event handler, but this event handler is not
> triggered for what would normally be the TextBox's TextChanged event. Can
> someone help me figure out how to handle this postback? Any help would be
> appreciated. Thanks.
> --
> Nathan Sokalski
> (E-Mail Removed)
> http://www.nathansokalski.com/
>
>
>

 
Reply With Quote
 
Nathan Sokalski
Guest
Posts: n/a
 
      10-03-2009
I had thought of that, but I didn't think it would work, since the TextBox
was inside the Repeater and was not available in the list of controls in the
codebehind in Visual Studio. But I have tried it now, since I have been told
that it did work, and thanks to you, it did! Yes, I guess I do have to plead
guilty of thinking of something and not trying it, so I guess I've learned
my lesson. Thanks.
--
Nathan Sokalski
(E-Mail Removed)
http://www.nathansokalski.com/

"Phil Harvey" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Nathan,
>
> A simple solution to this problem is to handle the TextChanged event on
> the
> TextBox.
>
> In your repeater, set the OnTextChanged property to an event handler
> method
> in your code-behind.
>
> <asp:Repeater ID="rptData" runat="server">
> <ItemTemplate>
> <asp:TextBox runat="server" Text=<%#
> Container.DataItem.ToString() %> OnTextChanged="TextChanged"
> AutoPostBack="true" />
> </ItemTemplate>
> </asp:Repeater>
>
> In your code behind, have something like the following (I hope c# is ok).
>
> protected void Page_Load(object sender, EventArgs e)
> {
> if (!Page.IsPostBack)
> {
> string[] data = new string[] { "s1", "s2" };
> this.rptData.DataSource = data;
> this.rptData.DataBind();
> }
> }
>
> protected void TextChanged(object sender, EventArgs e)
> {
> TextBox textbox = sender as TextBox;
> Debug.WriteLine("New text: " + textbox.Text);
> }
>
> Remember to only Databind the repeater if the request is not a postback,
> otherwise the TextChanged won't be fired and the new value will be lost.
>
> Regards,
>
> --
> Phil Harvey
> www.anotherblog.com
>
>
>
> "Nathan Sokalski" wrote:
>
>> I have a Repeater who's ItemTemplate contains a TextBox that has
>> AutoPostBack set to True. However, I am not sure where to handle this
>> postback. When I have a Button in the ItemTemplate, I simply use the
>> Repeater's ItemCommand event handler, but this event handler is not
>> triggered for what would normally be the TextBox's TextChanged event. Can
>> someone help me figure out how to handle this postback? Any help would be
>> appreciated. Thanks.
>> --
>> Nathan Sokalski
>> (E-Mail Removed)
>> http://www.nathansokalski.com/
>>
>>
>>



 
Reply With Quote
 
Enis Hyseni
Guest
Posts: n/a
 
      10-16-2009
Nathan Sokalski did you ever solved the problem that you had, because I`m
stucked at that.

If you did please tell mehow can I do that?

"Nathan Sokalski" wrote:

> I had thought of that, but I didn't think it would work, since the TextBox
> was inside the Repeater and was not available in the list of controls in the
> codebehind in Visual Studio. But I have tried it now, since I have been told
> that it did work, and thanks to you, it did! Yes, I guess I do have to plead
> guilty of thinking of something and not trying it, so I guess I've learned
> my lesson. Thanks.
> --
> Nathan Sokalski
> (E-Mail Removed)
> http://www.nathansokalski.com/
>
> "Phil Harvey" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi Nathan,
> >
> > A simple solution to this problem is to handle the TextChanged event on
> > the
> > TextBox.
> >
> > In your repeater, set the OnTextChanged property to an event handler
> > method
> > in your code-behind.
> >
> > <asp:Repeater ID="rptData" runat="server">
> > <ItemTemplate>
> > <asp:TextBox runat="server" Text=<%#
> > Container.DataItem.ToString() %> OnTextChanged="TextChanged"
> > AutoPostBack="true" />
> > </ItemTemplate>
> > </asp:Repeater>
> >
> > In your code behind, have something like the following (I hope c# is ok).
> >
> > protected void Page_Load(object sender, EventArgs e)
> > {
> > if (!Page.IsPostBack)
> > {
> > string[] data = new string[] { "s1", "s2" };
> > this.rptData.DataSource = data;
> > this.rptData.DataBind();
> > }
> > }
> >
> > protected void TextChanged(object sender, EventArgs e)
> > {
> > TextBox textbox = sender as TextBox;
> > Debug.WriteLine("New text: " + textbox.Text);
> > }
> >
> > Remember to only Databind the repeater if the request is not a postback,
> > otherwise the TextChanged won't be fired and the new value will be lost.
> >
> > Regards,
> >
> > --
> > Phil Harvey
> > www.anotherblog.com
> >
> >
> >
> > "Nathan Sokalski" wrote:
> >
> >> I have a Repeater who's ItemTemplate contains a TextBox that has
> >> AutoPostBack set to True. However, I am not sure where to handle this
> >> postback. When I have a Button in the ItemTemplate, I simply use the
> >> Repeater's ItemCommand event handler, but this event handler is not
> >> triggered for what would normally be the TextBox's TextChanged event. Can
> >> someone help me figure out how to handle this postback? Any help would be
> >> appreciated. Thanks.
> >> --
> >> Nathan Sokalski
> >> (E-Mail Removed)
> >> http://www.nathansokalski.com/
> >>
> >>
> >>

>
>
>

 
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
Using AutoPostBack with a TextBox in a Repeater Nathan Sokalski ASP .Net 4 10-16-2009 07:48 AM
AutopostBack for a TextBox =?Utf-8?B?Vmk=?= ASP .Net 5 10-29-2004 03:29 AM
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