Showing posts with label order. Show all posts
Showing posts with label order. Show all posts

Monday, March 26, 2012

Set display order of ListBox control

Hi
I have a ListBox control in my ASP.NET page. After I binding data to this
control, I would like to be able to change this display order of items in
this control. Just like change layout function of my.yahoo.com.
I tried client side approach, yes I can change display order by JavaScript,
but after clicking one of the button the display order will reverse back to
its original status. Because after PostBack, the page will try to render
this control by viewstate again.

I tried server side approach, but looks there is no way to switch two
ListItems programmatically.

Is there anybody who has some good idea?

Thanks!

--

WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours HardyI already solved this problem.

"Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
news:upQn0K$KEHA.628@.TK2MSFTNGP11.phx.gbl...
> Hi
> I have a ListBox control in my ASP.NET page. After I binding data to this
> control, I would like to be able to change this display order of items in
> this control. Just like change layout function of my.yahoo.com.
> I tried client side approach, yes I can change display order by
JavaScript,
> but after clicking one of the button the display order will reverse back
to
> its original status. Because after PostBack, the page will try to render
> this control by viewstate again.
> I tried server side approach, but looks there is no way to switch two
> ListItems programmatically.
>
> Is there anybody who has some good idea?
> Thanks!
> --
>
> WWW: http://hardywang.1accesshost.com
> ICQ: 3359839
> yours Hardy
How?
--
Joe Fallon

"Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
news:O7ZTxp$KEHA.2244@.tk2msftngp13.phx.gbl...
> I already solved this problem.
>
> "Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
> news:upQn0K$KEHA.628@.TK2MSFTNGP11.phx.gbl...
> > Hi
> > I have a ListBox control in my ASP.NET page. After I binding data to
this
> > control, I would like to be able to change this display order of items
in
> > this control. Just like change layout function of my.yahoo.com.
> > I tried client side approach, yes I can change display order by
> JavaScript,
> > but after clicking one of the button the display order will reverse back
> to
> > its original status. Because after PostBack, the page will try to render
> > this control by viewstate again.
> > I tried server side approach, but looks there is no way to switch two
> > ListItems programmatically.
> > Is there anybody who has some good idea?
> > Thanks!
> > --
> > WWW: http://hardywang.1accesshost.com
> > ICQ: 3359839
> > yours Hardy
Dump content of listbox to array, sort array in memory, then clear this
listbox and add listitem from array one by one.

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
"Joe Fallon" <jfallon1@.nospamtwcny.rr.com> wrote in message
news:%23nd3uPALEHA.3052@.TK2MSFTNGP12.phx.gbl...
> How?
> --
> Joe Fallon
>
> "Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
> news:O7ZTxp$KEHA.2244@.tk2msftngp13.phx.gbl...
> > I already solved this problem.
> > "Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
> > news:upQn0K$KEHA.628@.TK2MSFTNGP11.phx.gbl...
> > > Hi
> > > I have a ListBox control in my ASP.NET page. After I binding data to
> this
> > > control, I would like to be able to change this display order of items
> in
> > > this control. Just like change layout function of my.yahoo.com.
> > > I tried client side approach, yes I can change display order by
> > JavaScript,
> > > but after clicking one of the button the display order will reverse
back
> > to
> > > its original status. Because after PostBack, the page will try to
render
> > > this control by viewstate again.
> > > > I tried server side approach, but looks there is no way to switch two
> > > ListItems programmatically.
> > > > > Is there anybody who has some good idea?
> > > > Thanks!
> > > > --
> > > > > > WWW: http://hardywang.1accesshost.com
> > > ICQ: 3359839
> > > yours Hardy
> >
Yep.
That is what my listbox sort routine does.
Just wondering if you came up with something different.
--
Joe Fallon

"Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
news:uVlWuSFLEHA.3808@.TK2MSFTNGP12.phx.gbl...
> Dump content of listbox to array, sort array in memory, then clear this
> listbox and add listitem from array one by one.
> --
> WWW: http://hardywang.1accesshost.com
> ICQ: 3359839
> yours Hardy
> "Joe Fallon" <jfallon1@.nospamtwcny.rr.com> wrote in message
> news:%23nd3uPALEHA.3052@.TK2MSFTNGP12.phx.gbl...
> > How?
> > --
> > Joe Fallon
> > "Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
> > news:O7ZTxp$KEHA.2244@.tk2msftngp13.phx.gbl...
> > > I already solved this problem.
> > > > > "Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
> > > news:upQn0K$KEHA.628@.TK2MSFTNGP11.phx.gbl...
> > > > Hi
> > > > I have a ListBox control in my ASP.NET page. After I binding data to
> > this
> > > > control, I would like to be able to change this display order of
items
> > in
> > > > this control. Just like change layout function of my.yahoo.com.
> > > > I tried client side approach, yes I can change display order by
> > > JavaScript,
> > > > but after clicking one of the button the display order will reverse
> back
> > > to
> > > > its original status. Because after PostBack, the page will try to
> render
> > > > this control by viewstate again.
> > > > > > I tried server side approach, but looks there is no way to switch
two
> > > > ListItems programmatically.
> > > > > > > > Is there anybody who has some good idea?
> > > > > > Thanks!
> > > > > > --
> > > > > > > > > > WWW: http://hardywang.1accesshost.com
> > > > ICQ: 3359839
> > > > yours Hardy
> > > > > >

Thursday, March 22, 2012

Set javascript value OnCheckedChanged

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.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

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.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 dibled easily with the submit button by adding in it's
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 dibled easily with the submit button by adding in it's
> 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