下面是使用jQuery和ASPNET控件的示例。它從TextBox1中取值並將其發送到處理程序。然後處理程序發送另一個值並將其放入TextBox1中。您可能需要根據您的具體情況進行調整。
處理程序代碼
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//check if the querystring with the token exists
if (context.Request.QueryString["token"] != null)
{
//get the old token from the querystring (and do stuff with it)
string oldToken = context.Request.QueryString["token"];
//check if oldToken contains a value
if (string.IsNullOrEmpty(oldToken))
{
return;
}
//generate a new token
string newToken = Guid.NewGuid().ToString();
//send it to the browser
context.Response.Write(newToken);
}
}
的ASPX
<asp:TextBox ID="TextBox1" runat="server" Width="250"></asp:TextBox>
<br /><br />
<asp:Button ID="Button1" runat="server" Text="Get Set Token" UseSubmitBehavior="false" OnClientClick="getSetData(); return;" />
<script type="text/javascript">
function getSetData() {
var control = "#<%= TextBox1.ClientID %>";
var oldToken = $(control).val();
$.get("/TokenHandler.ashx?token=" + oldToken, function (newToken) {
$(control).val(newToken);
});
}
</script>
嗯......什麼是你想?對ashx和一個頁面的調用是兩個不同的請求。你也許可以通過'''context.Response.Redirect(newUrl)在ProcessRequest中重定向你的調用。 '''並傳遞一個URL參數... –
我需要在我的母版頁的輸入文本中存儲一個標記 –