2

I have to show confirmation dialogue on particular condition.And then proceed according to YES or No clicked.I tried with the following.

In aspx:

<script type="text/javascript">
  function ShowConfirmation() {
    if (confirm("Employee Introduced already.Continue?") == true) {
      document.getElementById("hdn_empname").value = 1;
    }
  }

</script>

<asp:HiddenField ID="hdn_empname" runat="server" />

in cs:

  if (reader2.HasRows)
    {  
        Page.ClientScript.RegisterStartupScript(this.GetType(), "showAl", "ShowConfirmation();", true);
    }
    else
    {
        hdn_empname.Value ="1";
    }

    if ((hdn_empname.Value)=="1")
    {
       //some code to execute
    }

But hdn_empname shows value="" while debuging.

Can anyone help me doing this?

Thanks in advance.

3 Answers 3

2

Try it You need to ClientID

document.getElementById('<%=hdn_empname.ClientID%>').value = 1;

I found out your main problems

The hidden field values will assign after the if condition call.

Edit :

So, You need to call your logic's in javascript side using ajax

if (confirm("Employee Introduced already.Continue?") == true) {

//some code to execute
    }
Sign up to request clarification or add additional context in comments.

2 Comments

So where do I assign the values?
Alborz already said theis: it is better that you set the ShowConfirmation function on onClientClick of you button
1

Where is your break point? If reader2.HasRows returns true your javascript will be registered. But it set the value on client and you get the result after postback.

4 Comments

The above code(in question) is under button click. and I have set breakpoint in button click.
So as i explained above the script is registered to client and the value will be eq 1 in the next post back. I think it is better that you set the ShowConfirmation function on onClientClick of you button.
Ok.. But i need it the confimation only on particular condition
May be the condition can be handled in ShowConfirmation function.But if you need to handle the condition in server side you can not handle it by this way. I suggest you using ajax call for handling the condition and showing confirm modal.
1

hdn_empname is server controls Id which is different from client sided id, to get client sided id you need to use ClientID

try this:

document.getElementById('<%=hdn_empname.ClientID%>').value = "1";

You dont need to compare

if (confirm("Employee Introduced already.Continue?") == true)

this will work:

if (confirm("Employee Introduced already.Continue?")) 

1 Comment

No this did not wok for me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.