Home » Asp.netRSS

Update Panel - TextBox

hello,

              I m getting a value into Textbox using Javascript. That textbox value may or maynot changes when I click on button in the same page.

When textbox value changes, I want to trigger the textbox event automatically and want to display the info on the same page.


Simply, whenever textbox value changes, I need autopostback. But I dont want to postback whole page.


TIA


 

7 Answers Found

 

Answer 1

Keep TextBox in an update panel

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="up1" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" 
                        OnTextChanged="TextBox1_TextChanged">
        </asp:TextBox>
    </ContentTemplate>
</asp:UpdatePanel>
 

Answer 2

sansan:
Keep TextBox in an update panel


I tried this one...But its not working.


I m getting the value into text box using Javascript.

 

Answer 3

sansan:
  OnTextChanged="TextBox1_TextChanged"


This is fired when ever control left the TextBox..?


How can I fire a control whenever the textbox value changes.?


 

Answer 4

No, TextChanged Event fires when value changes(onchange event).

If you are assigning a value to a TextBox on a button click as shown below, TEXTBOX DOES POSTBACK

<asp:Button ID="btnCopy" runat="server" Text="Copy" 
                OnClientClick="document.getElementById('TextBox1').value='your value';" />
    <asp:UpdatePanel runat="server" ID="up1" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" OnTextChanged="TextBox1_TextChanged">
            </asp:TextBox>
        </ContentTemplate>
    </asp:UpdatePanel>
 
 

Answer 6

sansan:

No, TextChanged Event fires when value changes(onchange event).

If you are assigning a value to a TextBox on a button click as shown below, TEXTBOX DOES POSTBACK


This is not working...Thank you for ur help


 

Answer 7

Hi,

Here is a full sample:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function pageLoad(sender, e) {
            if ("\v" == "v") {
                $addHandler($get("tchange"), "propertychange", OnTextValueChange);
            }
            else {
                // only support for FF 3.0.10 or later
                $get("tchange").addEventListener("DOMAttrModified", OnTextValueChange, false);
            }
        }
        function OnTextValueChange() {
            //do async-postback
            $get('btnpostback').click();
        }
        function changeTextValue() {
            //you need to use setAttribute to change the value
            $get('tchange').setAttribute('value', 'evg');
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="SM" runat="server">
        </asp:ScriptManager>
        <asp:TextBox runat="server" ID="tchange" Text="Init"></asp:TextBox>
        <asp:Button runat="server" ID="changevalue" Text="Change" OnClientClick="changeTextValue();return false;" />
        
        
        <asp:UpdatePanel runat="server" ID="UP">
            <ContentTemplate>
                <asp:Button ID="btnpostback" runat="server" OnClick="tchange_TextChange" Text="PostBackToDoSomething" Style="display: none" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>


 

    protected void tchange_TextChange(object sender, EventArgs e)
    {
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "change", "alert('value changed');", true);
    }


 

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter