Elatesummer Elatesummer - 1 year ago 57
Vb.net Question

how to add an event handler to a control from a modal popup?

I'm programming in visual basic for the first time, and using AJAX - I've done this before but a couple of years ago and I'm very stuck! I have searched for topics but they all assume a knowledge of the framework which I think I'm missing. Any help is very much appreciated.

Here's my markup:

<%@ Page Title="Report Execution" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
CodeBehind="reportExecution.aspx.vb" Inherits="RDMI.reportExecution" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
Report Execution
Welcome to the RDMI Report Execution page. Please select from the following reports:
<asp:Panel ID="panelReports" runat="server" Height="216px">
<asp:Button ID="btnRDMI520" runat="server" Text="Inspection Outcomes Report"
BackColor="#D8D9DB" Font-Bold="True" ForeColor="#00539F" />
<asp:modalpopupextender id="RDMI520_popup" runat="server" cancelcontrolid="btnNo"
targetcontrolid="btnRDMI520" popupcontrolid="popupPanel"
popupdraghandlecontrolid="popupHeader" drag="true" backgroundcssclass="backgroundPopup" OkControlID="btnYes" />
<span id="statusSpan" class="status"></span><br />
<asp:Panel ID="popupPanel" style="display: none" runat="server">
<div class="comparisonPopup">
<div class="comparisonPopupHeader" id="popupHeader"
style="font-size: 20px; font-weight: bold; color: #D8D9DB; background-color: #00539F" >Execute Report
<div class="popupBody" style="font-size=16px; font-weight=bold;">
<p>Would you like run this report with a comparison?</p>
<div class="Controls">
<input id="btnYes" type="button" value="Yes" onclick="btnYes_Click"/>
<input id="btnNo" type="button" value="No" onclick="btnNo_Click"/>

And so I want to add an event handler to the onclick events of the buttons which are in my popup box. I know I've done this before but I can't find my old code or remember how. If I need to plug in javascript to do this, any pointers to articles would be much appreciated as I'm at my wits end here!

Obviously I have tried the obvious -

Protected Sub btnYes_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnYes.Click
End Sub

This says that the 'Handles clause requires a WithEvents variable defined in the containing type or one of its base types.'

Any assistance gratefully received and I will mark as answer if successful.

Answer Source

You need to use jQuery ajax which is used to call page methods from view e.g

          type: "POST",
            url: "PageName.aspx/MethodName",
            data: "{}",
               contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                  // Do something interesting here.

Above code should be embedded in btn.click function of javascript.

Moreover search on google you will easily find many articles on using jQuery ajax.

Thanks and regards,

Nitin D. Varpe