Thursday, March 29, 2012
OnSelectedIndexChange runs twice
My GridView is partially defined as such:ignore this message - sent it by accident - another one is coming...
thanks...
"VB Programmer" <dont@.emailme.com> wrote in message
news:%23aUWNKgTGHA.1160@.TK2MSFTNGP09.phx.gbl...
> Using 2.0...
> My GridView is partially defined as such:
>
OnSelectedIndexChange runs twice
My GridView is partially defined as such:ignore this message - sent it by accident - another one is coming...
thanks...
"VB Programmer" <dont@.emailme.com> wrote in message
news:%23aUWNKgTGHA.1160@.TK2MSFTNGP09.phx.gbl...
> Using 2.0...
> My GridView is partially defined as such:
OnSelectedIndexChanged does not fire with inherited Page class
onselectedindexchanged is set to a function that never gets called
(checked during debug). This page is subclassed from custom class of
mine that I subclassed from Page.
I have overridden a couple of methods (OnPreRender, OnUnload, OnInit)
to provide for html template layout, all of the base functions are
called as well.
Can anyone lend some help as to why the SelectedIndexChanged event does
not fire when you use a custom Page class? I have to be doing something
in the custom code to prevent the event from firing, I just don't know
where.
Thanks a ton!
StuartAre you binding the dropdownlist in page_load without check for ispostback()
property.
--
-Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
<srallen@.gmail.com> wrote in message
news:1106060697.335855.60130@.c13g2000cwb.googlegro ups.com...
> I have a simple page that has a dropdown with autopostback=true and
> onselectedindexchanged is set to a function that never gets called
> (checked during debug). This page is subclassed from custom class of
> mine that I subclassed from Page.
> I have overridden a couple of methods (OnPreRender, OnUnload, OnInit)
> to provide for html template layout, all of the base functions are
> called as well.
> Can anyone lend some help as to why the SelectedIndexChanged event does
> not fire when you use a custom Page class? I have to be doing something
> in the custom code to prevent the event from firing, I just don't know
> where.
> Thanks a ton!
> Stuart
no, I do a check for IsPostBack with the Bind call...
I've narrowed the problem down some.
By overriding OnPreRender or OnLoad, somehow this causes the event not
to fire.
I moved all my templating code to OnInit and now I can get the event to
fire, its just that my template code is dependent on Session varaibles,
which are changed by the dropdown, so the session object isn't changed
when OnInit is run, only after OnLoad...
frustrated...
Hello Stu,
I've had this happen for me if the Value property is not unique... Make sure
that if you're using ValueMember that each item in your datasource has that
property unique.
--
Matt Berther
http://www.mattberther.com
> I have a simple page that has a dropdown with autopostback=true and
> onselectedindexchanged is set to a function that never gets called
> (checked during debug). This page is subclassed from custom class of
> mine that I subclassed from Page.
> I have overridden a couple of methods (OnPreRender, OnUnload, OnInit)
> to provide for html template layout, all of the base functions are
> called as well.
> Can anyone lend some help as to why the SelectedIndexChanged event
> does not fire when you use a custom Page class? I have to be doing
> something in the custom code to prevent the event from firing, I just
> don't know where.
> Thanks a ton!
> Stuart
Thanks for the suggestion.. that wasn't it... If the set the page that
has the dropdown to use the regular Page class, the event will fire.
I re-worded the problem, perhaps this will help:
Ok here is the situation:
I have inherited System.Web.UI.Page into a custom class for page
templating.
For my template html, I create several LiteralControls and add them to
the controls collection. works fine.
Initially I placed this code in the OnInit method. Works good.
Part of my template code now displays a Session variable, this is part
of the problem.
A page that inherits the custom class has a DropDownList with
autopostback=true and OnSelectedIndexChanged event set to fire.
In the event, I change the value of that Session variable.
But since the template code is calling in OnInit, the page shows the
old session variable, you have to refresh the page to get the page to
show the latest session variable, this is bad.
So, I tried moving my template html controls to another overridable
method, moved it all to OnPreRender.
So, now, my OnSelectedIndexChanged event doesn't fire, b/c the
DropDownList does something screwy with the PreRender method.
So here in summary:
Need custom class to inherit Page class for templating.
Templated HTML material needs access to Session variables. (in what
override should this code live in?)
DropDownList needs to fire SelectedIndexChanged event to change Session
variable.
(how does the prior affect this, where can I put the prior so it
doesn't screw up the event from firing?)
Any ideas?
Hello Stu,
Any possibility you could post the code that you have now that doesnt work?
We may be able to see something there...
--
Matt Berther
http://www.mattberther.com
> I re-worded the problem, perhaps this will help:
> Ok here is the situation:
> I have inherited System.Web.UI.Page into a custom class for page
> templating.
> For my template html, I create several LiteralControls and add them to
> the controls collection. works fine.
> Initially I placed this code in the OnInit method. Works good.
> Part of my template code now displays a Session variable, this is part
> of the problem.
> A page that inherits the custom class has a DropDownList with
> autopostback=true and OnSelectedIndexChanged event set to fire.
> In the event, I change the value of that Session variable.
> But since the template code is calling in OnInit, the page shows the
> old session variable, you have to refresh the page to get the page to
> show the latest session variable, this is bad.
> So, I tried moving my template html controls to another overridable
> method, moved it all to OnPreRender.
> So, now, my OnSelectedIndexChanged event doesn't fire, b/c the
> DropDownList does something screwy with the PreRender method.
> So here in summary:
> Need custom class to inherit Page class for templating.
> Templated HTML material needs access to Session variables. (in what
> override should this code live in?)
> DropDownList needs to fire SelectedIndexChanged event to change
> Session
> variable.
> (how does the prior affect this, where can I put the prior so it
> doesn't screw up the event from firing?)
> Any ideas?
OnSelectedIndexChanged Doesnt work *Resolved*
I have place the following code in a OnSelectedIndexChanged sub..
Here is the code...
Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
LISTBOX2.ITEMS.CLEAR
dim selectstring as string
Dim cn1 As OleDbConnection = New OleDbConnection(ConfigurationSettings.appSettings("connectionstring"))
cn1.Open()
selectString = "select question_id, Question from questions where exam_id = " & listbox1.selecteditem.value
Dim cmd1 As OleDbCommand = New OleDbCommand(selectString, cn1)
Dim reader1 As OleDbDataReader = cmd1.ExecuteReader()
dim liadd as listitem
while(reader1.read())
liadd = new listitem
liadd.text = reader1("question").tostring
liadd.value = reader1("question_id").tostring
listbox2.items.add(liadd)
end while
End Sub
But it doesn't work. As you can see it must refresh the values of a list box, but simply nothing happens...
Is there a mistake somewher ??
ThanksWhat code do you have for the listbox in the HTML source?
Hi,
<asp:ListBox id="ListBox1" runat="server" Width="279px" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged" Height="102px"></asp:ListBox>
You need to set the AutoPostBack property to true.
HTH
DJ
you r right, that was my mistake..
Thanks
OnSelectedIndexChanged does not fire with inherited Page class
onselectedindexchanged is set to a function that never gets called
(checked during debug). This page is subclassed from custom class of
mine that I subclassed from Page.
I have overridden a couple of methods (OnPreRender, OnUnload, OnInit)
to provide for html template layout, all of the base functions are
called as well.
Can anyone lend some help as to why the SelectedIndexChanged event does
not fire when you use a custom Page class? I have to be doing something
in the custom code to prevent the event from firing, I just don't know
where.
Thanks a ton!
StuartAre you binding the dropdownlist in page_load without check for ispostback()
property.
-Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
<srallen@.gmail.com> wrote in message
news:1106060697.335855.60130@.c13g2000cwb.googlegroups.com...
> I have a simple page that has a dropdown with autopostback=true and
> onselectedindexchanged is set to a function that never gets called
> (checked during debug). This page is subclassed from custom class of
> mine that I subclassed from Page.
> I have overridden a couple of methods (OnPreRender, OnUnload, OnInit)
> to provide for html template layout, all of the base functions are
> called as well.
> Can anyone lend some help as to why the SelectedIndexChanged event does
> not fire when you use a custom Page class? I have to be doing something
> in the custom code to prevent the event from firing, I just don't know
> where.
> Thanks a ton!
> Stuart
>
no, I do a check for IsPostBack with the Bind call...
I've narrowed the problem down some.
By overriding OnPreRender or OnLoad, somehow this causes the event not
to fire.
I moved all my templating code to OnInit and now I can get the event to
fire, its just that my template code is dependent on Session varaibles,
which are changed by the dropdown, so the session object isn't changed
when OnInit is run, only after OnLoad...
frustrated...
Hello Stu,
I've had this happen for me if the Value property is not unique... Make sure
that if you're using ValueMember that each item in your datasource has that
property unique.
Matt Berther
http://www.mattberther.com
> I have a simple page that has a dropdown with autopostback=true and
> onselectedindexchanged is set to a function that never gets called
> (checked during debug). This page is subclassed from custom class of
> mine that I subclassed from Page.
> I have overridden a couple of methods (OnPreRender, OnUnload, OnInit)
> to provide for html template layout, all of the base functions are
> called as well.
> Can anyone lend some help as to why the SelectedIndexChanged event
> does not fire when you use a custom Page class? I have to be doing
> something in the custom code to prevent the event from firing, I just
> don't know where.
> Thanks a ton!
> Stuart
Thanks for the suggestion.. that wasn't it... If the set the page that
has the dropdown to use the regular Page class, the event will fire.
I re-worded the problem, perhaps this will help:
Ok here is the situation:
I have inherited System.Web.UI.Page into a custom class for page
templating.
For my template html, I create several LiteralControls and add them to
the controls collection. works fine.
Initially I placed this code in the OnInit method. Works good.
Part of my template code now displays a Session variable, this is part
of the problem.
A page that inherits the custom class has a DropDownList with
autopostback=true and OnSelectedIndexChanged event set to fire.
In the event, I change the value of that Session variable.
But since the template code is calling in OnInit, the page shows the
old session variable, you have to refresh the page to get the page to
show the latest session variable, this is bad.
So, I tried moving my template html controls to another overridable
method, moved it all to OnPreRender.
So, now, my OnSelectedIndexChanged event doesn't fire, b/c the
DropDownList does something screwy with the PreRender method.
So here in summary:
Need custom class to inherit Page class for templating.
Templated HTML material needs access to Session variables. (in what
override should this code live in?)
DropDownList needs to fire SelectedIndexChanged event to change Session
variable.
(how does the prior affect this, where can I put the prior so it
doesn't screw up the event from firing?)
Any ideas?
Hello Stu,
Any possibility you could post the code that you have now that doesnt work?
We may be able to see something there...
Matt Berther
http://www.mattberther.com
> I re-worded the problem, perhaps this will help:
> Ok here is the situation:
> I have inherited System.Web.UI.Page into a custom class for page
> templating.
> For my template html, I create several LiteralControls and add them to
> the controls collection. works fine.
> Initially I placed this code in the OnInit method. Works good.
> Part of my template code now displays a Session variable, this is part
> of the problem.
> A page that inherits the custom class has a DropDownList with
> autopostback=true and OnSelectedIndexChanged event set to fire.
> In the event, I change the value of that Session variable.
> But since the template code is calling in OnInit, the page shows the
> old session variable, you have to refresh the page to get the page to
> show the latest session variable, this is bad.
> So, I tried moving my template html controls to another overridable
> method, moved it all to OnPreRender.
> So, now, my OnSelectedIndexChanged event doesn't fire, b/c the
> DropDownList does something screwy with the PreRender method.
> So here in summary:
> Need custom class to inherit Page class for templating.
> Templated HTML material needs access to Session variables. (in what
> override should this code live in?)
> DropDownList needs to fire SelectedIndexChanged event to change
> Session
> variable.
> (how does the prior affect this, where can I put the prior so it
> doesn't screw up the event from firing?)
> Any ideas?
>
OnSelectedIndexChanged event does not work with the selection on the checkbox ( on the cel
Does the OnSelectedIndexChanged event work when we mark on the checkbox on
the cell of Datagrid control ? I tried to call this event; it didn't
affect anything.
Do you know any event that make the selection on the checkbox work ? Please
give me your advise. ThanksCheck that the 'Handles' clause has not dissapeared...this is a known bug in
VS 2003...happens to me all the time-- really annoying!
"bienwell" wrote:
> Hi,
> Does the OnSelectedIndexChanged event work when we mark on the checkbox on
> the cell of Datagrid control ? I tried to call this event; it didn't
> affect anything.
> Do you know any event that make the selection on the checkbox work ? Please
> give me your advise. Thanks
>
Hi,
Here are my code. Please take a look on it. Thanks
Sub IndexChange_Command(sender As Object, e As EventArgs)
response.write("<BR>Account_ID ==> " &
DGrid_Carrier.SelectedItem.Cells(0).Text)
End Sub
<asp:DataGrid id="DGrid_Carrier" runat="server"
OnSelectedIndexChanged="IndexChange_Command"
OnItemDataBound="DGrid_ItemDataBound" OnItemCommand="DGrid_ItemCommand"
Width="353px" Font-Size="Smaller" Font-Names="Arial" CellSpacing="1"
CellPadding="3" AutoGenerateColumns="False"
================================================== ========
"Mike" <Mike@.discussions.microsoft.com> wrote in message
news:97A4CD58-B902-40D5-BFCD-7BE706B9F272@.microsoft.com...
> Check that the 'Handles' clause has not dissapeared...this is a known bug
in
> VS 2003...happens to me all the time-- really annoying!
> "bienwell" wrote:
> > Hi,
> > Does the OnSelectedIndexChanged event work when we mark on the checkbox
on
> > the cell of Datagrid control ? I tried to call this event; it didn't
> > affect anything.
> > Do you know any event that make the selection on the checkbox work ?
Please
> > give me your advise. Thanks
OnSelectedIndexChanged event does not work with the selection on t
VS 2003...happens to me all the time-- really annoying!
"bienwell" wrote:
> Hi,
> Does the OnSelectedIndexChanged event work when we mark on the checkbox on
> the cell of Datagrid control ? I tried to call this event; it didn't
> affect anything.
> Do you know any event that make the selection on the checkbox work ? Pleas
e
> give me your advise. Thanks
>
>Hi,
Here are my code. Please take a look on it. Thanks
Sub IndexChange_Command(sender As Object, e As EventArgs)
response.write("<BR>Account_ID ==> " &
DGrid_Carrier.SelectedItem.Cells(0).Text)
End Sub
<asp:DataGrid id="DGrid_Carrier" runat="server"
OnSelectedIndexChanged="IndexChange_Command"
OnItemDataBound="DGrid_ItemDataBound" OnItemCommand="DGrid_ItemCommand"
Width="353px" Font-Size="Smaller" Font-Names="Arial" CellSpacing="1"
CellPadding="3" AutoGenerateColumns="False">
========================================
==================
"Mike" <Mike@.discussions.microsoft.com> wrote in message
news:97A4CD58-B902-40D5-BFCD-7BE706B9F272@.microsoft.com...
> Check that the 'Handles' clause has not dissapeared...this is a known bug
in
> VS 2003...happens to me all the time-- really annoying!
> "bienwell" wrote:
>
on
Please
OnSelectedIndexChanged for drop down list?
I have a datagrid that I want to filter by using a drop down list containing categories to use as filters. So in my eventhandler for SelectedIndexChanged I do a select * from my_table where category = myDDL.SelectedItem.Value. (well not literally, but you get the picture)
Problem though is that nothing happens when I select something from the drop down list.
Also! My categories are bound from another db table, however besides getting categories from the db I would also like to add a default "ALL" category. How do I do this?
/RaymondHi!
Have you set the dorpdownlist's autopostback property to "True"?
Hope this helps,
Jeroen
1. if you don't want a button to fire the event, you must add the Autopostback property to the DDL tag and make it equal to "True"
2. if an item in the list is visible, and you click the DDL, choosing the same item, it will not fire
Thx, autopostback works fine.
What about adding a ListItem for the drop down list manually? An ALL item in addition to the ones collected from the db.
/Raymond
MyDDL.items.insert(0,"ALL")
the Zero puts the inserted item at the very top...just call this AFTER the DDL is fully databound
Thx, this works fine.
/Raymond
OnSelectedIndexChanged for a RadioButtonList in a DataGrid
row. It is a simple On & Off.
When the User Clicks on either of the RadioButtons, I need to postback to
the server and update the database.
Here is the control containment hierarchy:
ASP Page
Static User Control // just provides a pretty border around
contained user control
Dynamic User Control
Data Grid:
RadioButtonList: Autopostback = true and
OnSelectedIndexChanged hooked up
When I click on any radio button, I get a SelectedItemChange for each row
that was in the off state and all are now on!
Any ideas?
TIA
GeorgeHi George,
Thanks for posting in the community! My name is Steven, and I'll be
assisting you on this issue.
From your description, you used a RadioButtonList control in a DataGrid's
template column. The RadioButtonList contains two items. "On" and "Off" and
was set as AutoPostBack=True. And you want to do some database
manipulations in the RadioButtonList's SelectIndexChanged postback event,
yes?
If there is anything I misunderstood, please feel free to let me know.
As for this problem, I think you may try the following steps to accomplish
it:
1. Write a event handler function for the RadioButtonList like below:
protected void rblState_SelectedIndexChanged(object sender,
System.EventArgs e)
{
// retrieve the RadionButton's value and the DataGridItem(which contains
the certain RadioButtonList) 's index
// and do some database operations
}
2. Rigister the handler for the RadioButtonList control in the aspx page,
such as:
<asp:RadioButtonList id=rblState runat="server"
OnSelectedIndexChanged="rblState_SelectedIndexChanged" AutoPostBack="True"
SelectedIndex='<%# SetState(DataBinder.Eval(Container.DataItem,"state"))
%>'
To make the above description clearly, I've made a sample page, you may
refer to it if you feel anything unclear:
------------aspx
page---------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>RBL</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table align="center" width="500">
<tr>
<td>
<asp:Label id="lblMessage" runat="server"></asp:Label></td>
</tr>
<tr>
<td>
<asp:DataGrid id="dgRBL" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="index"
HeaderText="Index"></asp:BoundColumn>
<asp:BoundColumn DataField="name"
HeaderText="Name"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="State">
<ItemTemplate>
<FONT face="">
<asp:RadioButtonList id=rblState runat="server"
OnSelectedIndexChanged="rblState_SelectedIndexChanged" AutoPostBack="True"
SelectedIndex='<%# SetState(DataBinder.Eval(Container.DataItem,"state"))
%>'>
<asp:ListItem Value="On">On</asp:ListItem>
<asp:ListItem Value="Off">Off</asp:ListItem>
</asp:RadioButtonList></FONT>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid></td>
</tr>
</table>
</form>
</body>
</HTML>
----------code behind page
class----------
public class RBL : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Web.UI.WebControls.DataGrid dgRBL;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
BindGrid();
}
}
protected void BindGrid()
{
DataTable tb = new DataTable();
tb.Columns.Add("index");
tb.Columns.Add("name");
tb.Columns.Add("state");
for(int i=0;i<15;i++)
{
int index = i+1;
DataRow newrow = tb.NewRow();
newrow["index"] = index.ToString();
newrow["name"] = "Name" + index.ToString();
if(i%2 == 0)
{
newrow["state"] = true;
}
else
{
newrow["state"] = false;
}
tb.Rows.Add(newrow);
}
dgRBL.DataSource = tb;
dgRBL.DataBind();
}
protected void rblState_SelectedIndexChanged(object sender,
System.EventArgs e)
{
RadioButtonList rbl = (RadioButtonList)sender;
Control parent = rbl.Parent;
while(!(parent is System.Web.UI.WebControls.DataGridItem))
{
parent = parent.Parent;
}
int index = ((DataGridItem)parent).ItemIndex;
if(rbl.SelectedIndex == 0)
{
lblMessage.Text = "Row[" + index + "]'s state is changed to On!";
}
else
{
lblMessage.Text = "Row[" + index + "]'s state is changed to Off!";
}
}
protected int SetState(object st)
{
string state = st.ToString();
if(state.Equals("True"))
{
return 0;
}
else
{
return 1;
}
}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
}
---------------
Please check out the preceding suggestions. If you need any further
assistance, please feel free to post here.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Hi George,
Have you had a chance to try out my suggestion or the code or have you got
any progress on this issue? If you have any questions, please feel free to
let me know.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Hi Steven,
Yes, I have looked at your suggestion and it works, but the
production code I'm working on still doesn't. I can't figure out why.
I built a page that is a similar implementation of my production page,
and it works. I can't send you the production code because it relies on
a Business Layer that relies on a Database Layer that relies on an
Oracle Data Source.
Also, I've been working on other projects but now my priority is
this task. I'll let your know how I'm doing and if I have any
questions.
Thanks,
George
"Steven Cheng[MSFT]" <v-schang@.online.microsoft.com> wrote in message
news:V57IEY$5DHA.568@.cpmsftngxa07.phx.gbl...
> Hi George,
>
> Have you had a chance to try out my suggestion or the code or have you got
> any progress on this issue? If you have any questions, please feel free to
> let me know.
>
> Regards,
> Steven Cheng
> Microsoft Online Support
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
OK, found the problem!
In the ItemDataBound Handler of the DataGrid I was setting the Value on both
List Items in the RadioButtonList. In the code sample that Stephen
provided, I noticed he was only setting the Value Attribute of the Item[0].
In my ItemDataBound Handler that was causing me problems, I was doing this:
listItem[0].Value = listItem[1].Value =
myDataRowView.Item["fieldOfInterest"].toString();
changing it to this made the problem go away:
listItem[0].Value = myDataRowView.Item["fieldOfInterest"].toString();
It turns out, the bug goes away if I only set listItem[0]!!!
This doesn't make sense to me! Can anyone explain why this isn't a bug in
the RadioButtonList WebControl??
Thanks,
George
"DotNetGruven" <msdnNoSpam@.javagruven.com> wrote in message
news:e$WxQEd6DHA.3288@.TK2MSFTNGP11.phx.gbl...
> Hi Steven,
> Yes, I have looked at your suggestion and it works, but the
> production code I'm working on still doesn't. I can't figure out why.
> I built a page that is a similar implementation of my production page,
> and it works. I can't send you the production code because it relies on
> a Business Layer that relies on a Database Layer that relies on an
> Oracle Data Source.
> Also, I've been working on other projects but now my priority is
> this task. I'll let your know how I'm doing and if I have any
> questions.
> Thanks,
> George
>
> "Steven Cheng[MSFT]" <v-schang@.online.microsoft.com> wrote in message
> news:V57IEY$5DHA.568@.cpmsftngxa07.phx.gbl...
> > Hi George,
> > Have you had a chance to try out my suggestion or the code or have you
got
> > any progress on this issue? If you have any questions, please feel free
to
> > let me know.
> > Regards,
> > Steven Cheng
> > Microsoft Online Support
> > Get Secure! www.microsoft.com/security
> > (This posting is provided "AS IS", with no warranties, and confers no
> > rights.)
Hi DotNetGruven,
Thanks for your response. I'm glad that you've found out the root cause of
the problem in this issue. As for why the problem will occur when you use
the below code:
listItem[0].Value = listItem[1].Value =
myDataRowView.Item["fieldOfInterest"].toString();
This is because the RadioButtonList will be rendered as a certain group of
<input type=radio ...> into the client browser and the <input tyep=
radio..> ones have the same id. And in html page, certain <input type=radio
..> controls which have the same id(in the same group) can't be set as same
value(every member just the ListIItem on serverside should have a unique
value different from the others in the same group), other wise, there'll
occur unexpected errors. So if you set all the ListItem of a
RadioButtonList as same value, it'll cause the strange behavior you've met.
And when you set them as different value, the error disappears. How do you
think of this?
Please check out my suggestion, if you feel anything unclear on it, please
feel free to let me know.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Thanks for your help with this problem.
It seems that the value attribute of each element should not have to be
different, but if that is the way it works, so be it.
Thanks again,
George
"Steven Cheng[MSFT]" <v-schang@.online.microsoft.com> wrote in message
news:Gqm2KLk6DHA.3496@.cpmsftngxa07.phx.gbl...
> Hi DotNetGruven,
>
> Thanks for your response. I'm glad that you've found out the root cause of
> the problem in this issue. As for why the problem will occur when you use
> the below code:
> listItem[0].Value = listItem[1].Value =
> myDataRowView.Item["fieldOfInterest"].toString();
> This is because the RadioButtonList will be rendered as a certain group of
> <input type=radio ...> into the client browser and the <input tyep=
> radio..> ones have the same id. And in html page, certain <input
type=radio
> .> controls which have the same id(in the same group) can't be set as same
> value(every member just the ListIItem on serverside should have a unique
> value different from the others in the same group), other wise, there'll
> occur unexpected errors. So if you set all the ListItem of a
> RadioButtonList as same value, it'll cause the strange behavior you've
met.
> And when you set them as different value, the error disappears. How do you
> think of this?
> Please check out my suggestion, if you feel anything unclear on it, please
> feel free to let me know.
>
> Regards,
> Steven Cheng
> Microsoft Online Support
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
OnSelectedIndexChanged event not firing on a DropDownList within a DataList
DropDownList control which is in the ItemTemplate of a DataList.
I have made an exact copy of the DropDownList control, and placed it outside
of the DataList and it fires the event just fine. So it's definitely to do
with it being in a template.
I've managed to reproduce the issue on a small test app, the code and html
is below:
Thanks in advance,
Paul
*** Code behind ***
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label output;
protected System.Web.UI.WebControls.DropDownList Dropdownlist1;
protected System.Web.UI.WebControls.DataList DataList1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
ArrayList list = new ArrayList();
list.Add("item1");
list.Add("item2");
list.Add("item3");
DataList1.DataSource = list;
DataList1.DataBind();
}
public void SelectionChanged(object sender, EventArgs e)
{
output.Text = "Changed";
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
*** HTML / ASP ***
<%@dotnet.itags.org. Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="TestBed.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DropDownList ID="Dropdownlist1" Runat="server"
EnableViewState="True" AutoPostBack="True"
OnSelectedIndexChanged="SelectionChanged">
<asp:ListItem Selected="True" Value="1">One</asp:ListItem>
<asp:ListItem Selected="False" Value="2">Two</asp:ListItem>
<asp:ListItem Selected="False" Value="3">Three</asp:ListItem>
</asp:DropDownList>
<asp:DataList id="DataList1" style="Z-INDEX: 101; LEFT: 232px; POSITION:
absolute; TOP: 72px"
runat="server">
<ItemTemplate>
<asp:DropDownList ID="dropDown" Runat="server" EnableViewState="True"
AutoPostBack="True" OnSelectedIndexChanged="SelectionChanged">
<asp:ListItem Selected="True" Value="1">One</asp:ListItem>
<asp:ListItem Selected="False" Value="2">Two</asp:ListItem>
<asp:ListItem Selected="False" Value="3">Three</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:DataList>
<asp:Label id="output" style="Z-INDEX: 102; LEFT: 472px; POSITION:
absolute; TOP: 88px" runat="server">Label</asp:Label>
</form>
</body>
</HTML>My guess is the ID of the dropdownlist is changing between postbacks.
Can you put a breakpoint at the end of your page load and drill down
into the datalist and check the id of the dropdownlist and check where
it is in the control collection. It must be in the same place in the
control tree for restore view state to work, and as you already know
view state has to be enabled for this change event to fire. Also check
enableviewstate on the dropdownlist and every one of its .Parent(s) all
the way to the top. If even one of these is set to false the event
won't be fired.
You should check all this on page postback, not the initial load.
OnSelectedIndexChanged event not firing on a DropDownList within a DataList
DropDownList control which is in the ItemTemplate of a DataList.
I have made an exact copy of the DropDownList control, and placed it outside
of the DataList and it fires the event just fine. So it's definitely to do
with it being in a template.
I've managed to reproduce the issue on a small test app, the code and html
is below:
Thanks in advance,
Paul
*** Code behind ***
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label output;
protected System.Web.UI.WebControls.DropDownList Dropdownlist1;
protected System.Web.UI.WebControls.DataList DataList1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
ArrayList list = new ArrayList();
list.Add("item1");
list.Add("item2");
list.Add("item3");
DataList1.DataSource = list;
DataList1.DataBind();
}
public void SelectionChanged(object sender, EventArgs e)
{
output.Text = "Changed";
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
*** HTML / ASP ***
<%@dotnet.itags.org. Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="TestBed.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DropDownList ID="Dropdownlist1" Runat="server"
EnableViewState="True" AutoPostBack="True"
OnSelectedIndexChanged="SelectionChanged">
<asp:ListItem Selected="True" Value="1">One</asp:ListItem>
<asp:ListItem Selected="False" Value="2">Two</asp:ListItem>
<asp:ListItem Selected="False" Value="3">Three</asp:ListItem>
</asp:DropDownList>
<asp:DataList id="DataList1" style="Z-INDEX: 101; LEFT: 232px; POSITION:
absolute; TOP: 72px"
runat="server">
<ItemTemplate>
<asp:DropDownList ID="dropDown" Runat="server" EnableViewState="True"
AutoPostBack="True" OnSelectedIndexChanged="SelectionChanged">
<asp:ListItem Selected="True" Value="1">One</asp:ListItem>
<asp:ListItem Selected="False" Value="2">Two</asp:ListItem>
<asp:ListItem Selected="False" Value="3">Three</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:DataList>
<asp:Label id="output" style="Z-INDEX: 102; LEFT: 472px; POSITION:
absolute; TOP: 88px" runat="server">Label</asp:Label>
</form>
</body>
</HTMLMy guess is the ID of the dropdownlist is changing between postbacks.
Can you put a breakpoint at the end of your page load and drill down
into the datalist and check the id of the dropdownlist and check where
it is in the control collection. It must be in the same place in the
control tree for restore view state to work, and as you already know
view state has to be enabled for this change event to fire. Also check
enableviewstate on the dropdownlist and every one of its .Parent(s) all
the way to the top. If even one of these is set to false the event
won't be fired.
You should check all this on page postback, not the initial load.
OnSelectedIndexChanged on DDL not working? IE6.0.2 bug?
OnSelectedIndexChanged event is no producing an error in IE6. What concerns
me is that I just performed that large Windows update a couple of w
and it updated ActiveX "stuff" in IE. I'm not sure if the update has
effected IE or there's something wrong with mt .net application.
I have a simple DDL. It calls a sub when the value in the DDL is changed.
Now, when I change the value, IE displays the js error msg box and says:
'event' is null or not an object.Line X, character X.
It gets weird. It refers to a place in my code that makes no sense. There's
no javascript or anything .net generated on line X. Furthermore, I deleted
massive amounts of makr up code as a test. I wanted to see if the reference
to line x changed. I refreshed and tested the page. Same error even though
a 100+ lines of code are now gone (html), it still references to the same
place in my code! The page works fine as it always did in Firefox 1.5.
My simple code:
<asp:DropDownList ID="ddlCapitalItems" runat="server" BackColor="#FFFFFF"
Font-Names="Verdana,Arial" Font-Size="8pt" AutoPostBack="True"
OnSelectedIndexChanged="ddlCapitalItems_SelectedIndexChange" />
Protected Sub ddlCapitalItems_SelectedIndexChange(ByVa
l Sender As Object,
ByVal E As EventArgs)
'----
--
'- This sub routine is called when the Capital Items Drop Down List is
changed. -
'- If checks to see if the user selected "Other" and if so, it will enable
the -
'- the txtOtherDesc control and related validation controls. -
'----
--
If ddlCapitalItems.SelectedValue = 1 Then
txtOtherDesc.Enabled = True
txtOtherDesc.Text = ""
OtherDescRequired.Enabled = True
Else
txtOtherDesc.Enabled = False
txtOtherDesc.Text = "Not Required"
OtherDescRequired.Enabled = False
End If
End Subto add additional info. I tested my page on someone else's PC with IE6 and
it fails there too. Make me think it is not the Windows update but rather
my application. I whipped up a quick test page like below and it works
fine.
Any ideas' Thanks!
<%@. Page Language="VB" %>
<script runat="server">
Protected Sub DropDownList1_SelectedIndexChanged(ByVal
sender As Object,
ByVal e As System.EventArgs)
Label1.Text = DropDownList1.SelectedValue
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form runat="server">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
<br />
<br />
<asp:DropDownList ID="DropDownList1" runat="server"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="true">
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
</asp:DropDownList>
</form>
</body>
</html>
"Groove" <noway@.noemail.com> wrote in message
news:O5tywxdeGHA.1264@.TK2MSFTNGP05.phx.gbl...
>I have a strange problem. It seems that for some reason, a
>OnSelectedIndexChanged event is no producing an error in IE6. What
>concerns me is that I just performed that large Windows update a couple of
>w
>has effected IE or there's something wrong with mt .net application.
> I have a simple DDL. It calls a sub when the value in the DDL is changed.
> Now, when I change the value, IE displays the js error msg box and says:
> 'event' is null or not an object.Line X, character X.
> It gets weird. It refers to a place in my code that makes no sense.
> There's no javascript or anything .net generated on line X. Furthermore,
> I deleted massive amounts of makr up code as a test. I wanted to see if
> the reference to line x changed. I refreshed and tested the page. Same
> error even though a 100+ lines of code are now gone (html), it still
> references to the same place in my code! The page works fine as it always
> did in Firefox 1.5.
> My simple code:
> <asp:DropDownList ID="ddlCapitalItems" runat="server" BackColor="#FFFFFF"
> Font-Names="Verdana,Arial" Font-Size="8pt" AutoPostBack="True"
> OnSelectedIndexChanged="ddlCapitalItems_SelectedIndexChange" />
>
>
> Protected Sub ddlCapitalItems_SelectedIndexChange(ByVa
l Sender As Object,
> ByVal E As EventArgs)
> '----
--
> '- This sub routine is called when the Capital Items Drop Down List is
> changed. -
> '- If checks to see if the user selected "Other" and if so, it will enable
> the -
> '- the txtOtherDesc control and related validation controls. -
> '----
--
>
> If ddlCapitalItems.SelectedValue = 1 Then
> txtOtherDesc.Enabled = True
> txtOtherDesc.Text = ""
> OtherDescRequired.Enabled = True
> Else
> txtOtherDesc.Enabled = False
> txtOtherDesc.Text = "Not Required"
> OtherDescRequired.Enabled = False
> End If
>
> End Sub
>
>
>
OnSelectedIndexChanged on DDL not working? IE6.0.2 bug?
OnSelectedIndexChanged event is no producing an error in IE6. What concerns
me is that I just performed that large Windows update a couple of weeks ago
and it updated ActiveX "stuff" in IE. I'm not sure if the update has
effected IE or there's something wrong with mt .net application.
I have a simple DDL. It calls a sub when the value in the DDL is changed.
Now, when I change the value, IE displays the js error msg box and says:
'event' is null or not an object.Line X, character X.
It gets weird. It refers to a place in my code that makes no sense. There's
no javascript or anything .net generated on line X. Furthermore, I deleted
massive amounts of makr up code as a test. I wanted to see if the reference
to line x changed. I refreshed and tested the page. Same error even though
a 100+ lines of code are now gone (html), it still references to the same
place in my code! The page works fine as it always did in Firefox 1.5.
My simple code:
<asp:DropDownList ID="ddlCapitalItems" runat="server" BackColor="#FFFFFF"
Font-Names="Verdana,Arial" Font-Size="8pt" AutoPostBack="True"
OnSelectedIndexChanged="ddlCapitalItems_SelectedIndexChange" /
Protected Sub ddlCapitalItems_SelectedIndexChange(ByVal Sender As Object,
ByVal E As EventArgs)
'--------------------------
'- This sub routine is called when the Capital Items Drop Down List is
changed. -
'- If checks to see if the user selected "Other" and if so, it will enable
the -
'- the txtOtherDesc control and related validation controls. -
'--------------------------
If ddlCapitalItems.SelectedValue = 1 Then
txtOtherDesc.Enabled = True
txtOtherDesc.Text = ""
OtherDescRequired.Enabled = True
Else
txtOtherDesc.Enabled = False
txtOtherDesc.Text = "Not Required"
OtherDescRequired.Enabled = False
End If
End Subto add additional info. I tested my page on someone else's PC with IE6 and
it fails there too. Make me think it is not the Windows update but rather
my application. I whipped up a quick test page like below and it works
fine.
Any ideas?? Thanks!
<%@. Page Language="VB" %
<script runat="server"
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs)
Label1.Text = DropDownList1.SelectedValue
End Sub
</script
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
<title>Untitled Page</title
</head
<body
<form runat="server"
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br /
<br /
<br /
<asp:DropDownList ID="DropDownList1" runat="server"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="true"
<asp:ListItem>Red</asp:ListItem
<asp:ListItem>Blue</asp:ListItem
</asp:DropDownList
</form
</body
</html
"Groove" <noway@.noemail.com> wrote in message
news:O5tywxdeGHA.1264@.TK2MSFTNGP05.phx.gbl...
>I have a strange problem. It seems that for some reason, a
>OnSelectedIndexChanged event is no producing an error in IE6. What
>concerns me is that I just performed that large Windows update a couple of
>weeks ago and it updated ActiveX "stuff" in IE. I'm not sure if the update
>has effected IE or there's something wrong with mt .net application.
> I have a simple DDL. It calls a sub when the value in the DDL is changed.
> Now, when I change the value, IE displays the js error msg box and says:
> 'event' is null or not an object.Line X, character X.
> It gets weird. It refers to a place in my code that makes no sense.
> There's no javascript or anything .net generated on line X. Furthermore,
> I deleted massive amounts of makr up code as a test. I wanted to see if
> the reference to line x changed. I refreshed and tested the page. Same
> error even though a 100+ lines of code are now gone (html), it still
> references to the same place in my code! The page works fine as it always
> did in Firefox 1.5.
> My simple code:
> <asp:DropDownList ID="ddlCapitalItems" runat="server" BackColor="#FFFFFF"
> Font-Names="Verdana,Arial" Font-Size="8pt" AutoPostBack="True"
> OnSelectedIndexChanged="ddlCapitalItems_SelectedIndexChange" />
>
>
> Protected Sub ddlCapitalItems_SelectedIndexChange(ByVal Sender As Object,
> ByVal E As EventArgs)
> '--------------------------
> '- This sub routine is called when the Capital Items Drop Down List is
> changed. -
> '- If checks to see if the user selected "Other" and if so, it will enable
> the -
> '- the txtOtherDesc control and related validation controls. -
> '--------------------------
>
> If ddlCapitalItems.SelectedValue = 1 Then
> txtOtherDesc.Enabled = True
> txtOtherDesc.Text = ""
> OtherDescRequired.Enabled = True
> Else
> txtOtherDesc.Enabled = False
> txtOtherDesc.Text = "Not Required"
> OtherDescRequired.Enabled = False
> End If
>
> End Sub
>
>
OnSelectedIndexChanged not firing
event when it should. I also have a submit button on my page, and
when it is clicked, it does fire the selectedindexchanged event of the
dropdownlist. What am I doing wrong?
mbcbb:combobox is a user control combining the funcitonality of a
dropdownlist and a textbox.
aspx
<mbcbb:combobox
Runat="Server"
id="cmbmyCombo"
DataTextField="myValue"
DataValueField="myValue"
DataSource='<%# GetDropDownSource("sel_LookupMyValue", "**", "") %>'
OnSelectedIndexChanged="mySelIndexChanged"
AutoPostBack="True"
aspx.vb
Protected Sub mySelIndexChanged(sender as object, e as
System.EventArgs)
response.write("Text")
End Sub
Thanks in advance
Julie Barnetmissing handles?
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged
End Sub
"Julie Barnet" <barnetj@.pr.fraserpapers.com> wrote in message
news:438e1811.0308201052.7cea3f4a@.posting.google.c om...
> I have a dropdownlist. It does not fire the selected index changed
> event when it should. I also have a submit button on my page, and
> when it is clicked, it does fire the selectedindexchanged event of the
> dropdownlist. What am I doing wrong?
> mbcbb:combobox is a user control combining the funcitonality of a
> dropdownlist and a textbox.
> aspx
> <mbcbb:combobox
> Runat="Server"
> id="cmbmyCombo"
> DataTextField="myValue"
> DataValueField="myValue"
> DataSource='<%# GetDropDownSource("sel_LookupMyValue", "**", "") %>'
> OnSelectedIndexChanged="mySelIndexChanged"
> AutoPostBack="True" >
> aspx.vb
> Protected Sub mySelIndexChanged(sender as object, e as
> System.EventArgs)
> response.write("Text")
> End Sub
> Thanks in advance
> Julie Barnet
Hi,
Make sure AutoEventWireup attribute of your Contol directive is set to
true. Hope it will work.
--
Regards,
Yusuf D M
"Julie Barnet" <barnetj@.pr.fraserpapers.com> wrote in message
news:438e1811.0308201052.7cea3f4a@.posting.google.c om...
> I have a dropdownlist. It does not fire the selected index changed
> event when it should. I also have a submit button on my page, and
> when it is clicked, it does fire the selectedindexchanged event of the
> dropdownlist. What am I doing wrong?
> mbcbb:combobox is a user control combining the funcitonality of a
> dropdownlist and a textbox.
> aspx
> <mbcbb:combobox
> Runat="Server"
> id="cmbmyCombo"
> DataTextField="myValue"
> DataValueField="myValue"
> DataSource='<%# GetDropDownSource("sel_LookupMyValue", "**", "") %>'
> OnSelectedIndexChanged="mySelIndexChanged"
> AutoPostBack="True" >
> aspx.vb
> Protected Sub mySelIndexChanged(sender as object, e as
> System.EventArgs)
> response.write("Text")
> End Sub
> Thanks in advance
> Julie Barnet
OnSelectedIndexChanged runs twice!
My GridView is partially defined as such...
<asp:GridView ID="CartGrid" AutoGenerateColumns="False"
DataKeyNames="ID" OnSelectedIndexChanged="RemoveCartItem"
CellPadding="4" runat="Server"
ForeColor="Gray" GridLines="None" Width="90%"
BorderStyle="Inset"
BorderWidth="1px" Caption="Shopping Cart" Font-Bold="False"
CaptionAlign="Left">
<Columns>
<asp:ButtonField
CommandName="select" Text="Remove" />
<asp:BoundField
DataField="Name" HeaderText="Name">
<ControlStyle
Width="300px" />
<ItemStyle Width="300px"
/>
As you can see, when the user clicks "Remove" it runs the "RemoveCartItem"
function, defined as such...
Sub RemoveCartItem(ByVal s As Object, ByVal e As EventArgs) Handles
CartGrid.SelectedIndexChanged
Dim ID As String = CartGrid.SelectedDataKey.Value
Profile.MyShoppingCart.RemoveItem(ID)
BindShoppingCart()
End Sub
Sub BindShoppingCart()
If Not Profile.MyShoppingCart Is Nothing Then
CartGrid.DataSource = Profile.MyShoppingCart.CartItems
CartGrid.DataBind()
lblTotal.Text = Profile.MyShoppingCart.Total.ToString("c")
BindShippingDdl()
End If
End Sub
I put a breakpoint on RemoveCartItem and the code is running twice each
time. Any ideas why?
Thanks!hmm Good you noticed that
Patrick
"VB Programmer" <dont@.emailme.com> wrote in message
news:u3vqAAhTGHA.4132@.TK2MSFTNGP11.phx.gbl...
> Got it! I removed "Handles CartGrid.SelectedIndexChanged" from
> RemoveCartItem and it works. It was calling twice, once from the dg and
> once from the SelectedIndexChanged event I suppose.
> "VB Programmer" <dont@.emailme.com> wrote in message
> news:ufz0LcgTGHA.4264@.TK2MSFTNGP11.phx.gbl...
>
OnSelectedIndexChanged runs twice!
My GridView is partially defined as such...
<asp:GridView ID="CartGrid" AutoGenerateColumns="False"
DataKeyNames="ID" OnSelectedIndexChanged="RemoveCartItem"
CellPadding="4" runat="Server"
ForeColor="Gray" GridLines="None" Width="90%"
BorderStyle="Inset"
BorderWidth="1px" Caption="Shopping Cart" Font-Bold="False"
CaptionAlign="Left">
<Columns>
<asp:ButtonField
CommandName="select" Text="Remove" />
<asp:BoundField
DataField="Name" HeaderText="Name">
<ControlStyle
Width="300px" />
<ItemStyle Width="300px"
/
As you can see, when the user clicks "Remove" it runs the "RemoveCartItem"
function, defined as such...
Sub RemoveCartItem(ByVal s As Object, ByVal e As EventArgs) Handles
CartGrid.SelectedIndexChanged
Dim ID As String = CartGrid.SelectedDataKey.Value
Profile.MyShoppingCart.RemoveItem(ID)
BindShoppingCart()
End Sub
Sub BindShoppingCart()
If Not Profile.MyShoppingCart Is Nothing Then
CartGrid.DataSource = Profile.MyShoppingCart.CartItems
CartGrid.DataBind()
lblTotal.Text = Profile.MyShoppingCart.Total.ToString("c")
BindShippingDdl()
End If
End Sub
I put a breakpoint on RemoveCartItem and the code is running twice each
time. Any ideas why?
Thanks!FYI: Even AFTER I comment out the BindShoppingCart call it still calls
RemoveCartItem twice...
Any ideas?
"VB Programmer" <dont@.emailme.com> wrote in message
news:uSNTaLgTGHA.4264@.TK2MSFTNGP11.phx.gbl...
> Using ASP.NET 2.0...
> My GridView is partially defined as such...
> <asp:GridView ID="CartGrid" AutoGenerateColumns="False"
> DataKeyNames="ID" OnSelectedIndexChanged="RemoveCartItem"
> CellPadding="4" runat="Server"
> ForeColor="Gray" GridLines="None" Width="90%"
> BorderStyle="Inset"
> BorderWidth="1px" Caption="Shopping Cart" Font-Bold="False"
> CaptionAlign="Left">
> <Columns>
> <asp:ButtonField
> CommandName="select" Text="Remove" />
> <asp:BoundField
> DataField="Name" HeaderText="Name">
> <ControlStyle
> Width="300px" />
> <ItemStyle
> Width="300px" />
> As you can see, when the user clicks "Remove" it runs the "RemoveCartItem"
> function, defined as such...
> Sub RemoveCartItem(ByVal s As Object, ByVal e As EventArgs) Handles
> CartGrid.SelectedIndexChanged
> Dim ID As String = CartGrid.SelectedDataKey.Value
> Profile.MyShoppingCart.RemoveItem(ID)
> BindShoppingCart()
> End Sub
> Sub BindShoppingCart()
> If Not Profile.MyShoppingCart Is Nothing Then
> CartGrid.DataSource = Profile.MyShoppingCart.CartItems
> CartGrid.DataBind()
> lblTotal.Text = Profile.MyShoppingCart.Total.ToString("c")
> BindShippingDdl()
> End If
> End Sub
> I put a breakpoint on RemoveCartItem and the code is running twice each
> time. Any ideas why?
> Thanks!
Got it! I removed "Handles CartGrid.SelectedIndexChanged" from
RemoveCartItem and it works. It was calling twice, once from the dg and
once from the SelectedIndexChanged event I suppose.
"VB Programmer" <dont@.emailme.com> wrote in message
news:ufz0LcgTGHA.4264@.TK2MSFTNGP11.phx.gbl...
> FYI: Even AFTER I comment out the BindShoppingCart call it still calls
> RemoveCartItem twice...
> Any ideas?
> "VB Programmer" <dont@.emailme.com> wrote in message
> news:uSNTaLgTGHA.4264@.TK2MSFTNGP11.phx.gbl...
>> Using ASP.NET 2.0...
>>
>> My GridView is partially defined as such...
>>
>> <asp:GridView ID="CartGrid" AutoGenerateColumns="False"
>> DataKeyNames="ID" OnSelectedIndexChanged="RemoveCartItem"
>> CellPadding="4" runat="Server"
>> ForeColor="Gray" GridLines="None" Width="90%"
>> BorderStyle="Inset"
>> BorderWidth="1px" Caption="Shopping Cart" Font-Bold="False"
>> CaptionAlign="Left">
>> <Columns>
>> <asp:ButtonField
>> CommandName="select" Text="Remove" />
>> <asp:BoundField
>> DataField="Name" HeaderText="Name">
>> <ControlStyle
>> Width="300px" />
>> <ItemStyle
>> Width="300px" />
>>
>> As you can see, when the user clicks "Remove" it runs the
>> "RemoveCartItem" function, defined as such...
>>
>> Sub RemoveCartItem(ByVal s As Object, ByVal e As EventArgs) Handles
>> CartGrid.SelectedIndexChanged
>> Dim ID As String = CartGrid.SelectedDataKey.Value
>> Profile.MyShoppingCart.RemoveItem(ID)
>> BindShoppingCart()
>> End Sub
>> Sub BindShoppingCart()
>> If Not Profile.MyShoppingCart Is Nothing Then
>> CartGrid.DataSource = Profile.MyShoppingCart.CartItems
>> CartGrid.DataBind()
>> lblTotal.Text = Profile.MyShoppingCart.Total.ToString("c")
>> BindShippingDdl()
>> End If
>> End Sub
>>
>> I put a breakpoint on RemoveCartItem and the code is running twice each
>> time. Any ideas why?
>>
>> Thanks!
>>
>>
hmm Good you noticed that
Patrick
"VB Programmer" <dont@.emailme.com> wrote in message
news:u3vqAAhTGHA.4132@.TK2MSFTNGP11.phx.gbl...
> Got it! I removed "Handles CartGrid.SelectedIndexChanged" from
> RemoveCartItem and it works. It was calling twice, once from the dg and
> once from the SelectedIndexChanged event I suppose.
> "VB Programmer" <dont@.emailme.com> wrote in message
> news:ufz0LcgTGHA.4264@.TK2MSFTNGP11.phx.gbl...
>> FYI: Even AFTER I comment out the BindShoppingCart call it still calls
>> RemoveCartItem twice...
>>
>> Any ideas?
>>
>> "VB Programmer" <dont@.emailme.com> wrote in message
>> news:uSNTaLgTGHA.4264@.TK2MSFTNGP11.phx.gbl...
>>> Using ASP.NET 2.0...
>>>
>>> My GridView is partially defined as such...
>>>
>>> <asp:GridView ID="CartGrid" AutoGenerateColumns="False"
>>> DataKeyNames="ID" OnSelectedIndexChanged="RemoveCartItem"
>>> CellPadding="4"
>>> runat="Server" ForeColor="Gray" GridLines="None" Width="90%"
>>> BorderStyle="Inset"
>>> BorderWidth="1px" Caption="Shopping Cart" Font-Bold="False"
>>> CaptionAlign="Left">
>>> <Columns>
>>> <asp:ButtonField
>>> CommandName="select" Text="Remove" />
>>> <asp:BoundField
>>> DataField="Name" HeaderText="Name">
>>> <ControlStyle
>>> Width="300px" />
>>> <ItemStyle
>>> Width="300px" />
>>>
>>> As you can see, when the user clicks "Remove" it runs the
>>> "RemoveCartItem" function, defined as such...
>>>
>>> Sub RemoveCartItem(ByVal s As Object, ByVal e As EventArgs) Handles
>>> CartGrid.SelectedIndexChanged
>>> Dim ID As String = CartGrid.SelectedDataKey.Value
>>> Profile.MyShoppingCart.RemoveItem(ID)
>>> BindShoppingCart()
>>> End Sub
>>> Sub BindShoppingCart()
>>> If Not Profile.MyShoppingCart Is Nothing Then
>>> CartGrid.DataSource = Profile.MyShoppingCart.CartItems
>>> CartGrid.DataBind()
>>> lblTotal.Text = Profile.MyShoppingCart.Total.ToString("c")
>>> BindShippingDdl()
>>> End If
>>> End Sub
>>>
>>> I put a breakpoint on RemoveCartItem and the code is running twice each
>>> time. Any ideas why?
>>>
>>> Thanks!
>>>
>>>
>>
>>
OnSelectedIndexChanged pass value in querystring
I have a method that fires when the dropdown list event OnSelectedIndexChanged is invoked.
When the page redirects it doesn't pass the id value? The url only shows:
http://localhost/Lobbyist/statedetails.aspx?id=
So, the value isn't passed.
I set a break point and the watch window indicates that the id variable is 0?
Here is the code in my aspx page:
<asp:DropDownList ID="state" runat="server" OnSelectedIndexChanged="state_SelectedIndexChanged" AutoPostBack="True"></asp:DropDownList>
Here is the code-behind:
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
state.DataSource = StateDAO.GetStateList();
state.DataValueField = "PK";
state.DataTextField = "name";
state.DataBind();
state.Items.Insert(0, new ListItem("-- Please Select --", ""));
}
protected void state_SelectedIndexChanged(object sender, EventArgs e)
{
string id = state.SelectedValue.ToString();
if (id != "0")
{
Response.Redirect("~/statedetails.aspx?id=" + id);
}
}
}
What am I missing? How can I pass the id value? I don't understand why the value isn't passed.
Any help is appreciated.
Thanks.
Page_Load will fire before the OnSelectedIndexChanged event will fire, so the DropDownList is being re-databound and the selected value is being lost.
Only bind the DropDownList the first time a page is loaded, and not on a post
in Page_Load the code should be
If ( ! Page.IsPostBack)
{
state.DataSource = StateDAO.GetStateList();
state.DataValueField = "PK";
state.DataTextField = "name";
state.DataBind();
state.Items.Insert(0, new ListItem("-- Please Select --", ""));
}
Thank you Steve...that corrected the problem.
Regards.
OnServerValidate
1 to bring up a calendar. On the page I also have a custom validator
which calls a procedure via OnServerValidate.
The problem I have is that pressing the other button also triggers the
OnServerValidate. Does anybody know how I can stop this from happening?
Thanks,
Mike
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!"Mike P" <mrp@.telcoelectronics.co.uk> wrote in message
news:eIZyPSWmDHA.2268@.TK2MSFTNGP12.phx.gbl...
> I have 2 buttons on my ASP.NET page, one to Submit the user details and
> 1 to bring up a calendar. On the page I also have a custom validator
> which calls a procedure via OnServerValidate.
> The problem I have is that pressing the other button also triggers the
> OnServerValidate. Does anybody know how I can stop this from happening?
>
> Thanks,
> Mike
Property: CausesValidation = false
on the "calendar button"
You need to set the CausesValidation Property of the button object.
It should do the trick for you.
--
Patrik Lwendahl
cshrp.net - ' Elegant code by witty programmers '
cornerstone.se - ' IT Training for proffesionals '
"Mike P" <mrp@.telcoelectronics.co.uk> wrote in message
news:eIZyPSWmDHA.2268@.TK2MSFTNGP12.phx.gbl...
> I have 2 buttons on my ASP.NET page, one to Submit the user details and
> 1 to bring up a calendar. On the page I also have a custom validator
> which calls a procedure via OnServerValidate.
> The problem I have is that pressing the other button also triggers the
> OnServerValidate. Does anybody know how I can stop this from happening?
>
> Thanks,
> Mike
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Thanks!
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
OnServerClick problems
When i use the OnServerClick method within my anchor control it gives an "error on page" when i click the link.
This is my this anchor code
<a
id="Anchor1"
OnServerClick="Anchor1_Click"
runat="server"
Row Count
</a
And this is the sub it refers to
Sub Anchor1_Click(Source as Object, E as EventArgs)
Anchor1.InnerHtml = "Table 1: " & Table1.Rows.Count _
& " rows - Table 2: " & Table2.Rows.Count & " rows"
End Sub
Why is isn't this working?
Thanks in advance
Paul WiggersThere is no OnServerClick, you have to use OnClick for server side sub calls!
ok i have changed the OnServerClick to OnClick. But right now the text between the <a></a> tags isn't a link anymore, it's just plain text.
What to do about that?
And can you please explain why there isn't an OnServerClick? I thought that was used when you posted towards the same page.
TIA
Paul Wiggers
OnServerClick should work Ok as you're using a HtmlControls.HtmlAnchor object/class rather than a web control.
Is your <a tag inside <form runat="server" tags? If not then this could be your problem.
OOps, I thought he is using server side control, Yes, it should work as he said!
great, thanks for your help. Works perfectly now.
Still don't understand why I couldn't think of that. ah well, learn something new everyday ;)
thanks again
Onserverclick event not running (inc. Code)
I am trying to run both client and server events when clicking a button.
Since the code i wrote i tried this enclosed code as a test but it won't work please tell me what i'm doing wrong:
(P.S. I posted the browser source as there is almost no code behind and this, i think, shows more details)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm4</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"
</HEAD>
<body MS_POSITIONING="GridLayout">
<form name="Form1" method="post" action="WebForm4.aspx" id="Form1">
<input type="hidden" name="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" value="dDwxOTI0MjI4NTEyOzs+hLaPGDf9/EXBiKS+L6TBywF4Aw4=" /
<script language="javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
theform = document.forms["Form1"];
}
else {
theform = document.Form1;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
// -->
</script
<input language="javascript" onclick="Javascript: return test(); __doPostBack('Button1','')" name="Button1" id="Button1" type="button" style="Z-INDEX: 101; LEFT: 248px; POSITION: absolute; TOP: 120px" value="Button" />
</form>
<script language="javascript">
function test() {
alert("hi!");
}
</script>
</body>
</HTML
TIA,
GK582Hi,
Can I know how it won't work? Client script not run and server code not run?
The scenario should work, but I can't repro your problem. May I see you sample code? Is it a VS project or just a plain single ASPX page?
Thanks
Yugang
The following code snippet works for me. If you use code behind model, you need to paste client script into aspx file and move server script code to code behind file
<%@. Page Language="VB" %>
<script runat="server">
Sub Page_Load()
if not Page.ispostback then
button1.attributes.add("onclick", "Javascript: return test();")
end if
end sub
Sub button_click(byval sender as object, byval e as System.EventArgs)
REsponse.write("<h1>post back</h1>")
end sub
</script>
<script language="javascript">
function test() {
alert("hi!");
}
</script>
<html>
<body>
<form id="form1" runat=server>
<asp:button runat=server id=button1 text="button1" name=button1 onclick="button_click"></asp:button>
</form>
</body>
</html>
OnServerValidate not working?
.aspx file
<code>
<td class="label2" width="510"><strong>(Title):</strong> <asp:dropdownlist id="selConTitle" Runat="server" Width="140" Enabled="False" BackColor="#dcdcdc">
<asp:ListItem Value="" text="" Selected="True" />
<asp:ListItem Value="Title1" text="Title1" />
<asp:ListItem Value="Title2" text="Title2" />
<asp:ListItem Value="Title3" text="Title3" />
</asp:dropdownlist><asp:CustomValidator ID="custConTitle" Display="Dynamic" ControlToValidate="selConTitle" OnServerValidate="subConTitle"
Runat="server">*</asp:CustomValidator>
</td>
</code>
code behind in VB.NET
<code>
Public Sub subConTitle(ByVal objSource As Object, ByVal objArgs As ServerValidateEventArgs)
If Me.chkConOfficer.Checked Then
If Len(Me.selConTitle.SelectedValue) < 1 Then
Me.custConTitle.ErrorMessage = "You must select a title for the Officer of the Corporation."
objArgs.IsValid = False
Else
objArgs.IsValid = True
End If
End If
End Sub
</code>
For whatever reason the sub subConTitle is not being hit??
Anyone have any ideas ?
thanks,
-=angst=-It may be because your drop down list isn't enabled (even if you enable somewhere in code behind).
Try setting Enabled=True for the control by default and see if that works.
I tried that but no cigar! :(
Well, I haven't used validator controls before, so I'm not entirely sure.
One question however - when are you expecting the validation to takeplace, i.e. what event is causing the post-back? Do you have abutton that you use to submit the form or are you using some othermethod?
Thanks,
Tyler
By design, the CustomValidator does not get run when the control assigned to ControlToValidate has a blank value. Your first item in the list has a blank value. So expect it not to fire when set to that first item.
You can override this by NOT setting ControlToValidate and inside your evaluation function, directly use the listbox object.
Since you are trying to detect a blank item in the list box, you can actually use the RequiredFieldValidator. Just be sure that its InitialValue property is set to the same value as the blank item (which is "" in this case).
CustomValidator's OnServerValidate occurs only when
1. the control causing postback has 'CausesValidation' set to True.
2. if 'ControlToValidate' property of CustomValidator is set to control's name then its value must not be empty.
TylerFree: Yes a button is what submits the form.
PLBlum: your a genius. That indeed was the issue. I have other pages doing similar validation and it works because their values were set to something like 0 or 1. I just tossed a 0 in there and it works just fine!!! :)
Thank you so much. You just saved me a lot of time!
-=angst=-
p.s. I love this forum
p.p.s. "anger is a gift"
OnSessionStart or IsNewSession
2.0.
and another problem, the property IsNewSession is still true and it seems
like the session is new with each client request.
The session ID is changing too.
Any idea how to use this correctly (session will be IsNewSession=true only
with first request and the session will keep this for 20 minutes)
ThanksI put the Global.asax into my application and the IsNewSession is working
well.
"Mirek Endys" <MirekE@.community.nospam> wrote in message
news:eYulLdSPGHA.3264@.TK2MSFTNGP11.phx.gbl...
>I miss the information about using an event like OnSessionStart in ASP.NET
>2.0.
> and another problem, the property IsNewSession is still true and it seems
> like the session is new with each client request.
> The session ID is changing too.
> Any idea how to use this correctly (session will be IsNewSession=true only
> with first request and the session will keep this for 20 minutes)
> Thanks
Hi Mirek,
Thanks for posting.
As for the ASP.NET sessionstate, when the user hasn't stored any data in
the session, on each request, the runtime could assigned a random sessionid
to it (since no data store associated with it). And this is determined by
the internal implementation, at least for 1.1 , it follows such rule. And
here is a good FAQ article discusing on ASP.NET SessionState:
#ASP.NET Session State FAQ
http://www.eggheadcafe.com/articles/20021016.asp
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
OnSessionStart or IsNewSession
2.0.
and another problem, the property IsNewSession is still true and it seems
like the session is new with each client request.
The session ID is changing too.
Any idea how to use this correctly (session will be IsNewSession=true only
with first request and the session will keep this for 20 minutes)
ThanksI put the Global.asax into my application and the IsNewSession is working
well.
"Mirek Endys" <MirekE@.community.nospam> wrote in message
news:eYulLdSPGHA.3264@.TK2MSFTNGP11.phx.gbl...
>I miss the information about using an event like OnSessionStart in ASP.NET
>2.0.
> and another problem, the property IsNewSession is still true and it seems
> like the session is new with each client request.
> The session ID is changing too.
> Any idea how to use this correctly (session will be IsNewSession=true only
> with first request and the session will keep this for 20 minutes)
> Thanks
>
Hi Mirek,
Thanks for posting.
As for the ASP.NET sessionstate, when the user hasn't stored any data in
the session, on each request, the runtime could assigned a random sessionid
to it (since no data store associated with it). And this is determined by
the internal implementation, at least for 1.1 , it follows such rule. And
here is a good FAQ article discusing on ASP.NET SessionState:
#ASP.NET Session State FAQ
http://www.eggheadcafe.com/articles/20021016.asp
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
onsubmit Event in aspx page.
I'm trying to do some client side validation before sumbitting a form. I
added an onclick attribute to the submit button (<asp:Button> control) and
the source of the page looks ok on the client. In the function that is calle
d
by the onclick I do window.event.cancelBubble = true;
hoping that this will stop submitting the form, but the form is still
submitted (I'm assuming that onclick event is fired before the onsumbit
event).
Is it possible to cancel the submition of the form?
Thank you"Vi" <Vi@.discussions.microsoft.com> wrote in message
news:92A6FBE7-B7B1-4EF5-B12F-E5C4AC8535AB@.microsoft.com...
> Is it possible to cancel the submition of the form?
<script>
function validateForm()
{
if (<some validation check> == false)
{
return false;
}
else
{
document.forms[0].submit();
}
}
</script>
onSubmit called by all of my Imagebuttons
I have a few ImageButton controls on my form. One of them is the save
one, on which I want the form to be submited. Other imageButtons
trigger a postback, but they should not cause form validation on the
client side, meaning the OnSubmit property of the Form should not be
triggered. At the moment all of them trigger this property. How can I
prevent that from happening ?
ThanksSet the CausesValidation property to false to prevent a control from
causing validation.
You can't prevent the onsubmit event, that is always triggered when a
form is posted.
graphicsxp wrote:
Quote:
Originally Posted by
Hi,
>
I have a few ImageButton controls on my form. One of them is the save
one, on which I want the form to be submited. Other imageButtons
trigger a postback, but they should not cause form validation on the
client side, meaning the OnSubmit property of the Form should not be
triggered. At the moment all of them trigger this property. How can I
prevent that from happening ?
>
Thanks
>
onSubmit want function to execute, not the form action
<form action="somefile.asp" method="post" onSubmit="return FunctionToCall();"
<script language="javascript">
function FunctionToCall()
{
//This is the stuff you want to happen
return false; // This prevents the submit from happening
}
</script>
Ciao
It worked perfectly. I was trying onSubmit="FunctionToCall();" instead of "return FunctionToCall();". Thank you!!
onsubmit question - can't figure out
I have a login control with a login button to process the username,password,
etc.
I have the login control within a login page, and this page has the form
tags in it......
//this doesn't work for the onsubmit
<form id="Form1" method="post" runat="server" onsubmit="Button1_Click">
<uc1:Top id="Top1" runat="server"></uc1:Top>
<uc1:SideNav id="SideNav1" runat="server"></uc1:SideNav>
<uc1:Login id="Login1" runat="server"></uc1:Login>
</form>
I'm trying to call the Button1_Click method within Login control when the
form is submitted. It's not reaching it, what am I doing wrong?'onsubmit' is a client side event. You can't call a server side function to
handle a client side event.
You need to write client side script to handle this event on the client,
probably written in javascript.
"Craig" <Craig@.discussions.microsoft.com> wrote in message
news:F611109E-3578-4F55-BCC2-E3A9842F5F78@.microsoft.com...
> This has got to be easy, but I can't figure it out.
> I have a login control with a login button to process the
> username,password,
> etc.
> I have the login control within a login page, and this page has the form
> tags in it......
> //this doesn't work for the onsubmit
> <form id="Form1" method="post" runat="server" onsubmit="Button1_Click">
> <uc1:Top id="Top1" runat="server"></uc1:Top>
> <uc1:SideNav id="SideNav1" runat="server"></uc1:SideNav>
> <uc1:Login id="Login1" runat="server"></uc1:Login>
> </form>
> I'm trying to call the Button1_Click method within Login control when the
> form is submitted. It's not reaching it, what am I doing wrong?
Craig,
You can access the button's click event from within the control itself. You
don't need to tie it to the form submittal at all.
If you're using Visual Studio.Net then the easiest way to access the button
click's event is to go to the design view of the control and double click
the button. That will create the button click event server side within the
control's code behind page.
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Craig" <Craig@.discussions.microsoft.com> wrote in message
news:F611109E-3578-4F55-BCC2-E3A9842F5F78@.microsoft.com...
> This has got to be easy, but I can't figure it out.
> I have a login control with a login button to process the
> username,password,
> etc.
> I have the login control within a login page, and this page has the form
> tags in it......
> //this doesn't work for the onsubmit
> <form id="Form1" method="post" runat="server" onsubmit="Button1_Click">
> <uc1:Top id="Top1" runat="server"></uc1:Top>
> <uc1:SideNav id="SideNav1" runat="server"></uc1:SideNav>
> <uc1:Login id="Login1" runat="server"></uc1:Login>
> </form>
> I'm trying to call the Button1_Click method within Login control when the
> form is submitted. It's not reaching it, what am I doing wrong?
onsubmit question - cant figure out
I have a login control with a login button to process the username,password,
etc.
I have the login control within a login page, and this page has the form
tags in it......
//this doesn't work for the onsubmit
<form id="Form1" method="post" runat="server" onsubmit="Button1_Click">
<uc1:Top id="Top1" runat="server"></uc1:Top>
<uc1:SideNav id="SideNav1" runat="server"></uc1:SideNav>
<uc1:Login id="Login1" runat="server"></uc1:Login>
</form
I'm trying to call the Button1_Click method within Login control when the
form is submitted. It's not reaching it, what am I doing wrong?'onsubmit' is a client side event. You can't call a server side function to
handle a client side event.
You need to write client side script to handle this event on the client,
probably written in javascript.
"Craig" <Craig@.discussions.microsoft.com> wrote in message
news:F611109E-3578-4F55-BCC2-E3A9842F5F78@.microsoft.com...
> This has got to be easy, but I can't figure it out.
> I have a login control with a login button to process the
> username,password,
> etc.
> I have the login control within a login page, and this page has the form
> tags in it......
> //this doesn't work for the onsubmit
> <form id="Form1" method="post" runat="server" onsubmit="Button1_Click">
> <uc1:Top id="Top1" runat="server"></uc1:Top>
> <uc1:SideNav id="SideNav1" runat="server"></uc1:SideNav>
> <uc1:Login id="Login1" runat="server"></uc1:Login>
> </form>
> I'm trying to call the Button1_Click method within Login control when the
> form is submitted. It's not reaching it, what am I doing wrong?
Craig,
You can access the button's click event from within the control itself. You
don't need to tie it to the form submittal at all.
If you're using Visual Studio.Net then the easiest way to access the button
click's event is to go to the design view of the control and double click
the button. That will create the button click event server side within the
control's code behind page.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Craig" <Craig@.discussions.microsoft.com> wrote in message
news:F611109E-3578-4F55-BCC2-E3A9842F5F78@.microsoft.com...
> This has got to be easy, but I can't figure it out.
> I have a login control with a login button to process the
> username,password,
> etc.
> I have the login control within a login page, and this page has the form
> tags in it......
> //this doesn't work for the onsubmit
> <form id="Form1" method="post" runat="server" onsubmit="Button1_Click">
> <uc1:Top id="Top1" runat="server"></uc1:Top>
> <uc1:SideNav id="SideNav1" runat="server"></uc1:SideNav>
> <uc1:Login id="Login1" runat="server"></uc1:Login>
> </form>
> I'm trying to call the Button1_Click method within Login control when the
> form is submitted. It's not reaching it, what am I doing wrong?
onSubmit only works for buttons
I put onSubmit= "return myfunction();" in my <form clause on my aspx page.
If the user hits a button the javascript executes just fine. But if the
user changes the selection on a dropdown (that has AutoPostback=true) the
javascript does not get executed.
I want the javascript to execute whenever any control is hit that causes a
postback.
Anyone know why this is not working as I expect it to or what can be done to
get my desired results?
thanks,
TAsp controls who autopostback use the code __doPostBack. I am not sure if
this code calls 'submit'.
--
Direct Email: Michael.Baltic@.RemoveCharactersUpTo#NCMC.Com
Staff Consultant II
Enterprise Web Services
Cardinal Solutions Group
"Tina" wrote:
> I have some javascript that I want executed whenever my form is subitted so
> I put onSubmit= "return myfunction();" in my <form clause on my aspx page.
> If the user hits a button the javascript executes just fine. But if the
> user changes the selection on a dropdown (that has AutoPostback=true) the
> javascript does not get executed.
> I want the javascript to execute whenever any control is hit that causes a
> postback.
> Anyone know why this is not working as I expect it to or what can be done to
> get my desired results?
> thanks,
> T
>
The following is from msdn.
"You can override this event by returning false in the event handler. Use
this capability to validate data on the client side to prevent invalid data
from being submitted to the server. If the event handler is called by the
onsubmit attribute of the form object, the code must explicitly request the
return value using the return function, and the event handler must provide
an explicit return value for each possible code path in the event handler
function.
The submit method does not invoke the onsubmit event handler."
The last sentence says it all.
"Michael Baltic" <MichaelBaltic@.discussions.microsoft.com> wrote in message
news:BAB32C98-CB8A-45CE-8606-831D4B8B24D5@.microsoft.com...
> Asp controls who autopostback use the code __doPostBack. I am not sure if
> this code calls 'submit'.
> --
> Direct Email: Michael.Baltic@.RemoveCharactersUpTo#NCMC.Com
> Staff Consultant II
> Enterprise Web Services
> Cardinal Solutions Group
>
> "Tina" wrote:
> > I have some javascript that I want executed whenever my form is subitted
so
> > I put onSubmit= "return myfunction();" in my <form clause on my aspx
page.
> > If the user hits a button the javascript executes just fine. But if the
> > user changes the selection on a dropdown (that has AutoPostback=true)
the
> > javascript does not get executed.
> > I want the javascript to execute whenever any control is hit that causes
a
> > postback.
> > Anyone know why this is not working as I expect it to or what can be
done to
> > get my desired results?
> > thanks,
> > T
On Fri, 08 Jul 2005 10:44:02 -0700, Michael Baltic wrote:
> Asp controls who autopostback use the code __doPostBack. I am not sure if
> this code calls 'submit'.
Is your button a submit button?. If it is just a button no onSubmit is
triggered (you have to do your own)
Tina,
You have come accross a big fat hole in asp.net. Asp.net produces a
_doPostBack() javascript function using it's
page.RegisterOnSubmitStatement() but the problem is that code generated by
page.RegisterOnSubmitStatement() does not get executed when a page is
submitted using AutoPostBack. GOTCHA!!
There is an article at www.asptoday.com entitled DoPostBack Hijacking that
details how to get around this problem. you will need to subscribe to the
site to get the article but, in my opinion, it is well worth the money
because a 3 month subscription cost less than an hours work.
Regards,
G Dean Blake
www.deanblakely.com
"Tina" <tinamseaburn@.nospammeexcite.com> wrote in message
news:OottPD%23gFHA.1444@.TK2MSFTNGP10.phx.gbl...
>I have some javascript that I want executed whenever my form is subitted so
>I put onSubmit= "return myfunction();" in my <form clause on my aspx page.
> If the user hits a button the javascript executes just fine. But if the
> user changes the selection on a dropdown (that has AutoPostback=true) the
> javascript does not get executed.
> I want the javascript to execute whenever any control is hit that causes a
> postback.
> Anyone know why this is not working as I expect it to or what can be done
> to get my desired results?
> thanks,
> T
ontextchange - get textbox value
Thanks for reading
Under a textbox when we put a ontextchange event; how do we retrieve the tex
t value?
Sub txtChangedHandler(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
OnTextChanged="txtChangedHandler" AutoPostBack=true>0On Apr 13, 11:25 am, "Eric Layman" <namyalcire[at no spam]gmail.com>
wrote:
> Hi,
> Thanks for reading
> Under a textbox when we put a ontextchange event; how do we retrieve the t
ext value?
> Sub txtChangedHandler(ByVal sender As Object, ByVal e As System.EventArgs)
> End Sub
> OnTextChanged="txtChangedHandler" AutoPostBack=true>0
Hi Eric,
State the complete issue. Will try to help. Your post above does not
clearly mention what you need.
Ravi
ontextchange - get textbox value
Thanks for reading
Under a textbox when we put a ontextchange event; how do we retrieve the text value?
Sub txtChangedHandler(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
OnTextChanged="txtChangedHandler" AutoPostBack=true>0On Apr 13, 11:25 am, "Eric Layman" <namyalcire[at no spam]gmail.com>
wrote:
Quote:
Originally Posted by
Hi,
>
Thanks for reading
>
Under a textbox when we put a ontextchange event; how do we retrieve the text value?
>
Sub txtChangedHandler(ByVal sender As Object, ByVal e As System.EventArgs)
>
End Sub
>
OnTextChanged="txtChangedHandler" AutoPostBack=true>0
Hi Eric,
State the complete issue. Will try to help. Your post above does not
clearly mention what you need.
Ravi