473,503 Members | 5,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Disable button's "submit" behavior

GD
Hi,
I wonder how to disable the "submit" behavior of a button. What I want is to
assign values to dynamically added user controls without page postback.

Problem: dynamically created control can not be accessed because the button
click trigers page postback(see sample code). When the button is clicked, an
error occurs: "System.NullReferenceException: Object reference not set to an
instance of an object."

Please help. Thanks.

GD
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Button Button1;
public WebUserControl1 userCtl;

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
for (int i = 0; i < 5; i++)
{
userCtl = (WebUserControl1) LoadControl("WebUserControl1.ascx");
userCtl.ID = "ID" + i;
Panel1.Controls.Add(userCtl);
}
}
}

private void Button1_Click(object sender, System.EventArgs e)
{
userCtl = (WebUserControl1)FindControl("ID2");
userCtl.ctlValue = "test it";
}
}
Nov 18 '05 #1
6 4027
Can you not test for Page.IsPostBack for loading the "dynamic" controls. That might be cause of the problem?

--
Girish Bharadwaj
http://msmvps.com/gbvb

Hi,
I wonder how to disable the "submit" behavior of a button. What I want
is to
assign values to dynamically added user controls without page
postback.
Problem: dynamically created control can not be accessed because the
button click trigers page postback(see sample code). When the button
is clicked, an error occurs: "System.NullReferenceException: Object
reference not set to an instance of an object."

Please help. Thanks.

GD

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Button Button1;
public WebUserControl1 userCtl;
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
for (int i = 0; i < 5; i++)
{
userCtl = (WebUserControl1) LoadControl("WebUserControl1.ascx");
userCtl.ID = "ID" + i;
Panel1.Controls.Add(userCtl);
}
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
userCtl = (WebUserControl1)FindControl("ID2");
userCtl.ctlValue = "test it";
}
}


Nov 18 '05 #2
if you want to disble a submit behavior. i understand your requirement, you
do not want server side postback.

if you are using buttons of webcontrols type then you could set enabled =
falsel
otherwise consider using the html control <input type=button name="myButton"
id="myButton value="button title">

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"GD" <ge*********@comcast.net> wrote in message
news:uF*************@tk2msftngp13.phx.gbl...
Hi,
I wonder how to disable the "submit" behavior of a button. What I want is to assign values to dynamically added user controls without page postback.

Problem: dynamically created control can not be accessed because the button click trigers page postback(see sample code). When the button is clicked, an error occurs: "System.NullReferenceException: Object reference not set to an instance of an object."

Please help. Thanks.

GD
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Button Button1;
public WebUserControl1 userCtl;

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
for (int i = 0; i < 5; i++)
{
userCtl = (WebUserControl1) LoadControl("WebUserControl1.ascx");
userCtl.ID = "ID" + i;
Panel1.Controls.Add(userCtl);
}
}
}

private void Button1_Click(object sender, System.EventArgs e)
{
userCtl = (WebUserControl1)FindControl("ID2");
userCtl.ctlValue = "test it";
}
}

Nov 18 '05 #3
GD
Yes, I have to initialize the first group of controls under
!Page.IsPostBack, and then generate another group of controls based on the
values in the first group (in dropdown box).

"Girish bharadwaj" <gi*****@mvps.org> wrote in message
news:ul**************@TK2MSFTNGP09.phx.gbl...
Can you not test for Page.IsPostBack for loading the "dynamic" controls.
That might be cause of the problem?

--
Girish Bharadwaj
http://msmvps.com/gbvb

Hi,
I wonder how to disable the "submit" behavior of a button. What I want
is to
assign values to dynamically added user controls without page
postback.
Problem: dynamically created control can not be accessed because the
button click trigers page postback(see sample code). When the button
is clicked, an error occurs: "System.NullReferenceException: Object
reference not set to an instance of an object."

Please help. Thanks.

GD

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Button Button1;
public WebUserControl1 userCtl;
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
for (int i = 0; i < 5; i++)
{
userCtl = (WebUserControl1) LoadControl("WebUserControl1.ascx");
userCtl.ID = "ID" + i;
Panel1.Controls.Add(userCtl);
}
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
userCtl = (WebUserControl1)FindControl("ID2");
userCtl.ctlValue = "test it";
}
}

Nov 18 '05 #4
GD
'set enabled = false' simply disables the button. How can I access the
server controls using Html buttons? By client javascript?

"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
if you want to disble a submit behavior. i understand your requirement,
you
do not want server side postback.

if you are using buttons of webcontrols type then you could set enabled =
falsel
otherwise consider using the html control <input type=button
name="myButton"
id="myButton value="button title">

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"GD" <ge*********@comcast.net> wrote in message
news:uF*************@tk2msftngp13.phx.gbl...
Hi,
I wonder how to disable the "submit" behavior of a button. What I want is

to
assign values to dynamically added user controls without page postback.

Problem: dynamically created control can not be accessed because the

button
click trigers page postback(see sample code). When the button is clicked,

an
error occurs: "System.NullReferenceException: Object reference not set to

an
instance of an object."

Please help. Thanks.

GD
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Button Button1;
public WebUserControl1 userCtl;

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
for (int i = 0; i < 5; i++)
{
userCtl = (WebUserControl1) LoadControl("WebUserControl1.ascx");
userCtl.ID = "ID" + i;
Panel1.Controls.Add(userCtl);
}
}
}

