I want to check that if user has done some changes in the dropdown list say(changing from "pending" to "yes" or from "yes" to "no" anykind of change) then a dialog box should pop up to ask "do u want to notify the changes to the user"
How should i achieve this when populating in the code-behind ?
Kirtan PatelPosted Dec 28, 2009, 10:21 PM
Swati ,
here is your Solution !!!
if my answer helps you then check "Do you like this answer " check box :)
Take one Hidden Field on Form that Will Act as Intermediate between Jscript and CodeBehind
Since java script Can Run on Client Side Code
you need to Code Client Side script .
Code Behind
----------------
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
RegisterClientScriptBlock("", "ConfirmIt()");
/*Now Access the Hidden Filed Value Since it Contain the value that
User Clicked OK or Cancel */
int result = int.Parse(HiddenField1.Value.ToString());
if (result == 1)
{
// Do somthing
}
}
HTML Code
-------------
<head runat="server">
<script language="javascript">
function ConfirmIt()
{
var result = confirm("do u want to notify the changes to the user?");
if (result == true)
{
//Set the Hidden Field Value
document.getElementById("HiddenField1").value = "1";
}
else
{
document.getElementById("HiddenField1").value = "0";
}
}
script>
head>
<body>
<form id="form1" runat="server">
<div class="style1">
<asp:HiddenField ID="HiddenField1" runat="server" Value="" />
<asp:DropDownList ID="DropDownList1" runat="server" onselectedindexchanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem>Item1asp:ListItem>
<asp:ListItem>Item2asp:ListItem>
<asp:ListItem>Item3asp:ListItem>
asp:DropDownList>
div>
form>
body>
html>
Hiren SoniPosted Dec 28, 2009, 11:23 AM
sorry, if i made a mistake...
lets solve swati s problem .
Kirtan PatelPosted Dec 28, 2009, 11:05 AM
the code Given by you will show Confirm Message box only on Server / Visual Studio it cant show Confirm Dialog on Client Side
when you actually Host WebSite on IIS it will not shown to end user as its Server Side MessageBox .So it can be loaded at Client Side .
Hiren SoniPosted Dec 28, 2009, 10:09 AM
dont 4get to accept answer