In a page I have a link; clicking on it opens a dialog and sets a textbox value for that dialog.
However, once I click on submit in that dialog, the textbox value is null.
Link:
<a href="#" onclick="javascript:expand('https://me.yahoo.com');
jQuery('#openiddialog').dialog('open'); return false;">
<img id="yahoo" class="spacehw" src="/Content/Images/spacer.gif" /></a>
Script:
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery("#openiddialog").dialog({
autoOpen: false,
width: 600,
modal: true,
buttons: {
"Cancel": function () {
$(this).dialog("close");
}
}
});
});
function expand(obj) {
$("#<%=openIdBox.ClientID %>").val(obj);
}
Dialog:
<div id="openiddialog" title="Log in using OpenID">
<p>
<asp:Label ID="Label1" runat="server" Text="OpenID Login" />
<asp:TextBox ID="openIdBox" EnableViewState="true" runat="server" />
<asp:JButton Icon="ui-icon-key" ID="loginButton" runat="server" Text="Authenticate" OnClick="loginButton_Click" />
<asp:CustomValidator runat="server" ID="openidValidator" ErrorMessage="Invalid OpenID Identifier" ControlToValidate="openIdBox" EnableViewState="false" OnServerValidate="openidValidator_ServerValidate" />
<br />
<asp:Label ID="loginFailedLabel" runat="server" EnableViewState="False" Text="Login failed" Visible="False" />
<asp:Label ID="loginCanceledLabel" runat="server" EnableViewState="False" Text="Login canceled" Visible="False" />
</p>
</div>
If you're using an ASP.NET TextBox Control (for example), and it's READONLY or DISABLED, the postback won't catch the changed value. Per my issue, I was changing the value of the control thru javascript and even though the browser rendered the change, on the postback, the control still retained the original value.
When PostBack happens i.e. when Button is clicked or any other control that does PostBack inside GridView, the GridView is again populated with data and hence the modified values in TextBox are lost. Solution to this problem is to wrap the GridView binding code inside the Not IsPostBack condition as shown in the example below.
If you put code in your Page_Load event to set the values of the ASP.NET textboxes, the values that were posted back will not be saved, because Page_Load happens after the child control states are restored in the ASP.NET page lifecycle. The values are already restored by ASP.NET, but you are overwriting their restored values.
The initial values of these textboxes are retrieved from a database. When a user changes these values, they are not saved and the textboxes are cleared out after the submit button is clicked. Please help resolve this confusion. Thanks. thanks for your reply but it is still not working.....
I figured:
I have to add this line to append the dialog to the form, as jquery dialog appends to the body:
$("#openiddialog").parent().appendTo(jQuery("form:first"));
The entire script should now look like this:
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery("#openiddialog").dialog({
autoOpen: false,
width: 600,
modal: true,
buttons: { "Cancel": function () {
$(this).dialog("close");
}
}
});
$("#openiddialog").parent().appendTo(jQuery("form:first"));
});
function expand(obj) {
$("#<%=openIdBox.ClientID %>").val(obj);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With