473,425 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,425 software developers and data experts.

Confirm box in usercontrol

Hi,

I am having a problem, and is driving me nuts and my deadline is fast
approaching. Please do help me..

This is a webapplication with a usercontrol which has some buttons for
adding, deleting and updating to a database. When the user clicks the "Add"
button than the information provided is validated against the database. If
the validation succeeds than the information is added to the database. If not
a confirm box is shown and if the user clicks "yes" than the data is added
else the whole operation is suspended.

Here is the code in the usercontrol:

private void provBtnAdd_Clicked(object sender, ImageClickEventArgs e)
{
if (!misc.validateSiteCodes(out error, siteCodeText, startLoginText,
provAcctIDText))
{
string clientID = this.ClientID;
Page.RegisterHiddenField(clientID +"_confirmValue", "0");
string clientConfirm = "<script language=javascript>if (confirm('"
+error +
"?')) { document.getElementById('"+ clientID +
"_confirmValue').value = '1' } <" + "/"+ "script>";
Response.Write(clientConfirm);
}
if (confirmValue == "1")
{
.....// The Addition operation
}
}

The usercontrol also has the following input element:
<input type="hidden" id="confirmValue" name="conformValue" runat="server"
value="0" />

Whenever I click on the "Add" button, the confirm appears in a blank screen
rather than on the existing page and does not do the addition operation
inspite of the user clicking on "yes". The error it is displaying is:

'document.getElementById(...)' is null or not an object

When I investigated the source, it has the element. So I am not sure what is
wrong.

The snippet from the view source:

<script language=javascript>if (confirm('Account ID does not match the site
Number. Do you still want to continue??')) {
document.getElementById('aldpaPnl_confirmValue').v alue = '1' } </script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
..
..
..
..
..
..
<td colspan="4"><input name="aldpaPnl:confirmValue"
id="aldpaPnl_confirmValue" type="hidden" value="0" /></td>
I have tried using the RegisterStartupScript, but when I use it the confirm
box is shown after the record has been added to the database. I can see the
record being displayed and the confirm box appearing on top of it. The same
with the RegisterClientScriptBlock. Please do help..."

Thanks in advance.
--
GettingHelp/JustTryingToHelp
Nov 19 '05 #1
1 3807
The issue is that a submit back to server , upon user confirmation, is
missing..

The code does not execute seqentially between client & server code .. you
will need to explicitly call the form submit from javascript when the user
select "OK" from the confirm box..

your javascript (in view source) should be like

<script language=javascript>
if (confirm('error message'))
{
document.getElementById('aldpaPnl_confirmValue').v alue = '1'

document.forms[0].submit();
}
</script>

One solution..

1) Make a seperate c# function for adding to the database

void AddToDB()
{
.....// The Addition operation
}
2) In provBtnAdd_Clicked
if(//validation call failed)
{
string clientConfirm = //code to create javascript ;
Page.RegisterStartupScript("somename",clientConfir m); // this
will display confirm dialog ...
}
else
{
AddToDB(); //when validation success, insert to DB
}
3) In Page_Load

if(Page.IsPostBack)
{

if (Request["confirmValue"] == "1")
{
AddToDB(); // insert to DB
Request[confirmValue] = 0; // reset the value ,
so that the next post back does not insert again..
}
// continue other bussiness
}

Some reading on asp.net & javascrip may help
http://aspnet.4guysfromrolla.com/articles/021104-1.aspx

HTH
"freshRecruit" wrote:
Hi,

I am having a problem, and is driving me nuts and my deadline is fast
approaching. Please do help me..

This is a webapplication with a usercontrol which has some buttons for
adding, deleting and updating to a database. When the user clicks the "Add"
button than the information provided is validated against the database. If
the validation succeeds than the information is added to the database. If not
a confirm box is shown and if the user clicks "yes" than the data is added
else the whole operation is suspended.

Here is the code in the usercontrol:

private void provBtnAdd_Clicked(object sender, ImageClickEventArgs e)
{
if (!misc.validateSiteCodes(out error, siteCodeText, startLoginText,
provAcctIDText))
{
string clientID = this.ClientID;
Page.RegisterHiddenField(clientID +"_confirmValue", "0");
string clientConfirm = "<script language=javascript>if (confirm('"
+error +
"?')) { document.getElementById('"+ clientID +
"_confirmValue').value = '1' } <" + "/"+ "script>";
Response.Write(clientConfirm);
}
if (confirmValue == "1")
{
.....// The Addition operation
}
}

The usercontrol also has the following input element:
<input type="hidden" id="confirmValue" name="conformValue" runat="server"
value="0" />

Whenever I click on the "Add" button, the confirm appears in a blank screen
rather than on the existing page and does not do the addition operation
inspite of the user clicking on "yes". The error it is displaying is:

'document.getElementById(...)' is null or not an object

When I investigated the source, it has the element. So I am not sure what is
wrong.

The snippet from the view source:

<script language=javascript>if (confirm('Account ID does not match the site
Number. Do you still want to continue??')) {
document.getElementById('aldpaPnl_confirmValue').v alue = '1' } </script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
.
.
.
.
.
.
<td colspan="4"><input name="aldpaPnl:confirmValue"
id="aldpaPnl_confirmValue" type="hidden" value="0" /></td>
I have tried using the RegisterStartupScript, but when I use it the confirm
box is shown after the record has been added to the database. I can see the
record being displayed and the confirm box appearing on top of it. The same
with the RegisterClientScriptBlock. Please do help..."

Thanks in advance.
--
GettingHelp/JustTryingToHelp

Nov 19 '05 #2

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

Similar topics

2
by: Dave Veeneman | last post by:
Is there a simple way to pass drag-and-drop events to a child control in a UserControl? Here's an example: I have created a UserControl which contains a treeview and some text boxes. I want to...
8
by: Raed Sawalha | last post by:
Hi, I have a strange problem with a usercontrol on a page. The usercontrol dispalyes three categories (From a database) when the user clicks a category they see all the products in a shop for...
2
by: Sascha | last post by:
Hi there, I searched carefully through the web before finally deciding to post this message, because I could not find a solution for my problem. Hopefully someone will have a hint or explanation...
41
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
12
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control...
9
by: Marcelo Cabrera | last post by:
Hi, I have a user control that in turn creates a bunch of webcontrols dynamically and handles the events these webcontrols raise. It used to work fine on ASP .Net 1.1 but when compiled on 2.0 it...
14
by: Michael Bray | last post by:
Please, someone verify that this isn't just my system with this error... The problem is that VS.net can't properly store large 'long' values for control properties.. I'm guessing the threshold is...
6
by: MeowCow | last post by:
I have created a UserControl that encapsulates a third party data grid. My goal was to create my own DataSource and DataMember properties that forward the binding to the third party grid, then use...
10
by: Benton | last post by:
Hi there, I have a UserControl with a couple of textboxes and a couple of buttons ("Save" and "Cancel"). The Click event for this buttons is in the UserControl's codebehind of course, so here's...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
1
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...
0
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...

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.