Call a function on another page

Last post 05-16-2008 12:10 AM by Ivan Xin - MSFT. 8 replies.

Sort Posts:

  • Call a function on another page

    05-13-2008, 11:59 PM
    • Loading...
    • abupapa
    • Joined on 10-13-2006, 3:17 AM
    • Posts 203

    Hello,

    Currently I use window.showModalDialog on page1.aspx to call another page, editremarks.aspx. When users click on the button on editremarks.aspx and the information gets saved the editremarks.aspx is closed using javascript. Upon closing, I want to call another function on the page1.aspx. I wonder whether this is possible?

    Thanks

    Sincerely Yours,
    Abupapa
  • Re: Call a function on another page

    05-14-2008, 12:40 AM
    • Loading...
    • Avinash Desai
    • Joined on 01-23-2008, 9:24 AM
    • Bangalore-INDIA
    • Posts 717

    Hi

    What you are saying is Possible and you can call the Function after the Java script 

    Thanks
    ~Avinash desai~
    Software Developer
    Bangalore

    Please remember to click "Mark as Answer" on this post if it helped you.
  • Re: Call a function on another page

    05-14-2008, 12:46 AM

    http://www.codeproject.com/KB/scripting/share_parent_childorpopup.aspx 

    I compete with myself to motivate me!!

    Do not forget to mark posts, that help you, as "Answer".
  • Re: Call a function on another page

    05-14-2008, 1:04 AM
    • Loading...
    • abupapa
    • Joined on 10-13-2006, 3:17 AM
    • Posts 203

    enableDeepak:

    http://www.codeproject.com/KB/scripting/share_parent_childorpopup.aspx 

     Hi,

    The function that I want to call is in a code behind. Not a javascript function that was shown in your given example. May I know whether this is achievable?

    Anyway here's my code:

     

    page1.aspx

    private void btnRemarks_Click(object sender, System.EventArgs e)

    {

    String nric =
    null;

    String jScript;

    jScript="<script>window.showModalDialog('editremarks.aspx?activation_id=' + '"+this.tbxActivationID.Text+"&nric=' + '"+this.tbxNricNo.Text+"');</script>";

    Page.RegisterClientScriptBlock("clientScriptBlock",jScript);

    this.GetPersonnelList(int.Parse(this.tbxPageNo.Text),int.Parse(this.ddlFilterOptions.SelectedValue),this.tbxKeyWord.Text);

     

    }

    editremarks.aspx

    private void btnSave_Click(object sender, System.EventArgs e)

    {

     

     

    string jScript;

    jScript="<script>successSave();</script>";

    Page.RegisterClientScriptBlock("keyClientBlock",jScript);

    }

    After the successSave(); function is executed, the editremarks.aspx will close. Upon closing, I want to call GetPersonnelList function in page1.aspx. How do I go about achieving this?

    Thanks for the help.

    Sincerely Yours,
    Abupapa
  • Re: Call a function on another page

    05-14-2008, 1:12 AM
    • Loading...
    • Avinash Desai
    • Joined on 01-23-2008, 9:24 AM
    • Bangalore-INDIA
    • Posts 717

    Hi

    abupapa after close code it will not close the  Form it will remain upto Closing Bracket } and before that i.,e after your

    abupapa:
    private void btnSave_Click(object sender, System.EventArgs e)

    {

    string jScript;

    jScript="<script>successSave();</script>";

    Page.RegisterClientScriptBlock("keyClientBlock",jScript);

     

    Code above you  can Call the Function

    Thanks
    ~Avinash desai~
    Software Developer
    Bangalore

    Please remember to click "Mark as Answer" on this post if it helped you.
  • Re: Call a function on another page

    05-15-2008, 9:49 PM

    Hi abupapa,

           Based on my knowledge, from the programming aspect of view, I don't think what you want is achieveable. Because object of page1.aspx and editrmrks.aspx don't exist the same time at the server side. So you can't call some function that just dont exist. But a work around would be creating a class at the App_code folder, this way every page of your application can call the member function of the class in that folder.

    Regards,

    Ivan.

  • Re: Call a function on another page

    05-15-2008, 11:38 PM
    • Loading...
    • abupapa
    • Joined on 10-13-2006, 3:17 AM
    • Posts 203

    Ivan Xin - MSFT:

    Hi abupapa,

           Based on my knowledge, from the programming aspect of view, I don't think what you want is achieveable. Because object of page1.aspx and editrmrks.aspx don't exist the same time at the server side. So you can't call some function that just dont exist. But a work around would be creating a class at the App_code folder, this way every page of your application can call the member function of the class in that folder.

    Regards,

    Ivan.

     

    Ivan,

    Thanks for your reply. But I don't really get what you mean. Do you have some samples?

    Sincerely Yours,
    Abupapa
  • Re: Call a function on another page

    05-16-2008, 12:07 AM
    Answer

    Hi abupapa,

         Here is a demo about using a class written inside the App_Code folder.

    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server" defaultbutton ="LinkButton1">
        <div>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>&nbsp+&nbsp<asp:TextBox ID="TextBox2"
                runat="server"></asp:TextBox>&nbsp=&nbsp<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
            <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Add</asp:LinkButton>
            <asp:CompareValidator ID="CompareValidator1" runat="server" Operator ="DataTypeCheck" Type="Integer" ControlToValidate ="TextBox1" Display ="None"   ErrorMessage="Only integer value allowed"></asp:CompareValidator>
            <asp:CompareValidator ID="CompareValidator2" runat="server" Operator ="DataTypeCheck" Type="Integer" ControlToValidate="TextBox2" Display ="None"  ErrorMessage="Only integer value allowed"></asp:CompareValidator>
            <asp:ValidationSummary ID="ValidationSummary1" DisplayMode="List" runat="server" />
        </div>
        </form>
    </body>
    </html>

    -----------App_Code/calculator.cs

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    /// <summary>
    /// Summary description for calculator
    /// </summary>
    public class calculator
    {
     public calculator()
     {
      //
      // TODO: Add constructor logic here
      //
           
     }
        public static string Add(string input1, string input2)
        {
            int result = (int.Parse(input1) + int.Parse(input2));
            return result.ToString();
        }
        public static int Add(int input1,int input2)
        {
            return input1+input2;
        }
        public static int Minus(string input1, string input2)
        {
            //To Do
        }
    }

    ------------------default.aspx.cs---------------------------

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void LinkButton1_Click(object sender, EventArgs e)
        {

            Label1.Text = calculator.Add(TextBox1.Text, TextBox2.Text);
           
        }
    }

    Regards,

    Ivan.


     

  • Re: Call a function on another page

    05-16-2008, 12:10 AM
    Answer

    As the previous post's example, I think you can write some static member functions if insist using a page class to do your job. Because using static member function of a class don't require to initialize an instance of that class.

    Regards,

    Ivan.

Page 1 of 1 (9 items)
Microsoft Communities
Page view counter