Reputation: 31437
Default.aspx
<script type="text/javascript">
$(function() {
$("#add_questions").click(function() {
var question = $("#wmd-output").val();
var option1 = $("#option1").val();
var option2 = $("#option2").val();
var option3 = $("#option3").val();
var option4 = $("#option4").val();
var answer = $("#answer").val();
var paper = $("#txt_subject_id").val();
var dataString = 'question='+ question +'&option1='+option1 +'&option2='+option2 +'&option3='+option3 +'&option4='+option4 +'&answer='+answer+'&paper='+paper;
$("#flash").show();
$("#flash").fadeIn(400).html('<img src="../images/validate.gif" align="absmiddle">');
//alert(dataString)
$.ajax({
type: "GET",
url: "Default2.aspx",
data: dataString,
cache: false,
success: function(html){
$("#display").after(html);
//alert(html)
//document.getElementById('content').value='';
//document.getElementById('content').focus();
$("#flash").hide();
}
});
return false;
});
});
</script>
Let
dataString="question=p>hello</p>&option1=option1&option2=option2&option3=option3&option4=option4&answer=answer&paper=paper"
How could I pass this query string to next page using jquery? I didn't get response from the next page, which means the question=<p>hello</p>
not getting the value.
Default2.aspx
Dim question As String
question = Request.QueryString("question")
Response.Write(question)
I also tried encodeUri
and encodeURIcomponent
.
Upvotes: 2
Views: 4785
Reputation: 31437
First of all thanks to everyone for their effort.
This is what i did
question=encodeURIComponent(question)
var dataString = 'question='+ encodeURIComponent(question) +'&option1='+ option1 +'&option2='+ option2 +'&option3='+ option3 +'&option4='+ option4 +'&answer='+ answer +'&paper='+ paper;
I have used encodeURIComponent
twice and while decoding at the server side
quest = Server.UrlDecode(question)
display the correct value.
Thanks again for help !!
Upvotes: 1
Reputation: 66649
You say that you try the encodeURIcomponent
but I am afraid that you apply it on the full line. You must apply the encodeURIcomponent
to each value alone to make it work as:
var dataString = 'question='+ encodeURIcomponent(question) +'&option1='+
encodeURIcomponent(option1) +'&option2='+ encodeURIcomponent(option2) +'&option3='+
encodeURIcomponent(option3) +'&option4='+ encodeURIcomponent(option4) +'&answer='+
encodeURIcomponent(answer)+'&paper='+ encodeURIcomponent(paper);
Also, do you have check that you read the values from var question = $("#wmd-output").val();
? is the "#wmd-output"
the correct one or you need to add the rendered client id ?
Upvotes: 2
Reputation: 2742
I am afraid you can't pass HTML via querystring. You can use Session instead. You can store HTML in a string variable and store it in Session. On next page, you can retrieve it from Session.
Session.Add("myHTML","<p></p>");
On next page load
String html = Session["myHTML"].ToString();
Upvotes: -2