开发者

asp.net custom buttons

开发者 https://www.devze.com 2023-02-09 13:02 出处:网络
Button Layout I have 3 labels inside of a div. I want to make the div clickable and trigger a postback from clicking the div. In essensce I want to make a custom button that looks like the picture

Button Layout

asp.net custom buttons

I have 3 labels inside of a div. I want to make the div clickable and trigger a postback from clicking the div. In essensce I want to make a custom button that looks like the picture. So far the only way I found out of doing this is either having the div onclick event trigger javascript, or do some custom usercontrol magic, which i cant get to work.

User Control

<div class="meetingContainer" >
    <div class="meetingCityState">
      <asp:Label ID="lblMeetingCityState" runat="server" Text='<%# Eval("City") %>'></asp:Label>
    </div>
    <div>
      <asp:Label ID="lblMeetingDate" runat="server" Text='<%# Eval("MeetingDate") %>'></asp:Label>
    </div>
    <div>
      <asp:Label ID="lblMeetingSite" runat='server' Text='<%# Eval("Location") %>'></asp:Label>
    </div>
  </div>

code behind

<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Partial Public Class MeetingButton
  Inherits System.Web.UI.UserControl
  Implements System.Web.UI.IPostBackEventHandler

  Public Event Click As EventHandler

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

  End Sub

  Protected Overridable Sub OnClick(ByVal E As EventArgs)
    RaiseEvent Click(Me, E)
  End Sub

  Public Sub RaisePostBackEvent(ByVal eventArgument As String) _
         Implements IPostBackEventHandler.RaisePostBackEvent

    OnClick(New EventArgs())
 开发者_JAVA百科 End Sub
End Class


Yes, you can do this, using the __doPostBack method. You can create a custom reference to this from the server using this method: http://msdn.microsoft.com/en-us/library/ms153112(v=vs.80).aspx.

Otherwise, you can manually create it by passing it this:

<div id="<Server control's Client ID>" name="<Server control's Unique ID>" onclick="__doPostBack('<unique name>', '<command name and args>');">

On the server, check the following collection for the event:

string target = Request.Form["__EVENTTARGET"];
if (target != null && target.EndsWith("<id>"))
{
   // do this
}

You need to math the __doPostBack unique name to the UniqueID property of the user control.
This would automatically invoke the method defined by the IPostBackEventHandler; any control that implements this interface has its RaisePostBackEvent method called... however, I'm not 100% sure it works the same way for user controls...


looks link an asp:linkbutton will do what I need thaank you

0

精彩评论

暂无评论...
验证码 换一张
取 消