Javascript.
<script type="text/javascript">
function scrollfix()
{
document.getElementById("testDiv").innerHTML += document.getElementById('TextBox1').value;
document.getElementById("testDiv").scrollTop = 999999999; //maximum top position
}
</script>
.aspx page
On Button onClientClick Call function
<div id="testDiv" style="text-align: left;width:150px; height: 200px; overflow-y:auto; overflow-x:hidden">
<asp:Panel ID="Panel1" runat="server" Width="150px">
</asp:Panel>
</div>
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Width="130px"></asp:TextBox>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" onClientClick="scrollfix()" />
</ContentTemplate>
</asp:UpdatePanel>
.cs page
//import
using System.Data.SqlClient;
using System.Data;
//page load event
SqlConnection con;
SqlCommand cmd;
Protected void Page_Load(object sender, EventArgs e)
{
con = New SqlConnection("Connection string");
cmd = New SqlCommand("select name from test", con);
SqlDataAdapter sda = New SqlDataAdapter(cmd);
DataSet ds = New DataSet;
sda.Fill(ds);
If ds.Tables(0).Rows.Count > 0
{
i = ds.Tables(0).Rows.Count;
For ( j = 0 ;j<i ;j ++ )
{
Label l = New Label;
l.Text = "ds.Tables(0).Rows(j).ItemArray(0).ToString() + "<br/>";
l.ID = "l" + j.ToString();
l.Width = 90;
Panel1.Controls.Add(l);
}
}
TextBox1.Focus();
}
// Button1 click event
Protected void Button1_Click( Object sender,EventArgs e )
{
cmd = New SqlCommand("insert into test values('" & TextBox1.Text & "')", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
o/p
On Every postback ,position of scroll remain at top
<script type="text/javascript">
function scrollfix()
{
document.getElementById("testDiv").innerHTML += document.getElementById('TextBox1').value;
document.getElementById("testDiv").scrollTop = 999999999; //maximum top position
}
</script>
.aspx page
On Button onClientClick Call function
<div id="testDiv" style="text-align: left;width:150px; height: 200px; overflow-y:auto; overflow-x:hidden">
<asp:Panel ID="Panel1" runat="server" Width="150px">
</asp:Panel>
</div>
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Width="130px"></asp:TextBox>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" onClientClick="scrollfix()" />
</ContentTemplate>
</asp:UpdatePanel>
.cs page
//import
using System.Data.SqlClient;
using System.Data;
//page load event
SqlConnection con;
SqlCommand cmd;
Protected void Page_Load(object sender, EventArgs e)
{
con = New SqlConnection("Connection string");
cmd = New SqlCommand("select name from test", con);
SqlDataAdapter sda = New SqlDataAdapter(cmd);
DataSet ds = New DataSet;
sda.Fill(ds);
If ds.Tables(0).Rows.Count > 0
{
i = ds.Tables(0).Rows.Count;
For ( j = 0 ;j<i ;j ++ )
{
Label l = New Label;
l.Text = "ds.Tables(0).Rows(j).ItemArray(0).ToString() + "<br/>";
l.ID = "l" + j.ToString();
l.Width = 90;
Panel1.Controls.Add(l);
}
}
TextBox1.Focus();
}
// Button1 click event
Protected void Button1_Click( Object sender,EventArgs e )
{
cmd = New SqlCommand("insert into test values('" & TextBox1.Text & "')", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
o/p
On Every postback ,position of scroll remain at top
No comments:
Post a Comment