I have an user control, that is being called in a page. The psuedo code is as below Main page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<%@ Register TagPrefix="test" TagName="newcontrol" Src="~/UserControl.ascx" %>
<!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>
</head>
<body>
<script id="testscript" language="javascript" src="CheckJavaScript.js"> </script>
<form id="form1" runat="server">
<div>
<test:newcontrol ID="testingNewControl" runat="server" />
<asp:Button ID="btnSave" runat="server" Width="100" OnClientClick="CallingScript()" />
</div>
</form>
</body>
</html>
User control
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UserControl.ascx.cs"
Inherits="WebApplication1.UserControl" %>
<div id="usertest" runat="server">
<table>
<tr>
<td>
<asp:Label ID="label1" Text="Name" runat="server">
</asp:Label>
<asp:TextBox ID="text1" runat="server"></asp:TextBox>
</td>
</tr>
</table>
<table>
<tr>
<td>
<asp:Label ID="label2" Text="City" runat="server">
</asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
</table>
</div>
I want to call the javascript, if there is any change in the value of the text box, when the user hits the "Save" button.
How do I identify whether the text box value has changed or not. Further, i have show just two text boxes in user control, whereas there will be many textboxes. I have to show the alert as "value changed in textbox1" or "value changed in textbox2"
How do I proceed.
One way to do it is for each textbox have a hidden field on the page with the original value in it and have the name of the hidden field be similar to the textbox. For example if you have a textbox named "username" have a corresponding hidden field named "username_orig". Then on form submit you can simply check all the input tags using the jquery selector of input and compare to the input tag name + "_orig" and see if they are the same. if they aren't then alret the name of the box and that the value has changed.
For a generic solution, you need a solution that tracks old values. A typical outline of solution is
In my case, this entire solution was packaged at the base page level. So page developer has to do was to flip the flag to indicate control tracking & identify controls by register/un-register - the base page would take care of constructing original value dictionary, registering a hidden field, injecting the js script calls etc.
Store all initial values in a data set.
When submitting, check each value against the data set's vals.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.