Thursday, March 29, 2012
Set Button : autopostback to be false
?
How can I change it to be false ?
I tried this...
<td><asp:Button id="cmd1" ... autopostback="false"/></td>
But it failed. Why?
ThxThat's what you get when you use a server-side control - when it's clicked
it will post back to the server. If you don't want a postback then simply
use a <input type=button>.
-Brock
DevelopMentor
http://staff.develop.com/ballen
> The standard button is set its autopostback property to be true, am I
> right
> ?
> How can I change it to be false ?
> I tried this...
> <td><asp:Button id="cmd1" ... autopostback="false"/></td>
> But it failed. Why?
> Thx
>
Set Button : autopostback to be false
?
How can I change it to be false ?
I tried this...
<td><asp:Button id="cmd1" ... autopostback="false"/></td>
But it failed. Why?
ThxThat's what you get when you use a server-side control - when it's clicked
it will post back to the server. If you don't want a postback then simply
use a <input type=button>.
-Brock
DevelopMentor
http://staff.develop.com/ballen
> The standard button is set its autopostback property to be true, am I
> right
> ?
> How can I change it to be false ?
> I tried this...
> <td><asp:Button id="cmd1" ... autopostback="false"/></td>
> But it failed. Why?
> Thx
Set Conditional AutoPostBack In User Control
<asp:TextBox ID="txtName" runat="server"/>
I am encapsulating the above user control in a ASPX page named
Page1.aspx i.e. the ASPX page displays a single TextBox. There's also a
CheckBox in this ASPX page within the <formtags. Note that the
CheckBox IS NOT a part of the user control. It has been explicitly
added to the Form existing in the ASPX page. The AutoPostBack property
of the CheckBox is set to True so that whenever the CheckBox is
checked/unchecked by the user, a sub named 'chk_Check' gets executed.
This is the ASPX code:
<%@dotnet.itags.org. Register TagPrefix="MyPage" TagName="Ctrl" src="http://pics.10026.com/?src=Page1.ascx" %>
<script runat="server">
Sub chk_Check(obj As Object, ea As EventArgs)
........
........
End Sub
</script>
<form runat="server">
<MyPage:Ctrl ID="mpc" runat="server"/><br>
<asp:CheckBox ID="chk1" OnCheckedChanged="chk_Check"
AutoPostBack="true" Text="Check Me" runat="server"/>
</form>
When the page loads for the first time, the CheckBox is unchecked by
default. Now what I want is if the CheckBox is checked by the user,
then the AutoPostBack property of the TextBox existing in the user
control (whose ID is txtName) should be set to True. If the CheckBox is
unchecked by the user, then the AutoPostBack property of the TextBox
named txtName in the user control should be set to False.
One way of doing this is to make use of a Session variable...something
like this (in the ASPX page):
Sub Page_Load(.....)
If (chk1.Checked = True) Then
Session("chk") = 1
Else
Session("chk") = 0
End If
End Sub
Sub chk_Check(.....)
If (chk1.Checked = True) Then
Session("chk") = 1
Else
Session("chk") = 0
End If
End Sub
& then in the ASCX page
<script runat="server">
Sub Page_Load(.....)
If (Session("chk") = 1) Then
txtName.AutoPostBack = True
Else
txtName.AutoPostBack = False
End If
End Sub
</script>
Are there any other ways to accomplish this logic since, as far as
possible, I would like to avoid using Session variables?
Moreover, are there any major drawbacks of the above logic? Of course,
one of them being Session variables are memory resident & another being
users' browser should have cookies enabled although on most occasions,
cookies remain enabled.If you want to do this as simply as possible, you will have the checkbox
auto postback to set the value. If you want this fully dynamic, you will
have to write JavaScript that creates a postback event on the textbox and
removes it via checking/unchecking the box.
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com/
*************************************************
Think Outside the Box!
*************************************************
<rn5a@.rediffmail.comwrote in message
news:1160321009.138108.22940@.c28g2000cwb.googlegro ups.com...
Quote:
Originally Posted by
Assume that a user control has a TextBox (Page1.ascx)
>
<asp:TextBox ID="txtName" runat="server"/>
>
I am encapsulating the above user control in a ASPX page named
Page1.aspx i.e. the ASPX page displays a single TextBox. There's also a
CheckBox in this ASPX page within the <formtags. Note that the
CheckBox IS NOT a part of the user control. It has been explicitly
added to the Form existing in the ASPX page. The AutoPostBack property
of the CheckBox is set to True so that whenever the CheckBox is
checked/unchecked by the user, a sub named 'chk_Check' gets executed.
This is the ASPX code:
>
<%@. Register TagPrefix="MyPage" TagName="Ctrl" src="http://pics.10026.com/?src=Page1.ascx" %>
<script runat="server">
Sub chk_Check(obj As Object, ea As EventArgs)
........
........
End Sub
</script>
>
<form runat="server">
<MyPage:Ctrl ID="mpc" runat="server"/><br>
<asp:CheckBox ID="chk1" OnCheckedChanged="chk_Check"
AutoPostBack="true" Text="Check Me" runat="server"/>
</form>
>
When the page loads for the first time, the CheckBox is unchecked by
default. Now what I want is if the CheckBox is checked by the user,
then the AutoPostBack property of the TextBox existing in the user
control (whose ID is txtName) should be set to True. If the CheckBox is
unchecked by the user, then the AutoPostBack property of the TextBox
named txtName in the user control should be set to False.
>
One way of doing this is to make use of a Session variable...something
like this (in the ASPX page):
>
Sub Page_Load(.....)
If (chk1.Checked = True) Then
Session("chk") = 1
Else
Session("chk") = 0
End If
End Sub
>
Sub chk_Check(.....)
If (chk1.Checked = True) Then
Session("chk") = 1
Else
Session("chk") = 0
End If
End Sub
>
& then in the ASCX page
>
<script runat="server">
Sub Page_Load(.....)
If (Session("chk") = 1) Then
txtName.AutoPostBack = True
Else
txtName.AutoPostBack = False
End If
End Sub
</script>
>
Are there any other ways to accomplish this logic since, as far as
possible, I would like to avoid using Session variables?
>
Moreover, are there any major drawbacks of the above logic? Of course,
one of them being Session variables are memory resident & another being
users' browser should have cookies enabled although on most occasions,
cookies remain enabled.
>
It's simple (i am assuming you want to use postbacks instead of dynamic
javascript). Just create a property for user control that will expose
autopostback for the text box as shown below (i defined it in code behind of
the user control)
Public Class Page1
Inherits System.Web.UI.UserControl
Public Property TextBoxAutoPostBack() As Boolean
Get
Return txtName.AutoPostBack
End Get
Set(ByVal value As Boolean)
txtName.AutoPostBack = value
End Set
End Property
End Class
Now use it in aspx page like this
<%@. Register TagPrefix="MyPage" TagName="Ctrl" src="http://pics.10026.com/?src=Page1.ascx" %>
<script runat="server">
Sub chk_Check(obj As Object, ea As EventArgs)
mpc.TextBoxAutoPostBack = CType(obj, CheckBox).Checked
End Sub
</script>
<form runat="server">
<MyPage:Ctrl ID="mpc" runat="server"/><br>
<asp:CheckBox ID="chk1" OnCheckedChanged="chk_Check"
AutoPostBack="true" Text="Check Me" runat="server"/>
</form>
Autopostback is serialized to viewstate by default so you page contains it
between postbacks. That's all.
Hope this helps
--
Milosz Skalecki
MCP, MCAD
"rn5a@.rediffmail.com" wrote:
Quote:
Originally Posted by
Assume that a user control has a TextBox (Page1.ascx)
>
<asp:TextBox ID="txtName" runat="server"/>
>
I am encapsulating the above user control in a ASPX page named
Page1.aspx i.e. the ASPX page displays a single TextBox. There's also a
CheckBox in this ASPX page within the <formtags. Note that the
CheckBox IS NOT a part of the user control. It has been explicitly
added to the Form existing in the ASPX page. The AutoPostBack property
of the CheckBox is set to True so that whenever the CheckBox is
checked/unchecked by the user, a sub named 'chk_Check' gets executed.
This is the ASPX code:
>
<%@. Register TagPrefix="MyPage" TagName="Ctrl" src="http://pics.10026.com/?src=Page1.ascx" %>
<script runat="server">
Sub chk_Check(obj As Object, ea As EventArgs)
........
........
End Sub
</script>
>
<form runat="server">
<MyPage:Ctrl ID="mpc" runat="server"/><br>
<asp:CheckBox ID="chk1" OnCheckedChanged="chk_Check"
AutoPostBack="true" Text="Check Me" runat="server"/>
</form>
>
When the page loads for the first time, the CheckBox is unchecked by
default. Now what I want is if the CheckBox is checked by the user,
then the AutoPostBack property of the TextBox existing in the user
control (whose ID is txtName) should be set to True. If the CheckBox is
unchecked by the user, then the AutoPostBack property of the TextBox
named txtName in the user control should be set to False.
>
One way of doing this is to make use of a Session variable...something
like this (in the ASPX page):
>
Sub Page_Load(.....)
If (chk1.Checked = True) Then
Session("chk") = 1
Else
Session("chk") = 0
End If
End Sub
>
Sub chk_Check(.....)
If (chk1.Checked = True) Then
Session("chk") = 1
Else
Session("chk") = 0
End If
End Sub
>
& then in the ASCX page
>
<script runat="server">
Sub Page_Load(.....)
If (Session("chk") = 1) Then
txtName.AutoPostBack = True
Else
txtName.AutoPostBack = False
End If
End Sub
</script>
>
Are there any other ways to accomplish this logic since, as far as
possible, I would like to avoid using Session variables?
>
Moreover, are there any major drawbacks of the above logic? Of course,
one of them being Session variables are memory resident & another being
users' browser should have cookies enabled although on most occasions,
cookies remain enabled.
>
>
Set Conditional AutoPostBack In User Control
<asp:TextBox ID="txtName" runat="server"/>
I am encapsulating the above user control in a ASPX page named
Page1.aspx i.e. the ASPX page displays a single TextBox. There's also a
CheckBox in this ASPX page within the <form> tags. Note that the
CheckBox IS NOT a part of the user control. It has been explicitly
added to the Form existing in the ASPX page. The AutoPostBack property
of the CheckBox is set to True so that whenever the CheckBox is
checked/unchecked by the user, a sub named 'chk_Check' gets executed.
This is the ASPX code:
<%@dotnet.itags.org. Register TagPrefix="MyPage" TagName="Ctrl" src="http://pics.10026.com/?src=Page1.ascx" %>
<script runat="server">
Sub chk_Check(obj As Object, ea As EventArgs)
.......
.......
End Sub
</script>
<form runat="server">
<MyPage:Ctrl ID="mpc" runat="server"/><br>
<asp:CheckBox ID="chk1" OnCheckedChanged="chk_Check"
AutoPostBack="true" Text="Check Me" runat="server"/>
</form>
When the page loads for the first time, the CheckBox is unchecked by
default. Now what I want is if the CheckBox is checked by the user,
then the AutoPostBack property of the TextBox existing in the user
control (whose ID is txtName) should be set to True. If the CheckBox is
unchecked by the user, then the AutoPostBack property of the TextBox
named txtName in the user control should be set to False.
One way of doing this is to make use of a Session variable...something
like this (in the ASPX page):
Sub Page_Load(.....)
If (chk1.Checked = True) Then
Session("chk") = 1
Else
Session("chk") = 0
End If
End Sub
Sub chk_Check(.....)
If (chk1.Checked = True) Then
Session("chk") = 1
Else
Session("chk") = 0
End If
End Sub
& then in the ASCX page
<script runat="server">
Sub Page_Load(.....)
If (Session("chk") = 1) Then
txtName.AutoPostBack = True
Else
txtName.AutoPostBack = False
End If
End Sub
</script>
Are there any other ways to accomplish this logic since, as far as
possible, I would like to avoid using Session variables?
Moreover, are there any major drawbacks of the above logic? Of course,
one of them being Session variables are memory resident & another being
users' browser should have cookies enabled although on most occasions,
cookies remain enabled.If you want to do this as simply as possible, you will have the checkbox
auto postback to set the value. If you want this fully dynamic, you will
have to write JavaScript that creates a postback event on the textbox and
removes it via checking/unchecking the box.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com/
****************************************
*********
Think Outside the Box!
****************************************
*********
<rn5a@.rediffmail.com> wrote in message
news:1160321009.138108.22940@.c28g2000cwb.googlegroups.com...
> Assume that a user control has a TextBox (Page1.ascx)
> <asp:TextBox ID="txtName" runat="server"/>
> I am encapsulating the above user control in a ASPX page named
> Page1.aspx i.e. the ASPX page displays a single TextBox. There's also a
> CheckBox in this ASPX page within the <form> tags. Note that the
> CheckBox IS NOT a part of the user control. It has been explicitly
> added to the Form existing in the ASPX page. The AutoPostBack property
> of the CheckBox is set to True so that whenever the CheckBox is
> checked/unchecked by the user, a sub named 'chk_Check' gets executed.
> This is the ASPX code:
> <%@. Register TagPrefix="MyPage" TagName="Ctrl" src="http://pics.10026.com/?src=Page1.ascx" %>
> <script runat="server">
> Sub chk_Check(obj As Object, ea As EventArgs)
> ........
> ........
> End Sub
> </script>
> <form runat="server">
> <MyPage:Ctrl ID="mpc" runat="server"/><br>
> <asp:CheckBox ID="chk1" OnCheckedChanged="chk_Check"
> AutoPostBack="true" Text="Check Me" runat="server"/>
> </form>
> When the page loads for the first time, the CheckBox is unchecked by
> default. Now what I want is if the CheckBox is checked by the user,
> then the AutoPostBack property of the TextBox existing in the user
> control (whose ID is txtName) should be set to True. If the CheckBox is
> unchecked by the user, then the AutoPostBack property of the TextBox
> named txtName in the user control should be set to False.
> One way of doing this is to make use of a Session variable...something
> like this (in the ASPX page):
> Sub Page_Load(.....)
> If (chk1.Checked = True) Then
> Session("chk") = 1
> Else
> Session("chk") = 0
> End If
> End Sub
> Sub chk_Check(.....)
> If (chk1.Checked = True) Then
> Session("chk") = 1
> Else
> Session("chk") = 0
> End If
> End Sub
> & then in the ASCX page
> <script runat="server">
> Sub Page_Load(.....)
> If (Session("chk") = 1) Then
> txtName.AutoPostBack = True
> Else
> txtName.AutoPostBack = False
> End If
> End Sub
> </script>
> Are there any other ways to accomplish this logic since, as far as
> possible, I would like to avoid using Session variables?
> Moreover, are there any major drawbacks of the above logic? Of course,
> one of them being Session variables are memory resident & another being
> users' browser should have cookies enabled although on most occasions,
> cookies remain enabled.
>
It's simple (i am assuming you want to use postbacks instead of dynamic
javascript). Just create a property for user control that will expose
autopostback for the text box as shown below (i defined it in code behind of
the user control)
Public Class Page1
Inherits System.Web.UI.UserControl
Public Property TextBoxAutoPostBack() As Boolean
Get
Return txtName.AutoPostBack
End Get
Set(ByVal value As Boolean)
txtName.AutoPostBack = value
End Set
End Property
End Class
Now use it in aspx page like this
<%@. Register TagPrefix="MyPage" TagName="Ctrl" src="http://pics.10026.com/?src=Page1.ascx" %>
<script runat="server">
Sub chk_Check(obj As Object, ea As EventArgs)
mpc.TextBoxAutoPostBack = CType(obj, CheckBox).Checked
End Sub
</script>
<form runat="server">
<MyPage:Ctrl ID="mpc" runat="server"/><br>
<asp:CheckBox ID="chk1" OnCheckedChanged="chk_Check"
AutoPostBack="true" Text="Check Me" runat="server"/>
</form>
Autopostback is serialized to viewstate by default so you page contains it
between postbacks. That's all.
Hope this helps
--
Milosz Skalecki
MCP, MCAD
"rn5a@.rediffmail.com" wrote:
> Assume that a user control has a TextBox (Page1.ascx)
> <asp:TextBox ID="txtName" runat="server"/>
> I am encapsulating the above user control in a ASPX page named
> Page1.aspx i.e. the ASPX page displays a single TextBox. There's also a
> CheckBox in this ASPX page within the <form> tags. Note that the
> CheckBox IS NOT a part of the user control. It has been explicitly
> added to the Form existing in the ASPX page. The AutoPostBack property
> of the CheckBox is set to True so that whenever the CheckBox is
> checked/unchecked by the user, a sub named 'chk_Check' gets executed.
> This is the ASPX code:
> <%@. Register TagPrefix="MyPage" TagName="Ctrl" src="http://pics.10026.com/?src=Page1.ascx" %>
> <script runat="server">
> Sub chk_Check(obj As Object, ea As EventArgs)
> ........
> ........
> End Sub
> </script>
> <form runat="server">
> <MyPage:Ctrl ID="mpc" runat="server"/><br>
> <asp:CheckBox ID="chk1" OnCheckedChanged="chk_Check"
> AutoPostBack="true" Text="Check Me" runat="server"/>
> </form>
> When the page loads for the first time, the CheckBox is unchecked by
> default. Now what I want is if the CheckBox is checked by the user,
> then the AutoPostBack property of the TextBox existing in the user
> control (whose ID is txtName) should be set to True. If the CheckBox is
> unchecked by the user, then the AutoPostBack property of the TextBox
> named txtName in the user control should be set to False.
> One way of doing this is to make use of a Session variable...something
> like this (in the ASPX page):
> Sub Page_Load(.....)
> If (chk1.Checked = True) Then
> Session("chk") = 1
> Else
> Session("chk") = 0
> End If
> End Sub
> Sub chk_Check(.....)
> If (chk1.Checked = True) Then
> Session("chk") = 1
> Else
> Session("chk") = 0
> End If
> End Sub
> & then in the ASCX page
> <script runat="server">
> Sub Page_Load(.....)
> If (Session("chk") = 1) Then
> txtName.AutoPostBack = True
> Else
> txtName.AutoPostBack = False
> End If
> End Sub
> </script>
> Are there any other ways to accomplish this logic since, as far as
> possible, I would like to avoid using Session variables?
> Moreover, are there any major drawbacks of the above logic? Of course,
> one of them being Session variables are memory resident & another being
> users' browser should have cookies enabled although on most occasions,
> cookies remain enabled.
>
Thursday, March 22, 2012
Set javascript value OnCheckedChanged
I have a AutoPostBack checkbox and need to set a value bSubmitted =
true when the checkbox is checked in order to prevent a warning message
appearing notifying the user they are navigating away from the page.
I have been trying to add the following in the <script> section of the
<HEAD> section:
addNewSurgeonChkBx.Attributes.Add("onclick","javascript:bSubmitted=true;");
But it does not seem to work, I still get the error message.
I have also tried to put it on the onLoad section of the C# CodeBehind,
here though it surpresses the error message for all controls, not just
the checkbox.
Any ideas of how to fix this?
Thanks.How about letting the JavaScript that pops up the notification check if the
checkbox is checked.
So where is says:
Confirm('Are you sure you want to navigate away from this page');
change that too
if(!Document.GetElementById('addNewSurgeonChkBx'). Checked)
Confirm('Are you sure you want to navigate away from this page');
Is that what you looking for?
"Assimalyst" <c_oxtoby@.hotmail.com> wrote in message
news:1123775711.123436.307480@.g43g2000cwa.googlegr oups.com...
> Hi,
> I have a AutoPostBack checkbox and need to set a value bSubmitted =
> true when the checkbox is checked in order to prevent a warning message
> appearing notifying the user they are navigating away from the page.
> I have been trying to add the following in the <script> section of the
> <HEAD> section:
> addNewSurgeonChkBx.Attributes.Add("onclick","javascript:bSubmitted=true;");
> But it does not seem to work, I still get the error message.
> I have also tried to put it on the onLoad section of the C# CodeBehind,
> here though it surpresses the error message for all controls, not just
> the checkbox.
> Any ideas of how to fix this?
> Thanks.
Thanks, tried that but no luck. It stops the script from working for
all controls on the page!? Think it errored, so it could have been the
way i added it. Here's what I had:
function checkFormStatus(oForm)
{
if(isDirty(oForm))
if(!Document.GetElementById('addNewSurgeonChkBx'). Checked)
event.returnValue = "You have entered form Data without submitting
this form. \nAny changes you have made will not be saved.";
}
Here's the full original code, if that might give anymore ideas:
// Warns user before page unload
function checkFormStatus(oForm)
{
if(isDirty(oForm))
event.returnValue = "You have entered form Data without submitting
this form. \nAny changes you have made will not be saved.";
}
var bSubmitted=false;
function isDirty(oForm)
{
if(bSubmitted) return false;
var iNumElems = oForm.elements.length;
for (var i=0;i<iNumElems;i++)
{
var oElem = oForm.elements[i];
if ("text" == oElem.type || "TEXTAREA" == oElem.tagName)
{
if (oElem.value != oElem.defaultValue) return true;
}
else if ("checkbox" == oElem.type || "radio" == oElem.type)
{
if (oElem.checked != oElem.defaultChecked) return true;
}
else if ("SELECT" == oElem.tagName)
{
var oOptions = oElem.options;
var iNumOpts = oOptions.length;
for (var j=0;j<iNumOpts;j++)
{
var oOpt = oOptions[j];
if (oOpt.selected != oOpt.defaultSelected) return true;
}
}
}
return false;
}
It can be disadbled easily with the submit button by adding in it's
tag:
onclick="javascript:bSubmitted=true;"
However, adding this to a onCheckedChanged for a checkbox results in a
compilation error, saying ") expected".
Any more ideas?
Thanks
sorry, there was a Syntax error there.
Should have been:
document.getElementById('cb').checked
"Assimalyst" <c_oxtoby@.hotmail.com> wrote in message
news:1123839782.734420.108040@.f14g2000cwb.googlegr oups.com...
> Thanks, tried that but no luck. It stops the script from working for
> all controls on the page!? Think it errored, so it could have been the
> way i added it. Here's what I had:
> function checkFormStatus(oForm)
> {
> if(isDirty(oForm))
> if(!Document.GetElementById('addNewSurgeonChkBx'). Checked)
> event.returnValue = "You have entered form Data without submitting
> this form. \nAny changes you have made will not be saved.";
> }
> Here's the full original code, if that might give anymore ideas:
> // Warns user before page unload
> function checkFormStatus(oForm)
> {
> if(isDirty(oForm))
> event.returnValue = "You have entered form Data without submitting
> this form. \nAny changes you have made will not be saved.";
> }
> var bSubmitted=false;
> function isDirty(oForm)
> {
> if(bSubmitted) return false;
> var iNumElems = oForm.elements.length;
> for (var i=0;i<iNumElems;i++)
> {
> var oElem = oForm.elements[i];
> if ("text" == oElem.type || "TEXTAREA" == oElem.tagName)
> {
> if (oElem.value != oElem.defaultValue) return true;
> }
> else if ("checkbox" == oElem.type || "radio" == oElem.type)
> {
> if (oElem.checked != oElem.defaultChecked) return true;
> }
> else if ("SELECT" == oElem.tagName)
> {
> var oOptions = oElem.options;
> var iNumOpts = oOptions.length;
> for (var j=0;j<iNumOpts;j++)
> {
> var oOpt = oOptions[j];
> if (oOpt.selected != oOpt.defaultSelected) return true;
> }
> }
> }
> return false;
> }
> It can be disadbled easily with the submit button by adding in it's
> tag:
> onclick="javascript:bSubmitted=true;"
> However, adding this to a onCheckedChanged for a checkbox results in a
> compilation error, saying ") expected".
> Any more ideas?
> Thanks
Thank you very much Grant. Thats almost made it work.
It now behaves correctly when the checkbox changes from false to true.
However, the message still appears when it changes from true to false.
I would like to stop this too.
I tried changing the .checked to .checkedchanged but that makes the
message box appear when the checkbox if changing from true to false and
from false to true.
Any ideas?
Thanks again
Set javascript value OnCheckedChanged
I have a AutoPostBack checkbox and need to set a value bSubmitted =
true when the checkbox is checked in order to prevent a warning message
appearing notifying the user they are navigating away from the page.
I have been trying to add the following in the <script> section of the
<HEAD> section:
addNewSurgeonChkBx.Attributes.Add("onclick","Javascript:bSubmitted=true;");
But it does not seem to work, I still get the error message.
I have also tried to put it on the onLoad section of the C# CodeBehind,
here though it surpresses the error message for all controls, not just
the checkbox.
Any ideas of how to fix this?
Thanks.How about letting the JavaScript that pops up the notification check if the
checkbox is checked.
So where is says:
Confirm('Are you sure you want to navigate away from this page');
change that too
if(!Document.GetElementById('addNewSurgeonChkBx').Checked)
Confirm('Are you sure you want to navigate away from this page');
Is that what you looking for?
"Assimalyst" <c_oxtoby@.hotmail.com> wrote in message
news:1123775711.123436.307480@.g43g2000cwa.googlegroups.com...
> Hi,
> I have a AutoPostBack checkbox and need to set a value bSubmitted =
> true when the checkbox is checked in order to prevent a warning message
> appearing notifying the user they are navigating away from the page.
> I have been trying to add the following in the <script> section of the
> <HEAD> section:
> addNewSurgeonChkBx.Attributes.Add("onclick","java script:bSubmitted=true;")
;
> But it does not seem to work, I still get the error message.
> I have also tried to put it on the onLoad section of the C# CodeBehind,
> here though it surpresses the error message for all controls, not just
> the checkbox.
> Any ideas of how to fix this?
> Thanks.
>
Thanks, tried that but no luck. It stops the script from working for
all controls on the page!? Think it errored, so it could have been the
way i added it. Here's what I had:
function checkFormStatus(oForm)
{
if(isDirty(oForm))
if(!Document.GetElementById('addNewSurgeonChkBx').Checked)
event.returnValue = "You have entered form Data without submitting
this form. \nAny changes you have made will not be saved.";
}
Here's the full original code, if that might give anymore ideas:
// Warns user before page unload
function checkFormStatus(oForm)
{
if(isDirty(oForm))
event.returnValue = "You have entered form Data without submitting
this form. \nAny changes you have made will not be saved.";
}
var bSubmitted=false;
function isDirty(oForm)
{
if(bSubmitted) return false;
var iNumElems = oForm.elements.length;
for (var i=0;i<iNumElems;i++)
{
var oElem = oForm.elements[i];
if ("text" == oElem.type || "TEXTAREA" == oElem.tagName)
{
if (oElem.value != oElem.defaultValue) return true;
}
else if ("checkbox" == oElem.type || "radio" == oElem.type)
{
if (oElem.checked != oElem.defaultChecked) return true;
}
else if ("SELECT" == oElem.tagName)
{
var oOptions = oElem.options;
var iNumOpts = oOptions.length;
for (var j=0;j<iNumOpts;j++)
{
var oOpt = oOptions[j];
if (oOpt.selected != oOpt.defaultSelected) return true;
}
}
}
return false;
}
It can be di
tag:
onclick="java script:bSubmitted=true;"
However, adding this to a onCheckedChanged for a checkbox results in a
compilation error, saying ") expected".
Any more ideas?
Thanks
sorry, there was a Syntax error there.
Should have been:
document.getElementById('cb').checked
"Assimalyst" <c_oxtoby@.hotmail.com> wrote in message
news:1123839782.734420.108040@.f14g2000cwb.googlegroups.com...
> Thanks, tried that but no luck. It stops the script from working for
> all controls on the page!? Think it errored, so it could have been the
> way i added it. Here's what I had:
> function checkFormStatus(oForm)
> {
> if(isDirty(oForm))
> if(!Document.GetElementById('addNewSurgeonChkBx').Checked)
> event.returnValue = "You have entered form Data without submitting
> this form. \nAny changes you have made will not be saved.";
> }
> Here's the full original code, if that might give anymore ideas:
> // Warns user before page unload
> function checkFormStatus(oForm)
> {
> if(isDirty(oForm))
> event.returnValue = "You have entered form Data without submitting
> this form. \nAny changes you have made will not be saved.";
> }
> var bSubmitted=false;
> function isDirty(oForm)
> {
> if(bSubmitted) return false;
> var iNumElems = oForm.elements.length;
> for (var i=0;i<iNumElems;i++)
> {
> var oElem = oForm.elements[i];
> if ("text" == oElem.type || "TEXTAREA" == oElem.tagName)
> {
> if (oElem.value != oElem.defaultValue) return true;
> }
> else if ("checkbox" == oElem.type || "radio" == oElem.type)
> {
> if (oElem.checked != oElem.defaultChecked) return true;
> }
> else if ("SELECT" == oElem.tagName)
> {
> var oOptions = oElem.options;
> var iNumOpts = oOptions.length;
> for (var j=0;j<iNumOpts;j++)
> {
> var oOpt = oOptions[j];
> if (oOpt.selected != oOpt.defaultSelected) return true;
> }
> }
> }
> return false;
> }
> It can be di
> tag:
> onclick="java script:bSubmitted=true;"
> However, adding this to a onCheckedChanged for a checkbox results in a
> compilation error, saying ") expected".
> Any more ideas?
> Thanks
>
Thank you very much Grant. Thats almost made it work.
It now behaves correctly when the checkbox changes from false to true.
However, the message still appears when it changes from true to false.
I would like to stop this too.
I tried changing the .checked to .checkedchanged but that makes the
message box appear when the checkbox if changing from true to false and
from false to true.
Any ideas?
Thanks again