我目前在每个日期都有一个带有编辑按钮的日历,按下它们后,它们会在URL字段中发送“setReminder = ID”。虽然ID是正确的,但我不知道如何实际“抓住”ID?
情况几乎如下:
目前我有:
<%
var days = DateTime.DaysInMonth(2015, 11);
var month = 11;
var year = 2015;
List<string> dateTimes = new List<string>();
for (int x = 1; x < 8; x++)
{
string dateTime = new DateTime(year, month, x).ToString("dddd") ;
dateTime = dateTime.Replace(dateTime[0], dateTime[0].ToString().ToUpper()[0]);
Response.Write("<div class='days visible-lg-inline-block'> <ul> <li>");
Response.Write(dateTime);
Response.Write("</li> </ul> </div>");
dateTimes.Add(dateTime);
}
for (int i = 1; i < days; i++)
{
Response.Write("<div class='week'>");
Response.Write("<ul>");
Response.Write("<li>");
Response.Write(i);
%>
<a href='WebForm1.aspx?setReminder=<%= i %>'> <img src='editIcon.png' alt='Set reminder' /> </a>
<%
Response.Write("</li>");
Response.Write("</ul>");
Response.Write("</div>");
}
var setReminder = Request["setReminder"];
if(setReminder != null)
{
%>
<h3>Set a reminder/event</h3>
<form method="POST" action="WebForm1.aspx">
<input type="hidden" name="reminderId" value="25" />
Event name: <input type="text" name="reminderName" /> <br />
<button type="submit" name="submitReminder">Set</button> <br />
</form>
<%
}
%>
答案 0 :(得分:0)
如果我弄错了,您需要从网址获取setReminder
的值。
URL中的setReminder
是查询参数,您可以像这样得到它的值 -
在C#中,您可以使用QueryString
class-
HttpRequest
属性
string setReminderValue= Request.QueryString["setReminder"];
如果你需要在Javascript中,你可以这样做
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}