private void Button1_Click(object sender, System.EventArgs e)
{
userCtl = (WebUserControl1)FindControl("ID2");
userCtl.ctlValue = "test it";
}
}


Nov 18 '05 #5
have a look at the rendered html. you will have to rely on javascript to
disable the submit for you.
you will need to access the buttons using the rendered name to disable them.

i would advise you to use htmlcontrols and specify a proper name for which
writing javascript should be a lot easier.

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"GD" <ge*********@comcast.net> wrote in message
news:#O**************@TK2MSFTNGP10.phx.gbl...
'set enabled = false' simply disables the button. How can I access the
server controls using Html buttons? By client javascript?

"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
if you want to disble a submit behavior. i understand your requirement,
you
do not want server side postback.

if you are using buttons of webcontrols type then you could set enabled = falsel
otherwise consider using the html control <input type=button
name="myButton"
id="myButton value="button title">

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"GD" <ge*********@comcast.net> wrote in message
news:uF*************@tk2msftngp13.phx.gbl...
Hi,
I wonder how to disable the "submit" behavior of a button. What I want
is to
assign values to dynamically added user controls without page postback.

Problem: dynamically created control can not be accessed because the

button
click trigers page postback(see sample code). When the button is
clicked, an
error occurs: "System.NullReferenceException: Object reference not set
to an
instance of an object."

Please help. Thanks.

GD
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Button Button1;
public WebUserControl1 userCtl;

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
for (int i = 0; i < 5; i++)
{
userCtl = (WebUserControl1) LoadControl("WebUserControl1.ascx");
userCtl.ID = "ID" + i;
Panel1.Controls.Add(userCtl);
}
}
}

private void Button1_Click(object sender, System.EventArgs e)
{
userCtl = (WebUserControl1)FindControl("ID2");
userCtl.ctlValue = "test it";
}
}



Nov 18 '05 #6
Can you add a client side javascript that returns false for click() and add that as the OnClick() handler for the new buttons.
Would that help?

<script>
function onClick() {
return false;
}
</script>

in the client side html.
btn.Attributes.Add("onclick","onClick();"); on your server side code..
would that help you?

--
Girish Bharadwaj
http://msmvps.com/gbvb

Yes, I have to initialize the first group of controls under
!Page.IsPostBack, and then generate another group of controls based on
the values in the first group (in dropdown box).

"Girish bharadwaj" <gi*****@mvps.org> wrote in message
news:ul**************@TK2MSFTNGP09.phx.gbl...
Can you not test for Page.IsPostBack for loading the "dynamic"
controls. That might be cause of the problem?

--
Girish Bharadwaj
http://msmvps.com/gbvb
Hi,
I wonder how to disable the "submit" behavior of a button. What I
want
is to
assign values to dynamically added user controls without page
postback.
Problem: dynamically created control can not be accessed because the
button click trigers page postback(see sample code). When the
button
is clicked, an error occurs: "System.NullReferenceException: Object
reference not set to an instance of an object."
Please help. Thanks.

GD

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Button Button1;
public WebUserControl1 userCtl;
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
for (int i = 0; i < 5; i++)
{
userCtl = (WebUserControl1) LoadControl("WebUserControl1.ascx");
userCtl.ID = "ID" + i;
Panel1.Controls.Add(userCtl);
}
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
userCtl = (WebUserControl1)FindControl("ID2");
userCtl.ctlValue = "test it";
}
}


Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
12365
by: lsarg | last post by:
i've been trying forever to figure out a way to use a regular text link in place of a submit button at the bottom of this. can't get it. i'm just starting to learn php, so i'm stuck. any help at...
7
5274
by: NotGiven | last post by:
I changed my POST to GET and find appended to the url, the above string. Why and what can I do to NOT have them appended? Thanks.
5
10425
by: Mikko Rantalainen | last post by:
See example at <URL:http://www.cc.jyu.fi/~mira/moz/formtest.php>. The problem is that the label of submit button is always centered on the button regardsless of 'text-align' property in CSS....
3
7704
by: Pete Wilson | last post by:
How can I highlight the <input type="submit"> object that I want to highlight? 1. In my form, the user enters his ID. He sees two submit "buttons," left labeled Cancel, the right labeled Signup....
3
10127
by: Adam | last post by:
Hey guys, I've decided to stop banging my head against the wall and just ask you guys for the answer. I can't seem to find it. I have a form in which I have multiple submit buttons; only, I'm...
5
19990
by: Alex Maghen | last post by:
In ASPX 2.0 with MasterPages and all that, my entire page only has one actual <FORM>. But there are several different sections of the page that provide what are functionally separate forms with...
9
2308
by: Alexandra | last post by:
Not sure why none of these permutations are working. I appreciate a second set of eyes! .... <form id="form1" name="form1" > .... <input name="Submit1" type="submit" tabindex="10"...
17
5639
by: axlq | last post by:
Situation: User submits a form, gets a page returned. User clicks the "reload button." Normal result: Browser asks to confirm re-submitting of the form data. That's not what I want. What I...
14
75434
by: white lightning | last post by:
How to have <select onchange="this.form.submit()"and also a Submit button on one form? I have something like this: <form action="<?php $_SERVER; ?>" method="post"...
0
7070
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
7267
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,...
1
6976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4993
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
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
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
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
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 ...
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.