当我点击它并在我的活动中将其用作参数时,我想用C#语言获取我输入的Id。
<input type="submit" id="btn1" value ="Some Text" runat="server" onserverclick="btnClick" />
我已经搜索了很长时间寻找解决方案。
protected void btnClick(object sender, EventArgs e)
{
// some code which use input id
}
答案 0 :(得分:2)
您的按钮已作为参数sender
传递。只需投下并进入酒店。
<input type="submit" id="btn1" value="Some Text" runat="server" onserverclick="btnClick" />
protected void btnClick(object sender, EventArgs e)
{
var id = ((System.Web.UI.HtmlControls.HtmlInputSubmit)sender).ID;
// 'id' now contains the value "btn1"
}
答案 1 :(得分:0)
将runat服务器添加到您的输入中,然后您就可以从 iCalendar iCal = new iCalendar();
Event evt = iCal.Create<Event>();
DateTime dt = (DateTime)Convert.ToDateTime(lblTicketDue.Text);
Console.Write(dt);
evt.Start = new iCalDateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second);
evt.End = new iCalDateTime((DateTime)Convert.ToDateTime(lblTicketDue.Text).AddMinutes(15.0));
Alarm alarm = new Alarm();
alarm.Action = AlarmAction.Display;
alarm.Summary = "Ticket due!";
Trigger t = new Trigger();
iCalDateTime icdt = new iCalDateTime(dt.Subtract(TimeSpan.FromMinutes(120.0)));
t.DateTime = icdt;
alarm.Trigger = t;
evt.Alarms.Add(alarm);
iCal.Events.Add(evt);
iCalendarSerializer serializer = new iCalendarSerializer();
string output = serializer.SerializeToString(iCal);
Response.ContentType = "text/calendar";
Response.Write(output);
Response.End();
后面的代码中访问它了
我建议使用aspx控件:
var blah = btn1.Id;