Click here to Skip to main content
12,358,497 members (61,508 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# WebForms
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 24-Feb-13 20:18pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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" />
<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
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);
}
  Permalink  
v3
Comments
Mittu Machhi 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);
Mittu Machhi 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
Mittu Machhi 25-Feb-13 3:39am
   
this code is working and i put it inside the button click.
Pallavi Waikar 25-Feb-13 4:11am
   
then why dont u call validate fuction on OnClientClick event of button.
exampal....<asp:Button runat="server" ID="btnSubmit" OnClientClick="return Valiadate()"
onclick="btnSubmit_Click" Text="Submit" />
and use javascript as it is which ur mentioned in ur question
Pallavi Waikar 25-Feb-13 8:19am
   
also check out updated answer

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160621.1 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100