Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Dear All,

I am using the Page.ClientScript inside the button click event. So, how can i get the any value from below funvtion.
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "validate();", true);


the pop up is display of confirm button but i want to know that user click the "Ok" or "Cancel" button, so i can do based on that particular code.

<script type="text/javascript">

function validate()
{
       if(!confirm('Are you Sure to submit your File or Data?'))
       {              
             return false;
       }
       $.showprogress();

}

</script>


So, please help me for this.
Posted

1 solution

use hidden field on page set it's value in validation function and after calling Page.ClientScript.RegisterStartupScript() retrive it from hidenfield
exa.
<asp:HiddenField id="HiddenField1" runat="server" />

XML
<script type="text/javascript">

//in javascript fist check for postback becose it is registered on page load
function validate()
{
var chkPostBack = '<%= Page.IsPostBack ? "true" : "false" %>';
if (chkPostBack == 'true')
 {

       if(!confirm('Are you Sure to submit your File or Data?'))
       {
document.getElementById('<%= HiddenField1.ClientID %>').value=0;
            
       }
       $.showprogress();
}
        else
       document.getElementById('<%= HiddenField1.ClientID %>').value=1;

}

</script>


on code behind retrive it from hiddenfield.But first register fuction using RegisterStartupScript on page
C#
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
             ScriptManager.RegisterStartupScript(this, typeof(string), "alert", "validate();", true);
        }
      
    }
protected void Button1_Click(object sender, EventArgs e)
    {
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "validate();", true);
int result1=Convert.ToInt32(HiddenField1.Value);
}
 
Share this answer
 
v3
Comments
[no name] 25-Feb-13 3:18am    
error of converting int to string
Pallavi Waikar 25-Feb-13 3:26am    
use int result1=Convert.ToInt32(HiddenField1.Value);
[no name] 25-Feb-13 3:30am    
but HiddenField1 not getting value
Pallavi Waikar 25-Feb-13 3:38am    
then ur javascript was not working...this should work..if u want to call $.showprogress(); on true of confirmation then add it in else part...if not then i can help u up to this only...check ur code
[no name] 25-Feb-13 3:39am    
this code is working and i put it inside the button click.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900