Asp.Net Bind javascript to textbox

Discussion in 'Software' started by kasbekar.ajay, Apr 22, 2010.

  1. kasbekar.ajay

    kasbekar.ajay

    Joined:
    Apr 22, 2010
    Messages:
    2
    I have a datatable with 8 columns and 500 rows. (8*500=4000) elements.
    I am binding this data table to gridview and showing all elements in texbox.
    The page contents are display very fast in 3-5 seconds and i am showing all rows in grid ( Paging is not implemented)

    <asp:GridView ID="gvHistoricalLFG" runat="server" AutoGenerateColumns="false">
    <Columns>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:TextBox ID="txt1" runat="server" Text='<%# Eval("1") %>' />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:TextBox ID="txt2" runat="server" Text='<%# Eval("2") %>' />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:TextBox ID="txt3" runat="server" Text='<%# Eval("3") %>' />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:TextBox ID="txt4" runat="server" Text='<%# Eval("4") %>' />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:TextBox ID="txt5" runat="server" Text='<%# Eval("5") %>' />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:TextBox ID="txt6" runat="server" Text='<%# Eval("6") %>' />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:TextBox ID="txt7" runat="server" Text='<%# Eval("7") %>' />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:TextBox ID="txt8" runat="server" Text='<%# Eval("8") %>' />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>


    -- Code Behing

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    '****************** Create Table with 8*500 elements
    Dim dt As New DataTable
    Dim counter As Int32 = 1
    Dim dr As DataRow

    dt.Columns.Add(New DataColumn("1"))
    dt.Columns.Add(New DataColumn("2"))
    dt.Columns.Add(New DataColumn("3"))
    dt.Columns.Add(New DataColumn("4"))
    dt.Columns.Add(New DataColumn("5"))
    dt.Columns.Add(New DataColumn("6"))
    dt.Columns.Add(New DataColumn("7"))
    dt.Columns.Add(New DataColumn("8"))

    While (counter <= 5)
    dr = dt.NewRow()
    dr("1") = counter
    dr("2") = counter
    dr("3") = counter
    dr("4") = counter
    dr("5") = counter
    dr("6") = counter
    dr("7") = counter
    dr("8") = counter
    dt.Rows.Add(dr)
    counter = counter + 1
    End While
    '****************** Create Table with 8*500 elements

    ' bind table
    gvHistoricalLFG.DataSource = dt
    gvHistoricalLFG.DataBind()
    End Sub


    The code works and grid is showing in 3-5 seconds.

    Later i added simple javascript to all the textbox in RowDataBound event as shown

    Private Sub gvHistoricalLFG_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvHistoricalLFG.RowDataBound

    ' bind javascript to each textbox
    If (e.Row.RowType = DataControlRowType.DataRow) Then
    DirectCast(e.Row.FindControl("txt1"), System.Web.UI.WebControls.TextBox).Attributes.Add("onblur", "javascript:alert('Welcome')")
    DirectCast(e.Row.FindControl("txt2"), System.Web.UI.WebControls.TextBox).Attributes.Add("onblur", "javascript:alert('Welcome')")
    DirectCast(e.Row.FindControl("txt3"), System.Web.UI.WebControls.TextBox).Attributes.Add("onblur", "javascript:alert('Welcome')")
    DirectCast(e.Row.FindControl("txt4"), System.Web.UI.WebControls.TextBox).Attributes.Add("onblur", "javascript:alert('Welcome')")
    DirectCast(e.Row.FindControl("txt5"), System.Web.UI.WebControls.TextBox).Attributes.Add("onblur", "javascript:alert('Welcome')")
    DirectCast(e.Row.FindControl("txt6"), System.Web.UI.WebControls.TextBox).Attributes.Add("onblur", "javascript:alert('Welcome')")
    DirectCast(e.Row.FindControl("txt7"), System.Web.UI.WebControls.TextBox).Attributes.Add("onblur", "javascript:alert('Welcome')")
    DirectCast(e.Row.FindControl("txt8"), System.Web.UI.WebControls.TextBox).Attributes.Add("onblur", "javascript:alert('Welcome')")
    End If


    End Sub



    But when i add javascript to textbox then it take 7-8 minutes to display the page. How only attaching simple javascript to each textbox slows down the page. Any alternative method to attach javascript and render page faster.
    I don't want to implement paging and need to show all data.
    kasbekar.ajay, Apr 22, 2010
    #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. smi59550
    Replies:
    0
    Views:
    1,525
    smi59550
    Jan 18, 2008
  2. smi59550
    Replies:
    0
    Views:
    6,073
    smi59550
    Jan 18, 2008
  3. tmpm7
    Replies:
    0
    Views:
    1,146
    tmpm7
    Feb 18, 2008
  4. write2atif
    Replies:
    0
    Views:
    4,283
    write2atif
    Apr 30, 2009
  5. kasbekar.ajay

    GridView bind javascript

    kasbekar.ajay, Apr 26, 2010, in forum: Software
    Replies:
    0
    Views:
    3,677
    kasbekar.ajay
    Apr 26, 2010
Loading...

Share This Page