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

Fetching array then reversing it
Hi, I have a simple problem, I'll try to explain it as best I can:
News entries in my database ar

Xml parsing
I need a suggestion about parsing xml with multiply parts like pervious...
i.e. different device

Image DPI
Hi.

I allow users to upload images, the user then is able to adjust several settings for the

calendar dates and hours compare problem
i have a calendar in wordpress, everything works great except that i can make 2 meetings at the same

Login Control?!
I have a Web Site that uses the login control also I have set the destinationurl to the page I want

I face problems to extract data from one table and insert it in another one
Hi,

For modifications, I have to extract data from one table and insert it in another one

Array help
Hello i got this code to fetch data from database but it is not working it displays
7
Array

Is it possible to put an entire 500-page book in a database with PHP?
I am working on an intranet and I was wondering if its possible to code php with mysql to enter a fu

Generate multilayered array from string.
ok so i have a string that looks like this:
Code: [Select]blog:edit_all,delete_all|users:edit_all

Thought I has this figured out especially after all the help i received?
Cags, Salathe, Daniel helped me with this yesterday, but not sure i took it all in.
I am attempti

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