-
December 30th, 2005, 12:28 PM
#1
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?
-
December 30th, 2005, 12:38 PM
#2
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;
-
December 30th, 2005, 02:14 PM
#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.
-
December 30th, 2005, 04:53 PM
#4
Re: function calling problem
add onclick attribute to the client
Code:
//Page_Load
Button.Attributes.Add("onclick","window.close()");
-
December 30th, 2005, 11:04 PM
#5
Re: function calling problem
hey
mehdi62b
its working!!!
Thanks a lot for ur timely help.
regards..
-
December 31st, 2005, 03:11 AM
#6
Re: function calling problem
Adding to what mmetzger said:
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
-
January 2nd, 2006, 06:02 AM
#7
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...
-
January 3rd, 2006, 07:32 AM
#8
Re: function calling problem
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.
-
January 3rd, 2006, 08:07 AM
#9
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
-
January 3rd, 2006, 10:54 AM
#10
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.
-
January 3rd, 2006, 01:51 PM
#11
Re: function calling problem
hey,
Why did you override PreRender function?
-
January 3rd, 2006, 01:55 PM
#12
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|