473,545 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_Clic ked(object sender, ImageClickEvent Args e)
{
if (!misc.validate SiteCodes(out error, siteCodeText, startLoginText,
provAcctIDText) )
{
string clientID = this.ClientID;
Page.RegisterHi ddenField(clien tID +"_confirmValue ", "0");
string clientConfirm = "<script language=javasc ript>if (confirm('"
+error +
"?')) { document.getEle mentById('"+ 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="confirmValu e" name="conformVa lue" 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.getEl ementById(...)' 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=javasc ript>if (confirm('Accou nt ID does not match the site
Number. Do you still want to continue??')) {
document.getEle mentById('aldpa Pnl_confirmValu e').value = '1' } </script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
..
..
..
..
..
..
<td colspan="4"><in put name="aldpaPnl: confirmValue"
id="aldpaPnl_co nfirmValue" type="hidden" value="0" /></td>
I have tried using the RegisterStartup Script, 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 RegisterClientS criptBlock. Please do help..."

Thanks in advance.
--
GettingHelp/JustTryingToHel p
Nov 19 '05 #1
1 3817
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=javasc ript>
if (confirm('error message'))
{
document.getEle mentById('aldpa Pnl_confirmValu e').value = '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_Clic ked
if(//validation call failed)
{
string clientConfirm = //code to create javascript ;
Page.RegisterSt artupScript("so mename",clientC onfirm); // this
will display confirm dialog ...
}
else
{
AddToDB(); //when validation success, insert to DB
}
3) In Page_Load

if(Page.IsPostB ack)
{

if (Request["confirmVal ue"] == "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
"freshRecru it" 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_Clic ked(object sender, ImageClickEvent Args e)
{
if (!misc.validate SiteCodes(out error, siteCodeText, startLoginText,
provAcctIDText) )
{
string clientID = this.ClientID;
Page.RegisterHi ddenField(clien tID +"_confirmValue ", "0");
string clientConfirm = "<script language=javasc ript>if (confirm('"
+error +
"?')) { document.getEle mentById('"+ 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="confirmValu e" name="conformVa lue" 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.getEl ementById(...)' 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=javasc ript>if (confirm('Accou nt ID does not match the site
Number. Do you still want to continue??')) {
document.getEle mentById('aldpa Pnl_confirmValu e').value = '1' } </script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
.
.
.
.
.
.
<td colspan="4"><in put name="aldpaPnl: confirmValue"
id="aldpaPnl_co nfirmValue" type="hidden" value="0" /></td>
I have tried using the RegisterStartup Script, 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 RegisterClientS criptBlock. Please do help..."

Thanks in advance.
--
GettingHelp/JustTryingToHel p

Nov 19 '05 #2

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

Similar topics

2
7110
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 be able to drag-and-drop to the treeview from outside the UserControl. Now, when I drag over the treeview in the UserControl, the UserControl gets...
8
1950
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 that category, the results are paged 10 to a page and the user can page them. As this "Category" usercontrol hardly ever changes I wanted to setup...
2
4607
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 for me! I apologize for the length of this posting, but I wanted to make sure that I get an answer other than "Hey man, just use LoadControl!",...
41
4257
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 on some initialization information obtained elsewhere. Basically, I'm going to create my own dynamic toolbar where the toolbarbuttons can change. ...
12
2183
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 server. It "serves" back the required control (either WebControl or UserControl) based on the contents of an xml file. The code in the webform places...
9
14427
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 does not. The problem is that the webcontrols get created on the OnLoad event of the usercontrol and the event handlers are assigned at the same...
14
1235
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 actually if they are larger than an int.MaxValue. Steps to reproduce: 1. Create a Windows Control Library project 2. Create a new control...
6
12123
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 binding like normal. The problem I am running into is that my UserControl ends up with a different BindingContext then the ParentForm it is...
10
2404
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 my question. Once the UserControl is dropped onto the container page, how can I perform some action on the codebehind of the container page from...
0
7664
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7918
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7436
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5981
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3463
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1897
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 we have to send another system
1
1022
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
715
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.