user2402179
user2402179

Reputation:

Calling manual AJAX functions in ASP.NET WebForms with postbacks

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:

But, finally nothing is happen... The most strangest things for me, are:

So, the final question is: why do it call a bug and how to fix it?

Upvotes: 0

Views: 610

Answers (1)

mshsayem
mshsayem

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

Related Questions