|
-
Mar 17th, 2005, 11:12 PM
#1
Thread Starter
Frenzied Member
Custom Postback Class[Check this out]
Friends, Romans, Frogs lend me your ears.
Do you need to load Data based on one page based on an action from another page? Do you need to do some weird JavaScript and then post back? Do you want to use the JavaScript setTimeOut to create a really funky Server Side Timer?
I say unto you no longer shall you fight to be able to raise a custom PostBack Event from your JavaScript. Behold the very short, very ugly, very over rated PostBackEvent.
Simply drop one on your WebForm write your event code and invoke it from JavaScript you write and only JavaScript you write.
Not only that but it is only slightly agrivating at Design Time..........
PHP Code:
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
namespace Controls
{
/// <summary>Provides a quick drop on controless PostBackEvent.</summary>
/// <developer>Zeke Naulty</developer>
/// <createdOn>3/17/05</createdOn>
[Designer(typeof(PostBackEvent.PostBackDesigner), typeof(ControlDesigner))]
public class PostBackEvent : Control, IPostBackEventHandler
{
internal class PostBackDesigner : ControlDesigner
{
public override string GetDesignTimeHtml()
{
PostBackEvent c = null;
if(Component is PostBackEvent) c = (PostBackEvent)Component;
if(c != null) return "<!-- PostBackEvent " + c.ID + "(" + c.UniqueID + ") Purpose: " + c.EventPurpose + " -->";
return null;
}
}
public event EventHandler PostBack;
private string _eventName = "CustomPostBack";
public string EventPurpose
{
get{return _eventName;}
set{if(_eventName != value) _eventName = value;}
}
public PostBackEvent(){}
protected virtual void OnPostBack(EventArgs e){if(PostBack != null) PostBack(this, e);}
public void RaisePostBackEvent(string eventArgument)
{
EventArgs e = new EventArgs();
OnPostBack(e);
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
writer.Write("<!-- PostBackEvent " + this.ID + "(" + this.UniqueID + ") Purpose: " + _eventName + " -->");
}
protected override void OnPreRender(System.EventArgs e)
{
this.Page.GetPostBackClientEvent(this, "");
base.OnPreRender(e);
}
}
}
Last edited by Magiaus; Apr 8th, 2007 at 02:37 PM.
Reason: title change
Magiaus
If I helped give me some points.
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
|