Hi @Ashok Kumar,
According to your needs, I created simple examples to achieve such requirement. Here is the code sample:
Page1:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<div>
<a class="redirectclick" href="page2.aspx">RedirectToPage2</a>
</div>
<script type="text/javascript">
$(document).ready(function () {
//"use strict";
FinalSB();
});
</script>
</asp:Content>
Page 2:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:Label runat="server" ID="MessageLabel" hidden="hidden"></asp:Label>
<script type="text/javascript">
$(document).ready(function () {
//"use strict";
FinalOC();
});
<%--function FinalOC() {
var p = $('#<%= MessageLabel.ClientID %>').text();
alert(p);
}--%>
</script>
</asp:Content>
Page2.aspx.cs
public static string message { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Request.RequestType == "POST")
{
message = Request.Form["Message"];
MessageLabel.Text = message;
}
}
}
[WebMethod]
public static string getMessage() {
return message;
}
custom.js
function FinalOC() {
$.ajax({
url: "page2.aspx/getMessage",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg.d);
}
});
}
function FinalSB() {
$(".redirectclick").on("click", function (e) {
e.preventDefault();
//alert('click');
redirectopage2();
});
}
function redirectopage2() {
post_to_url('page2.aspx',
{
message: "Calling"
}, 'post', '_blank');
}
//Form Submit
function post_to_url(path, params, method, targetOpt) {
method = method || "post";
targetOpt = targetOpt || "_blank";
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("target", targetOpt);
form.setAttribute("action", path);
for (var key in params) {
if (params.hasOwnProperty(key)) {
var input = document.createElement("input");
input.setAttribute("name", key);
input.setAttribute("value", params[key]);
form.appendChild(input);
}
}
document.body.appendChild(form);
form.submit();
}
Result:
The form submission is on the server side, so you can't get the data from the server side from the browser DOM, in this case, you can get it through server controls (e.g. ASP:Label in prevoius example) or Ajax request. On the other hand, as Bruce mentioned, the submitted form does not contain the disaled element.
Best regards,
Xudong Peng
If the answer is the right solution, please click "Accept Answer" and kindly upvote. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.