Returned Page Won't Update When Using Custom Template & Textbox

Discussion in 'ASP .Net Datagrid Control' started by Greg Pyatt, Sep 18, 2003.

  1. Greg Pyatt

    Greg Pyatt Guest

    Hi ASP.NET programmers,

    I'm doing battle with a very tricky bug and it's mostly winning. I
    hope someone out there can help with a few ideas...

    I have a custom template column in a datagrid. In the template column
    I've included an HtmlInputText object. The custom object uses
    ITemplate.InstantiateIn.

    The page loads just fine, however when I postback to the server with
    an update to one of the textboxes, the database is updated correctly
    but the returned page looks as though it was populated with the
    Request.Form collection. It looks as though nothing happened between
    the update postback and the page being returned.

    Here is the code for the custom template colum object below:

    ------

    Option Strict On
    Option Explicit On

    Public Class HTMLInputTextColumn

    Implements ITemplate
    Dim m_ID As String
    Dim m_ColumnName As String

    Public Sub New(ByVal ID As String)
    m_ID = ID
    Select Case m_ID
    Case "txtNewBase"
    m_ColumnName = "salary_increase"
    Case "txtDollarIncrease"
    m_ColumnName = "dollar_increase"
    Case "txtPercentageIncrease"
    m_ColumnName = "percentage_increase"
    Case "txtLumpSum"
    m_ColumnName = "lump_sum_increase"
    End Select
    End Sub

    Overridable Overloads Sub InstantiateIn(ByVal container As
    Control) Implements ITemplate.InstantiateIn
    Dim txtTextbox As New HtmlInputText()

    With txtTextbox
    .Size = 6
    .ID = m_ID
    .Name = m_ID
    .EnableViewState = True
    End With

    AddHandler txtTextbox.DataBinding, AddressOf Me.OnDataBinding
    container.Controls.Add(txtTextbox)
    End Sub

    Private Sub OnDataBinding(ByVal sender As System.Object, ByVal e
    As System.EventArgs)
    Dim txtTextbox As HtmlInputText = CType(sender, HtmlInputText)
    Dim container As DataGridItem =
    CType(txtTextbox.NamingContainer, DataGridItem)
    txtTextbox.Value = CType(container.DataItem,
    DataRowView)(m_ColumnName).ToString()
    End Sub

    End Class

    ------

    That's it! I know this one's a real trick, because I've looked all
    over the internet for an answer and I'm still stuck. Thanks for any
    help, it's greatly appreciated!

    -Greg Pyatt
     
    Greg Pyatt, Sep 18, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Larry Bud

    Formview update--one field won't update

    Larry Bud, Jul 11, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    395
    Larry Bud
    Jul 11, 2007
  2. Donald Welker

    Update Textbox from adjacent dropdown in datagrid custom template

    Donald Welker, Aug 9, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    247
    Donald Welker
    Aug 10, 2005
  3. Replies:
    1
    Views:
    231
  4. Rico
    Replies:
    2
    Views:
    114
  5. Steve
    Replies:
    4
    Views:
    214
    Steve
    Feb 7, 2006
Loading...

Share This Page