p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

aspdotnet_website_programming thread: buttonlink removal.


Message #1 by "Lampros Eleftherios" <lampros@c...> on Thu, 23 May 2002 18:54:20 +0300
This is a multi-part message in MIME format.

------=_NextPart_000_0022_01C2028B.3F44AC10
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello,

I had an idea these days. Assume that we have a simlpe <asp:buttonlink)
I created a counter so everytime i click the button the value of the 
counter increases.
For example i click the button once the counter has the value 1. I click 
the button
twice and the counter has the value 2 and so on.

If the value is equal to five (or whatever) i would like to change the 
link to PLAIN TEXT.
Do you have any ideas how this change from a link to plain text could be 
implemented.

Thank you in advanced.

Terry



Message #2 by Feduke Cntr Charles R <FedukeCR@m...> on Tue, 28 May 2002 09:58:22 -0400
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C2064F.BA87F310
Content-Type: text/plain;
	charset="iso-8859-1"

Terry,
 
    Alright, I did up an example on how to do what you were asking.  This is
a very rough example with no real concerns for security; i.e. a person could
still look at the source code and use a custom client to execute a post
because the <a> tags are still written, just not made active.  Additionally
you may have to track the clicks on a per-LinkCountButton in Session rather
than ViewState because leaving the page and returning nullifies the
ViewState data.  I will post this example to the list so it is archived for
searches as well.
 
    To use this, make a page and do something similiar to the following:
 
Test.aspx:
 
<%@ Page language="c#" 
    Codebehind="Test.aspx.cs" 
    AutoEventWireup="false" 
    Inherits="Whatever.Testing.Test" 
    Trace="true" %>
<%@ Register TagPrefix="CT" 
    Namespace="CreativeTechnology.Web.UI.WebControls" 
    Assembly="YourAssembly" %>
<form runat="server">
 <CT:LinkCountButton Text="This is a test." RunAt="server" OnClick="Click"
Id="counter" />
</form>

 
    Below is the code of LinkCountButton.cs.
 
using System;
using System.Web.UI.WebControls;
/// <author>Charles Feduke</author>
namespace CreativeTechnology.Web.UI.WebControls
{
 /// <summary>
 /// Becomes plain text after a certain number of clicks.
 /// </summary>
 public class LinkCountButton : LinkButton
 {
  #region Member Variables
  private int _count = 0;
  private int _maxCount = 5;
  #endregion
 
  #region Constructors
  /// <summary>
  /// Creates a new instance of the LinkCountButton.
  /// </summary>
  public LinkCountButton() { }
  #endregion
 
  #region Properties
  /// <summary>
  /// Retrieves the current click count.
  /// </summary>
  public int Count
  {
   get { return _count; }
  }
 
  /// <summary>
  /// Sets or retrieves the maximum number of clicks before a redirect
should occur.
  /// </summary>
  public int MaxCount
  {
   get { return _maxCount; }
   set { _maxCount = value; }
  }
  #endregion
 
  #region Methods
  /// <summary>
  /// Handles incrementing the counter on a click.
  /// </summary>
  /// <param name="e"></param>
  private void OnClick(Object sender, EventArgs e)
  {
   _count++;
  }
 
  /// <summary>
  /// Saves the current count to the view state stream.
  /// </summary>
  protected override object SaveViewState()
  {
   return (object)_count;
  }
 
  /// <summary>
  /// Loads the current count from teh view state stream.
  /// </summary>
  protected override void LoadViewState(object savedState)
  {
   _count = (int)savedState;
  }
 
  #endregion
 
  #region Events
  /// <summary>
  /// Occurs when the link button is initialized.
  /// </summary>
  protected override void OnInit(System.EventArgs e)
  {
   // add our click method to the OnClick chain of events
   this.Click += new EventHandler(OnClick);
  }
 
  /// <summary>
  /// This is nasty, but a necessary evil (or would you prefer to rewrite 
  /// the entire RenderContents method?).
  /// </summary>
  public override void RenderBeginTag(System.Web.UI.HtmlTextWriter writer)
  {
   base.RenderBeginTag(writer);
   if (_count == _maxCount)
    writer.Write("</a>");
  }
 
  /// <summary>
  /// Nasty and insecure!
  /// </summary>
  public override void RenderEndTag(System.Web.UI.HtmlTextWriter writer)
  {
   if (_count == _maxCount)
    writer.Write("<a>");
   base.RenderEndTag(writer);
  }
 
  #endregion
 }
}
 
    Please note that the above code is in no way, shape, or form affiliated
with my employer, Creative Technology, Inc.  I use the namespace here for
ease of use in my current project.
 
HTH,
- Chuck


-----Original Message-----
From: Lampros Eleftherios [mailto:lampros@c...]
Sent: Friday, May 24, 2002 12:10 PM
To: Feduke Cntr Charles R
Subject: 



Hello, 
first of all i had to apologise for sending this email private to you, but
i am watching the list and i am counting to ypur opinion and knowledge.
I had a problem these days expreced in the next email:
----------------------------------------------------------------------------
--------------
Hello,
 
I had an idea these days. Assume that we have a simlpe <asp:buttonlink)
I created a counter so everytime i click the button the value of the counter
increases.
For example i click the button once the counter has the value 1. I click the
button 
twice and the counter has the value 2 and so on. 
 
If the value is equal to five (or whatever) i would like to change the link
to PLAIN TEXT.
Do you have any ideas how this change from a link to plain text could be
implemented.
 
Thank you in advanced.
 
Terry    
----------------------------------------------------------------------------
-----------------
 
Do you have any idea how this could be done?
 
Thanx, and sorry again for sending the email specifically to you



  Return to Index