Click here to Skip to main content
15,885,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am working on a requirement where we have to create a UI on the .ashx file which includes buttons.
I was able to add the button but the onClick is not getting triggered.Below is the code of the .Ashx file.Please help!

XML
<%@ Assembly Name="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ WebHandler Language="C#" Class="SPHandler" %>

using System;
using System.Web;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls ;
using Microsoft.SharePoint;
using System.Drawing;

public partial class SPHandler:  IHttpHandler
    {
        //private Button btnaccept;

        public void ProcessRequest(HttpContext context)
        {

            //Panel p = new Panel();
            //Label lblmessage = new Label();
            //lblmessage.Text = "This is from Handler";
            // btnaccept = new Button();
            //btnaccept.Text = "Accept";
            //btnaccept.Click += new System.EventHandler(this.btnaccept_Click);
            //p.Controls.Add(lblmessage);
            //p.Controls.Add(btnaccept);
            //StringWriter sw = new StringWriter();
            //HtmlTextWriter writer = new HtmlTextWriter(sw);
            //p.RenderControl(writer);
            //context.Response.Write(sw.ToString());


            ManageForm(context);

        }

        //public void btnaccept_Click(object sender, EventArgs e)
        //{
        ////HttpContext.Current.("This from the Accept button click event");
        //}


        public void ManageForm(HttpContext context)
        {
             context.Response.Write("<html><body><form Method='Link'Action='http://yahoo.com'>");
            context.Response.Write( "<input type=button value='Accept' >");
            
            context.Response.Write(""); 
            context.Response.Write("</form></body></html>");
        }

        public bool IsReusable
        {
            get
            {
                return true;
            }
        }
}
Posted

1 solution

I can see some problems in your current code like below...

You have not written any code inside the button like onClick="btnaccept_Click".

And the below code will be executed only for one server side control with an runat="server"
C#
public void btnaccept_Click(object sender, EventArgs e)
{
    HttpContext.Current.("This from the Accept button click event");
}

, whereas your button is one client-side html control like...
HTML
<input type="button" value="Accept"></input>


That's why your event is not firing.

Two solutions can be possible
-------------------------------
1. Try adding one onclick event handler code to the html control and write that event is javaScript.
2. Add one server side button control instead of html control and define event for that.

Good luck...
Thanks...
 
Share this answer
 
Comments
Dylan Morley 22-Oct-12 5:54am    
Moved comment from OP:

Thank you for the replay Tadit Dash.I shall try that and check.
Thanks Dylan...
Hi Vanitha,

Please accept this answer, if it has helped you in any way.
This will help others to find the answer in one go and you will also be awarded with some points for this action...

Thanks,
Tadit

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900