473,499 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c# bug on button click

5 New Member
hi,
I m very new here. So my base is not so strong and I have a small prob
I am trying to add a textbox at runtime on the click of a button.
So every time the button is clicked a new textbox has to be generated without effecting the previous textboxes that are already created.

here is my code
public partial class enteriquestions : System.Web.UI.Page
{
int rowcount;
public TableRow tr;
TableCell td1,td2;
TextBox tb1;
Label label1;

protected void Page_Load(object sender, EventArgs e)
{
if(Page.IsPostBack == false)
rowcount = 1;
createrow();
Page.Focus();

}
protected void Button2_Click(object sender, EventArgs e)
{
rowcount++;
createrow();
}
public void createrow()
{
tr = new TableRow();
td1 = new TableCell();
label1 = new Label();
label1.ID = "lbl" + rowcount.ToString();
label1.Text = "Enter Question" + rowcount;
td2 = new TableCell();
tb1 = new TextBox();
tb1.ID = "txtbox" + rowcount.ToString();
tb1.Width = 700;
td1.Controls.Add(label1);
td2.Controls.Add(tb1);
tr.Cells.Add(td1);
tr.Cells.Add(td2);
Table1.Rows.Add(tr);
tb1.Focus();
}



-------
The problem that i am having is everytime the button is clicked the rowcount is reinitialized to 0. How do i solve this to increament the row count.
Please help me
Jul 15 '07 #1
5 1410
kenobewan
4,871 Recognized Expert Specialist
The value won't increment unless you store it somewhere. I remember once storing it textbox that that wasn't visible. HTH.
Jul 15 '07 #2
shhntl
5 New Member
Can u please elaborate the explaination.I mreally new and I donot get this.
I am creating a variable rowcount.
First time initializing it to 1 and then everytime the button is clicked it has to increament because i have rowcount++.
but this doesnot happen. How can i make it increament.
where do i have to store the value ?
Jul 15 '07 #3
nmsreddi
366 Contributor
Can u please elaborate the explaination.I mreally new and I donot get this.
I am creating a variable rowcount.
First time initializing it to 1 and then everytime the button is clicked it has to increament because i have rowcount++.
but this doesnot happen. How can i make it increament.
where do i have to store the value ?
Hello

i a web application when ever the page is post back you have to maintain the view state of some variables ,so you variable is restoring to initial value on each click,

try to maintain the view state of the variable so that it always store the latest updated value ,to do this you have many ways(sessions ,applications,some times static fields) try to choose your best way

Good Luck
Jul 16 '07 #4
shhntl
5 New Member
thanks very much for your help. IT was really help ful.
I stored the rowcount in the session and now the rowcount is increamenting in the way that i wished it to do.
But now on every button click as the page is refreshed the previous textboxes disappears and only the new one in displayed.
what do I do so that the previous rows remain and the new row is generated.
Plz help me out to finish this code.
Jul 16 '07 #5
Plater
7,872 Recognized Expert Expert
You will need to store and restore those textboxes in some sort of persistant collection.
thanks very much for your help. IT was really help ful.
I stored the rowcount in the session and now the rowcount is increamenting in the way that i wished it to do.
But now on every button click as the page is refreshed the previous textboxes disappears and only the new one in displayed.
what do I do so that the previous rows remain and the new row is generated.
Plz help me out to finish this code.
Jul 16 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
6800
by: Steve | last post by:
Hi, Is it possible to make hitting the enter key in an ASP textbox run the code behind an ASP button on a form? I have a search page which users tend to type in the query then just hit enter...
11
13845
by: CW | last post by:
I have message entry screen that's causing me a bit of an issue. At the moment, there are 2 buttons, one is used to send message to another user (btnSend) and another is used to send messages to...
1
1786
by: Klaus Jensen | last post by:
Hi! This has been annoying me all day, and I can't get it to work It is really driving me nuts! Basicly this simple webapp created to illustrate my problem, renders five buttons, and adds a...
3
8703
by: Imran Aziz | last post by:
Hello All, I have a search text and button that post data and my button handler filters the repeater control. However when the button is clicked the first time. The page_load event is being called...
5
5403
by: Wonder | last post by:
How can I create or use the msgobx to show a message without a default button. The user has explicity to click on the button, so the msgbox closes it. Thanks,
21
8115
by: Ben | last post by:
Hello I have frames set up in an asp.net application and need one frame to refresh another. Seeing as events need to be registered at the time the page is sent from the server, I was wondering...
6
2796
by: user | last post by:
Hello, With ASP.NET2, how to program a button's click ? For example, I have two button and when i click the first one, i would like that the second one will be click too (by programming) ......
7
6843
by: =?Utf-8?B?bWFydGluMQ==?= | last post by:
Hi, All, I create button in the code ( Dim Button as new Button), not using button web component (means not drap button and drop it ont he webform), after that I try to use button_click event,...
9
2725
by: Jonathan Wood | last post by:
Does anyone know of any reason a button on a master page would have no effect? I have a complex HTML page that I'm converting to ASP.NET, and acknowledge I could have something odd that is...
1
6960
by: daonho | last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the...
0
7009
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.