CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Apr 2005
    Posts
    54

    function calling problem

    Hi,
    i m trying to close web form by creating
    function fclose()
    {
    window.close ;
    }
    and calling this function by
    <asp:Button id="Button2" runat="server" Text="cancel" OnClick = "fclose()"></asp:Button>

    but somehow its giving compilation error as
    'fclose' is not a member of 'ASP.WebForm1_aspx'.
    pls tell me how to solve this problem?

  2. #2
    Join Date
    Apr 2002
    Location
    PA, USA
    Posts
    1,658

    Re: function calling problem

    1) by default your function is private 2) it looks like you're mixing and matching VB and C# code.

    Here is a C# example
    Code:
    public void fclose()
    {
    // your code
    }
    I have no clue what window.close does in this case, but chances are it's a function and not a property so you'd want window.close(); and not window.close;
    =--=--=--=--=--=--=--=--=--=--=--=--=--=
    Please rate this post to show your appreciation for those that helped you.

    Before You Post A Question, Please Read This: How & When To Ask Your Question
    =--=--=--=--=--=--=--=--=--=--=--=--=--=

    -eli
    http://www.toad-software.com
    http://www.dailymission.com - Do It Daily

  3. #3

    Re: function calling problem

    You can't call a client side script directly with an asp.net button. Either switch the button type to a standard input button or add the javascript as a client side attribute.

  4. #4
    Join Date
    Sep 2004
    Location
    Tehran(Ir)
    Posts
    469

    Re: function calling problem

    add onclick attribute to the client
    Code:
    //Page_Load
    Button.Attributes.Add("onclick","window.close()");

  5. #5
    Join Date
    Apr 2005
    Posts
    54

    Re: function calling problem

    hey
    mehdi62b

    its working!!!
    Thanks a lot for ur timely help.
    regards..

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: function calling problem

    Adding to what mmetzger said:
    Quote Originally Posted by mmetzger
    You can't call a client side script directly with an asp.net button. Either switch the button type to a standard input button or add the javascript as a client side attribute.
    Here's a nice example

  7. #7
    Join Date
    Apr 2005
    Posts
    54

    Re: function calling problem

    but i think the onclientclick is only available for .net ver 2 but i have 1.1

    so that attribute not working here...

  8. #8
    Join Date
    Sep 2004
    Location
    Tehran(Ir)
    Posts
    469

    Re: function calling problem

    Quote Originally Posted by swapcode
    but i think the onclientclick is only available for .net ver 2 but i have 1.1
    it doesn't relate to .NET,it is a javascript attribute.
    onclientclick? not heard that befor,I think you meant onclick attribute.

  9. #9
    Join Date
    Apr 2002
    Location
    PA, USA
    Posts
    1,658

    Re: function calling problem

    OnClientClick is a .NET 2.0 attribute because OnClick relates to .NET functions with ASP.NET controls, whereas with a normal HTML control onclick relates to a javascript call.

    The .NET 2.0 solution: have OnClick work like OnClick in 1.0 (.NET related) and add the OnClientClick attribute which will relate back to a javascript onClick event. No more having to use the .Attributes.Add() method mentioned above, everybody wins
    =--=--=--=--=--=--=--=--=--=--=--=--=--=
    Please rate this post to show your appreciation for those that helped you.

    Before You Post A Question, Please Read This: How & When To Ask Your Question
    =--=--=--=--=--=--=--=--=--=--=--=--=--=

    -eli
    http://www.toad-software.com
    http://www.dailymission.com - Do It Daily

  10. #10
    Join Date
    Sep 2004
    Location
    Tehran(Ir)
    Posts
    469

    Re: function calling problem

    oh yeah, .NET 2 makes things simpler for developers
    another way..
    Code:
    public class ButtonClosing:System.Web.UI.WebControls.Button
     {
      protected override void OnPreRender(EventArgs e)
      {
       base.OnPreRender(e);
       this.Attributes["onclick"]="window.close()";
      }
     }
    .
    Last edited by mehdi62b; January 3rd, 2006 at 01:57 PM.

  11. #11
    Join Date
    Sep 2005
    Posts
    9

    Re: function calling problem

    hey,
    Why did you override PreRender function?

  12. #12
    Join Date
    Sep 2004
    Location
    Tehran(Ir)
    Posts
    469

    Re: function calling problem

    hey,
    Why did you override PreRender function?
    well,because the order of events is,
    init,load,[other events],prerender,unload which ulnload would be fired off after loading the page with no affect...so prerender is the best place for adding the attribute.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured