如何使用C#在ASP中动态添加的输入按钮上添加操作 [英] how to add action on dynamically added input button in asp using c#

查看:37
本文介绍了如何使用C#在ASP中动态添加的输入按钮上添加操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我想在单击输入按钮时调用方法.输入按钮是动态创建的.输入按钮是使用.aspx文件中的response.write()创建的.我们编写的代码如下:


In my application i want to call method on clicking of input button.the input button is created dynamically.The input button is created using response.write() in .aspx file.The code written by us is as follows:


<body bgcolor="silver">
        <form id="form1" runat="server">
       <div>
            <%   string AdminId = Request.Params.Get("AdminId");
                string FirstName,LastName,EmailId,ClassName,FacultyName;
                 SqlConnection objsqlconnection = new SqlConnection();
                 objsqlconnection.ConnectionString = ("Data Source=.\\SQLEXPRESS;AttachDbFilename=G:\\Ujwala\\Project\\Student Community\\Student_Community\\Student_Community\\App_Data\\Stud_Community.mdf;Integrated Security=True;User Instance=True");
                 SqlCommand objsqlcommand = objsqlconnection.CreateCommand();
                 objsqlconnection.Open();
                 string SelectStudInfo = "SELECT tblStudent_Registration.FirstName, tblStudent_Registration.LastName,tblStudent_Registration.EmailId,tblClass_Info.ClassName,tblFaculty_Info.FacultyName FROM tblRequestApprove INNER JOIN tblStudent_Registration ON tblRequestApprove.StudId = tblStudent_Registration.StudId INNER JOIN tblClass_Info ON tblStudent_Registration.ClassId = tblClass_Info.ClassId INNER JOIN tblFaculty_Info ON tblStudent_Registration.FacultyId = tblFaculty_Info.FacultyId WHERE (tblRequestApprove.AdminId ='"+AdminId+"')";
                 objsqlcommand = objsqlconnection.CreateCommand();
                 objsqlcommand.CommandText = SelectStudInfo;
                 SqlDataAdapter sqldataadapter = new SqlDataAdapter(objsqlcommand);
                 DataTable datatable = new DataTable();
                 sqldataadapter.Fill(datatable);
                 int i = 0;
                 Response.Write("<b><font face='roman' size=3 color='red'>");
                 Response.Write("<Table border='1' height=40 width=800><tr><th>Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th>EmailId&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th>ClassName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th>FacultyName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th></tr></Table><br>");
                 Response.Write("</b></font>");
                 foreach (DataRow row in datatable.Rows)
                 {

                     FirstName = datatable.Rows[i]["FirstName"].ToString();
                     LastName = datatable.Rows[i]["LastName"].ToString();
                     EmailId = datatable.Rows[i]["EmailId"].ToString();
                     ClassName = datatable.Rows[i]["ClassName"].ToString();
                     FacultyName = datatable.Rows[i]["FacultyName"].ToString();
                     Response.Write("<table border='1' height=60 width=800><tr><td>");
                     Response.Write("<a href='DisplayStudInfo.aspx?AdminId="+AdminId+"&EmailId="+EmailId+"'><b><font color='blue'>" + FirstName + "" + LastName + "</font></b></a>");
                     Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                     Response.Write("<b><font size=4 color='black'>");
                     Response.Write(EmailId);
                     Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                     Response.Write(ClassName);
                     Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                     Response.Write(FacultyName);

                     Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                     Response.Write("<form><input type='Button' value='Approve' name='BtnSubmit' nbsp;&nbsp;<input type='Button' value='Reject' name='BtnReject' /form>");
                     Response.Write("</b></font>");
                     Response.Write("</td></tr></table>");
                     Response.Write("<br>");
                    i++;
                 }
                objsqlconnection.Close();
               %>
        </div>
        </form>
    </body>





我想在单击输入提交按钮时执行方法.
我该如何实现?请帮助我.
谢谢.





I want to execute method on click of input submit button.
How can I achieve this?Please help me.
Thanks.

推荐答案



您必须提供form action属性才能激活输入操作.


试试看.它可以为您服务.


一切顺利
Hi,

You''ve to give form action property to activate input action .


try that.It can works for you.


All the best



这篇关于如何使用C#在ASP中动态添加的输入按钮上添加操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