button.click += new eventhandler() not works in if(!ispostback)


Posted on 16th Feb 2014 07:03 pm by admin

i want to use button.clcik event in function VIewScrap() which is called in if(!ispostback) but itdoes not works any slolution ? if i do not use if(!ispostback) then also button.click works first time well but in second time it just refresh the page for third time clicking it works what 2 do ? my code is given bellow ... using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Drawing;
using BussinessLayer;
public partial class WebControls_Scrap2 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{ if (!IsPostBack)
{
ViewScrap(); }
} private void ViewScrap()
{
Detail.Rows.Clear();
Scrap obj = new Scrap();
obj.UserName = Session["UserName"].ToString();
DataTable dt = obj.ReadScrap();
foreach (DataRow dr in dt.Rows)
{ HtmlTableRow tr1 = new HtmlTableRow();
HtmlTableRow tr2 = new HtmlTableRow();
HtmlTableCell tc1 = new HtmlTableCell();
HtmlTableCell tc2 = new HtmlTableCell();
HtmlTableCell tc3 = new HtmlTableCell();
HtmlTableCell tc4 = new HtmlTableCell();
HtmlImage userim = new HtmlImage();
HtmlAnchor ha2 = new HtmlAnchor();
HtmlAnchor ha = new HtmlAnchor();
userim.Width = 100;
userim.Height = 130;
if (dr["Photo"].ToString() != "Noimage.gif")
{
userim.Src = System.Configuration.ConfigurationManager.AppSettings["Image"].ToString() + dr["Sender"].ToString() + "/" + dr["Photo"].ToString();
}
else
{
userim.Src = System.Configuration.ConfigurationManager.AppSettings["ImagePath"].ToString() + dr["Photo"].ToString();
}
ha.HRef = "../SearchUser/SrchUserHome.aspx?UserName=" + dr["UserName"].ToString();
ha.Controls.Add(userim);
ha2.InnerText = dr["Name"].ToString();
ha2.HRef = "../SearchUser/SrchUserHome.aspx?UserName=" + dr["UserName"].ToString();
Button btndel = new Button();
btndel.Text = "Delete";
btndel.Click += new EventHandler(ClickDel);
btndel.CommandArgument = dr["ScrapId"].ToString();
Label lbl = new Label();
lbl.Text = dr["Scrap"].ToString();
lbl.Height = 103;
lbl.Width = 450;
lbl.BorderStyle = BorderStyle.Inset;
lbl.BorderWidth = 1;
lbl.BackColor = Color.Lavender; tc1.Controls.Add(ha);
tc2.Controls.Add(lbl);
tc3.Controls.Add(ha2);
tc4.Controls.Add(btndel); tc3.Align = "Left";
tc4.Align = "Right"; tc1.Width = "100";
tc3.Width = "100";
tc2.Width = "500";
tc4.Width = "500"; tr1.Cells.Add(tc1);
tr1.Cells.Add(tc2);
tr2.Cells.Add(tc3);
tr2.Cells.Add(tc4); Detail.Rows.Add(tr1);
Detail.Rows.Add(tr2);
} }
public void ClickDel(object sender, EventArgs e)
{
Button objbtn = (Button)sender;
Scrap obj = new Scrap();
obj.ScId = Convert.ToInt32(objbtn.CommandArgument.ToString());
obj.Delete();
ViewScrap();
}
protected void btnPost_Click(object sender, EventArgs e)
{
Scrap obj = new Scrap();
obj.UserName = Session["UserName"].ToString();
obj.Sender = Session["UserName"].ToString();
obj.Scraps = txtScrap.Text;
obj.InsertData();
ViewScrap();
}
}

No comments posted yet

Your Answer:

Login to answer
318 Like 32 Dislike
Previous forums Next forums
Other forums

Change Sort Order to Display Newest File First
Hi Guys,

I have a page that sorts the contents (PDFs) of a directory and displays them on the

How to add functionality to a simple php calender?
Hello everyone,

I have just finished creating a simple php calander. Can someone point

smart reading from a text file
Hello there fellow coders, i was wondering if one of you wouldnt mind helping me with this problem i

Multiple while loops
I have several DB queries that I know should be returning results and aren't. I have a feeling it ha

Conditions of info record - Error
When i created GR (901) and PO create automatic my PBXX is obtain the net price of info record but

Why is this function returning a false value when it shouldn't be??
This is in an include file. I want it to check a value in an html form and see if it's just white s

Javascript or not?
How many people prefer javascript/ajax sites? How many prefer the good old fashion straight php sit

Check something, wait, check again, do something!
Hi guys.

I wonder if someone can help me with this.

Basically, what I want to do is (

Dump with added_funcion cl_salv_table
Hi there, I'm having some troubles adding a self defined function to an ALV in fullscreen. The thing

Warning: session_start() headers already sent error - Driving me Nuts!
I am trying my sister in laws site and I keep getting an error with my coding. I am more of a design

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash