By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,190 Members | 2,204 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,190 IT Pros & Developers. It's quick & easy.

Confirm box in usercontrol

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.