문제

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.

도움이 되었습니까?

해결책 2

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.

다른 팁

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
    }

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?")) 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top