การเรียกใช้ Control object ของ Masterpage ใน Class

การเรียกใช้ Control object ของ MasterPage ใน Class เช่นตัวอย่างการทำ Popup Status ในหน้า Master Page และทำการเรียกใช้งานผ่าน Class โดยจะต้องอ้างอิงถึง Control ในหน้า MasterPage ด้วย

 

ControlPopup1

1. เริ่มจากวาง Control object ลงใน MasterPage ในส่วนของ <form></form>

<dx:ASPxPopupControl ID="ASPxPopupControl1" runat="server" CloseAction="CloseButton"  Modal="True"
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter" ClientInstanceName="pcStatus"
        HeaderText="ข้อความแจ้งเตือน" AllowDragging="True"  PopupAnimationType="None" EnableViewState="False" Height="120px" Theme="SoftOrange" Width="550px"><ContentCollection>
<dx:PopupControlContentControl runat="server" >
    <table style="width:100%">
        <tr><td class="txtStatus">
            <%=Session["ssStatus"] %>
            </td></tr>

    </table>
    
</dx:PopupControlContentControl>
</ContentCollection>
        </dx:ASPxPopupControl>

2. สร้างไฟล์ class ตั้งชื่ออะไรก็ได้แล้วแอดโค้ดไป

  public void ShowStatus(String messageStatus)
    {
        Page currentPage = (Page)HttpContext.Current.Handler;
        ASPxPopupControl ASPxPopupControl1 =
       (ASPxPopupControl)((MasterPage)currentPage.Master).FindControl("ASPxPopupControl1");
        HttpContext.Current.Session["ssStatus"] = messageStatus;
        ASPxPopupControl1.ShowOnPageLoad = true;
    }

สังเกตุว่ามีการใช้ Page เพื่อทำการเรียก MasterPage หลังจากนั้นจะใช้ Session ใน Class รับค่า Text เพื่อไปแสดงบน Popup ใน MasterPage ด้วย ในบทความนี้จะใช้ Popup Control ของ DevExpress ด้วย

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.