Reputation:
I'm developing something similar to the system console, but which renders with simple HTML-page.
Here are the codes:
Code is rather in test state and I don't want to mention about code-style etc... I know this problem.
I'm confused a little with the AJAX calls of my WebForms project. So let me to describe, what I'm trying to do:
First of all, I'm catching a key event Enter
, when user has finished entering the text into <textarea>
.
Then I'm reading the text secondly, which user has added and send it via XmlHttp
object to this page (postback action, because I'm sending POST HTTP queries to the same web page)
At the third action, I analyse the string data and render the response in consoleOutput
finally by setting the response with the CheckGetData()/GetDirectories() methods in the CodeBehind.
But, finally nothing is happen... The most strangest things for me, are:
IsPostBack
value when XmlHttp has sent GET query at debug time, it would be false
, why? As by the definition of postback, it's a such type of recursive HTTP query to the same web page (making POST queries from the web page to itself)So, the final question is: why do it call a bug and how to fix it?
Upvotes: 0
Views: 610
Reputation: 18008
Not a direct answer, just a suggestion of how you can achieve.
Use an UpdatePanel
. Here is how you can achieve(bare minimum; a bit hacky):
Script:
<script>
function keyPressed(e) {
var code;
if (window.event) {
//IE
code = e.keyCode;
}
else {
//other browsers
code = e.which;
}
//check, for example, if the Enter key was pressed (code 13)
if (code == 13) {
//Enter key pressed
document.getElementById("<%= btnPostback.ClientID %>").click();
}
else {
//Another key pressed
}
}
</script>
aspx markup:
<textarea id="consoleBody" rows="30" cols="30" runat="server" onkeypress="javascript:keyPressed(event);" />
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnPostback" EventName="Click" />
</Triggers>
<ContentTemplate>
<label id="consoleOutput" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button Text="Enter" Style="display: none;" runat="server" ID="btnPostback" OnClick="HandleCommand" />
Code-behind:
protected void HandleCommand(object sender, EventArgs e)
{
SetPageData();
CheckGetData();
}
Upvotes: 1