Textbox value in Update panel
-
Hello, I am using VS 2005
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager id="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel id="UpdatePanel1" runat="server" EnableViewState="False">
<contenttemplate>
<asp:TextBox ID="TextBox1" runat="server" Style="position: relative; top: 0px;"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Style="position: relative"
Text="Next" />
<asp:Button ID="Button2" runat="server" Style="position: relative" Text="Pevious" OnClick="Button2_Click" />
<asp:Button ID="Button3" runat="server" Style="left: 0px; position: relative" Text="Update" OnClick="Button3_Click" /><br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand='SELECT * FROM "EMP"'>
</asp:SqlDataSource>
</contenttemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button3" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>And in the aspx.vb file i have code following: Protected Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click MessageBox.Show(TextBox1.Text, "xx", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) End Sub but it is not showing me the current value (user chaged the value; when page comes on the browser) of the textbox; it is showing me the value which was at the time of page load. After searching a lot on the net, i am posting the question here, to get the solution how to get the current/changed value of the textbox which is in the update panel; on click of the button. Thanks & Regards Girish Sharma
-
Hello, I am using VS 2005
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager id="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel id="UpdatePanel1" runat="server" EnableViewState="False">
<contenttemplate>
<asp:TextBox ID="TextBox1" runat="server" Style="position: relative; top: 0px;"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Style="position: relative"
Text="Next" />
<asp:Button ID="Button2" runat="server" Style="position: relative" Text="Pevious" OnClick="Button2_Click" />
<asp:Button ID="Button3" runat="server" Style="left: 0px; position: relative" Text="Update" OnClick="Button3_Click" /><br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand='SELECT * FROM "EMP"'>
</asp:SqlDataSource>
</contenttemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button3" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>And in the aspx.vb file i have code following: Protected Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click MessageBox.Show(TextBox1.Text, "xx", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) End Sub but it is not showing me the current value (user chaged the value; when page comes on the browser) of the textbox; it is showing me the value which was at the time of page load. After searching a lot on the net, i am posting the question here, to get the solution how to get the current/changed value of the textbox which is in the update panel; on click of the button. Thanks & Regards Girish Sharma
plz check whether you have checked the page load in your page load event.... code in c#: if (!IsPostBack) { //Code }
Padmanabhan
-
plz check whether you have checked the page load in your page load event.... code in c#: if (!IsPostBack) { //Code }
Padmanabhan
in the page load event i have following code: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Page.IsPostBack = False Then Session("r") = 0 End If 'dv.Table.Rows(1)(1) = "xx" showdata() End Sub Regards Girish Sharma
-
in the page load event i have following code: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Page.IsPostBack = False Then Session("r") = 0 End If 'dv.Table.Rows(1)(1) = "xx" showdata() End Sub Regards Girish Sharma
try to put the showdata() inside the post back. that is the error... code: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Page.IsPostBack = False Then Session("r") = 0 'dv.Table.Rows(1)(1) = "xx" showdata() End If End Sub
Padmanabhan
-
try to put the showdata() inside the post back. that is the error... code: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Page.IsPostBack = False Then Session("r") = 0 'dv.Table.Rows(1)(1) = "xx" showdata() End If End Sub
Padmanabhan
Thanks a lot padmanabhan N. It is working fine; but it is really new to me how it is working now; when page's postback event has been fired and i have following in showdata: Public Sub showdata() dv = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), System.Data.DataView) TextBox1.Text = dv.Table.Rows(Session("r"))(1).ToString() End Sub what is the relation with the postback's true/false? I wish to thanks for providing the the answer and shall be more informative for the question i asked above please. Best Regards Girish Sharma
-
Thanks a lot padmanabhan N. It is working fine; but it is really new to me how it is working now; when page's postback event has been fired and i have following in showdata: Public Sub showdata() dv = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), System.Data.DataView) TextBox1.Text = dv.Table.Rows(Session("r"))(1).ToString() End Sub what is the relation with the postback's true/false? I wish to thanks for providing the the answer and shall be more informative for the question i asked above please. Best Regards Girish Sharma
with pleasure, The postback is doing all the things. The loop your write inside the postback will fire only when the page is loaded and the value will be maintained and the loop wont be executed after that. So, if we write the code after the loop will be fired in even and every postback. just keep the breakpoint in the page load and check. You can see for each and every postback the pageload event is fired. So each and every time the button click it fires the page load first and then the button event. So, the showdata() will clears your modification and the original data will be set. For this only you got the old values. I hope you understand now.
Padmanabhan
-
with pleasure, The postback is doing all the things. The loop your write inside the postback will fire only when the page is loaded and the value will be maintained and the loop wont be executed after that. So, if we write the code after the loop will be fired in even and every postback. just keep the breakpoint in the page load and check. You can see for each and every postback the pageload event is fired. So each and every time the button click it fires the page load first and then the button event. So, the showdata() will clears your modification and the original data will be set. For this only you got the old values. I hope you understand now.
Padmanabhan
-
padmanabhan N Thank you so much for clearing doubts and nice explanation. Best Regards Girish Sharma
its ok, Happy coding..
Padmanabhan