Mobile Content

Monday, February 28, 2011

To fire two event when button is click

protected void Button1_Click(object sender,EventArgs e)
     respose.write("<script type='javascript'">
sqlconnection con=new sqlconnection("connection string.");
sqlcommand cmd=new sqlcommand("insert into sub value('a','b')",con);;

it will fire two event at a time, it will popup the default.aspx page and also insert data into sub table...

Monday, February 21, 2011

Two way to refresh the page using javascript

1. Using link.
<a href="javascript:location.reload(true)">Refresh </a>
it will show link "Refresh" on page by clicking, it will refresh the page

2. Automatic refreshing  of page using javascript

<script type="text/JavaScript">
function timedRefresh(timeoutPeriod) {
<body onload="JavaScript:timedRefresh(5000);">

it will refresh page every 5 sec when page is loaded

Sunday, February 20, 2011

Dynamically generate button or Textbox according to the data in database in

 For generating dynamic button and textbox according to data present in database
       {string[] nm=new string[100];
            SqlConnection con = new SqlConnection("connection string....");
            SqlCommand cmd = new SqlCommand("sql query.....", con);
            SqlDataReader dr = cmd.ExecuteReader();
            int cnt = 0;
            int c=0;
            while (dr.Read())
                for (int i = 0; i < cnt; i++)
                    Button btn = new Button();                        TextBox txt = new TextBox();
                    btn.Text = nm[i];
                     btn.ID = i + "id";                                       txt.ID = i + "txt";
                     form1.Controls.Add(btn);                        txt.Width = 16;
                                                                                     txt.Height = 16;
                                                                                     txt.BorderStyle = BorderStyle.None;
                                                                                  //   txt.Enabled = false;
it will generate the dynamic button and textbox according to data present in table

Refresh the gridview without refreshing the whole page using Ajax in

To refresh particular control we have to use <asp:UpdatePanel> with <asp:Timer> Ajax control.

Before taking this control we have to take <asp:ScriptManager> 
in aspx page
 <asp:ScriptManager ID="ScriptManager1" runat="server">
  <asp:UpdatePanel ID="UpdatePanel2" runat="server">
        <asp:Timer ID="Timer1" runat="server" Interval="5000">
  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" >
       <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
       <asp:BoundField DataField="Message" HeaderText="Message"
                SortExpression="Message" />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT [Date], [Message] FROM [ChatDb]"></asp:SqlDataSource>
   <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
in .cs page

 protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
            GridView1.DataSource = SqlDataSource1;

 protected void Timer1_Tick(object sender, EventArgs e)

            GridView1.DataSource = SqlDataSource1;


Saturday, February 19, 2011

popup occur by clicking button control in

we can popup using javascript in .aspx file or aspx.cs file
in aspx file
<script language="javascript">
function pop(url)
<asp:Button id="Button1" runat="server" Text="popup" onclick="pop('default.aspx')"/>// default.aspx page will pop up when we click popup button.

or we can also write        onclick="'default.aspx')"/>;

In .cs file
we can write

To refresh the page : html doc

<meta http-eqiv="Refresh" content="5" id="refresh" runat="server"/>

content=contain the second the page will refresh
we can refresh the page in .cs file by using id of <meta>
eg:  refresh.content=5;