Click here to Skip to main content
15,889,315 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
protected void Button1_Click(object sender, EventArgs e)
    {
       

            foreach (RepeaterItem item2 in Repeater1.Items)
            {

                CheckBox chkdel = item2.FindControl("CheckBox1") as CheckBox;
                if (chkdel.Checked)
                {


                    int lblid = Convert.ToInt32((item2.FindControl("Label1") as Label).Text);
                    string SqlConnect = System.Configuration.ConfigurationManager.ConnectionStrings["Connect"].ConnectionString;
                    SqlConnection Sqlconn = new SqlConnection(SqlConnect);
                    SqlCommand Sqlcomm = new SqlCommand("Delstock", Sqlconn);
                    Sqlcomm.CommandType = CommandType.StoredProcedure;
                    Sqlconn.Open();
                    Sqlcomm.Parameters.Add("@id", SqlDbType.Int).Value = lblid;
                    Sqlcomm.ExecuteNonQuery();
                    Sqlconn.Close();
                    Label2.Visible = true;

                    Label2.Text = "Stock Detail(s) Deleted";

                }


            }
            BindStockDetails();
       
   
    }



i want to clear label's value when the page is refreshed By user
Posted
Updated 9-Oct-12 6:26am
v2
Comments
Sergey Alexandrovich Kryukov 9-Oct-12 12:34pm    
Which label? Label2 (look, never use auto-generated names; always rename to something semantic; this is even the violation of good Microsoft naming conventions)? But you assigned an immediate string constant to its text. What do you need to have, an empty string? Then assign it, perhaps depending on some condition. What's the problem?
The question suggests you don't know how Web works, HTTP request/response, etc.
--SA
Teenustar 9-Oct-12 12:41pm    
Since you have the label inside the repeater control, depending on your requirement, during page post back find control and clear it or change the repeater binding to Nothing.

On Page_Load, set
C#
Label2.Text = "";
 
Share this answer
 
Comments
Surendra0x2 10-Oct-12 4:52am    
But if i set this then when i'll click on button then label2 will not show message
Label2.text="Stock Detail(s) Deleted";
MT_ 10-Oct-12 4:54am    
Can you make clear which label you want to clear ?
Surendra0x2 10-Oct-12 5:01am    
label2 sir you can find on above code
MT_ 10-Oct-12 5:03am    
So what is the problem you want to loose the value label2 and you are loosing it by setting as I said. If you want reset to "Stock Details(s) Deleted". set Label2.Text ="Stock Details(s) Deleted". Or even better set Text value in properties in design mode.
Surendra0x2 10-Oct-12 5:10am    
i want on Button Click, Label2 will appear and after when i refresh the page i want to clear the label's value
Label2.Text
set viewSate=false on properties
 
Share this answer
 
v2
<asp:Label ID="lblMsg" runat="server" Text="Stock Detail(s) Deleted" EnableViewState="false" visible="false"></asp:Label>

This is what you are looking for. Please Note
EnableViewState="false"


dheeraj9457 has already mentioned this.I just felt i should clarify.

Hope it helps.
 
Share this answer
 
Comments
Surendra0x2 10-Oct-12 4:55am    
Sir i want to clear label when page is refreshed by user
first time when i'll click on button then it will show label but when at the same time if i refresh the page then i want to clear the label's value
TheCoolCoder 10-Oct-12 5:11am    
See if you are talking about a refresh just after a button click normally if you hit f5 or refresh from browser you will be prompted 'if you want to resubmit data to server', if you click yes then the previous button click will be re-done, in that case your code label2.visible=true will execute again and the label will be shown, which is the way it is supposed to work. I dont know if the refresh behaviour can be altered, sorry.
Surendra0x2 11-Oct-12 8:01am    
Thanks sir

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900