Showing posts with label controls. Show all posts
Showing posts with label controls. Show all posts

Saturday, March 31, 2012

Strange behavior of invisible controls

Hello:
I'm updating multiple rows in the datagrid, using the routine described in
the article "Top Questions about the DataGrid Web Server Control":
http://msdn.microsoft.com/library/d...>
ercontrol.asp
To determine which rows had been changed, I'm using the RowChanged sub:
Protected Sub RowChanged(ByVal sender As Object, _
ByVal e As System.EventArgs)
'----
--
' Add ID's for changed rows
'----
--
Try
Dim dgi As DataGridItem = _
CType(CType(sender, Control).NamingContainer, DataGridItem)
Dim IDlabel As Label = CType(dgi.FindControl("lblOrder"), Label)
Dim ID As Integer = CType(IDlabel.Text, Integer)
If Not (IDlist.Contains(ID)) Then
IDlist.Add(ID)
End If
Catch ex As Exception
Me.lblError.Text = "Error No.: " & Err.Number.ToString & " - " & ex.ToString
End Try
End Sub
<asp:CheckBox id="chkInHouse" ToolTip="Plates In House" runat="server"
OnCheckedChanged="RowChanged" Checked='<%# DataBinder.Eval(Container,
"DataItem.InHouse") %>'>
It works OK everywhere, except one datagrid where some of my checkboxes are
invisible - the user has to click a button to make them visible. These
invisible checkboxes always indicate that their values had been changed. As
a result all my data from the datagrid is sent to the database, even if no
changes has been made. As soon as I make these checkboxes visible -
everything works OK.
Why is this happening? Is there any workaround?
I would appreciate your help.
Thank you,
Peter AfoninHi,
If you set checkbox visibility by visible property and you are using
postback to change visible state maybe there is something in the
postback activity that cause that behavior.
you can change check box visibility by changing visibility attribute of
control Style using javascrit thus reducing network traffic.
Natty Gur[MVP]
blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!
Thank you, Natty.
Do you have a JavaScript sample on how to do this? I don't know JS well.
Peter
"Natty Gur" <natty@.dao2com.com> wrote in message
news:Occ$GsiPEHA.164@.TK2MSFTNGP12.phx.gbl...
> Hi,
> If you set checkbox visibility by visible property and you are using
> postback to change visible state maybe there is something in the
> postback activity that cause that behavior.
> you can change check box visibility by changing visibility attribute of
> control Style using javascrit thus reducing network traffic.
> Natty Gur[MVP]
> blog : http://weblogs.asp.net/ngur
> Mobile: +972-(0)58-888377
>
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!

Strange behavior of invisible controls

Hello:

I'm updating multiple rows in the datagrid, using the routine described in
the article "Top Questions about the DataGrid Web Server Control":

http://msdn.microsoft.com/library/d...ercontrol. asp

To determine which rows had been changed, I'm using the RowChanged sub:

Protected Sub RowChanged(ByVal sender As Object, _
ByVal e As System.EventArgs)
'-----------------------
-------
' Add ID's for changed rows
'-----------------------
-------
Try
Dim dgi As DataGridItem = _
CType(CType(sender, Control).NamingContainer, DataGridItem)
Dim IDlabel As Label = CType(dgi.FindControl("lblOrder"), Label)
Dim ID As Integer = CType(IDlabel.Text, Integer)
If Not (IDlist.Contains(ID)) Then
IDlist.Add(ID)
End If
Catch ex As Exception
Me.lblError.Text = "Error No.: " & Err.Number.ToString & " - " & ex.ToString
End Try
End Sub

<asp:CheckBox id="chkInHouse" ToolTip="Plates In House" runat="server"
OnCheckedChanged="RowChanged" Checked='<%# DataBinder.Eval(Container,
"DataItem.InHouse") %>'
It works OK everywhere, except one datagrid where some of my checkboxes are
invisible - the user has to click a button to make them visible. These
invisible checkboxes always indicate that their values had been changed. As
a result all my data from the datagrid is sent to the database, even if no
changes has been made. As soon as I make these checkboxes visible -
everything works OK.

Why is this happening? Is there any workaround?

I would appreciate your help.

Thank you,

--
Peter AfoninHi,

If you set checkbox visibility by visible property and you are using
postback to change visible state maybe there is something in the
postback activity that cause that behavior.

you can change check box visibility by changing visibility attribute of
control Style using javascrit thus reducing network traffic.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Thank you, Natty.

Do you have a JavaScript sample on how to do this? I don't know JS well.

Peter

"Natty Gur" <natty@.dao2com.com> wrote in message
news:Occ$GsiPEHA.164@.TK2MSFTNGP12.phx.gbl...
> Hi,
> If you set checkbox visibility by visible property and you are using
> postback to change visible state maybe there is something in the
> postback activity that cause that behavior.
> you can change check box visibility by changing visibility attribute of
> control Style using javascrit thus reducing network traffic.
> Natty Gur[MVP]
> blog : http://weblogs.asp.net/ngur
> Mobile: +972-(0)58-888377
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

Strange behavior with server web controls

Hi,

I don't know if anybody else experienced this, but sometimes, I can't set
breakpoints the event code of a button on a form for some reason. The code
still executes, but I can't stop the execution with a breakpoint. While
compiling, a question mark appears in the red dot on the left side of the
code editor and if I hover my mouse over it, it says

"The breakpoint will not currently be hit. No executable code is associated
with this line."

The last time I experienced this, I has to copy the event code somewhere
else, delete the form button and recreate it by pasting the code back.
Anybody had this happen to them? Is there an explanation?

Thanks

EricJust an idea...

Sometimes, VS.NET would erase everything after the Handles clause. Perhaps you
could see if that's the case.

I'm just speculating that the compiler is noticing that without a handler,
there's nothing to call the code.

Ken

"news.public.microsoft.com" <mindmover@.hotmail.com> wrote in message
news:eIU3lNWUDHA.372@.tk2msftngp13.phx.gbl...
Hi,

I don't know if anybody else experienced this, but sometimes, I can't set
breakpoints the event code of a button on a form for some reason. The code
still executes, but I can't stop the execution with a breakpoint. While
compiling, a question mark appears in the red dot on the left side of the
code editor and if I hover my mouse over it, it says

"The breakpoint will not currently be hit. No executable code is associated
with this line."

The last time I experienced this, I has to copy the event code somewhere
else, delete the form button and recreate it by pasting the code back.
Anybody had this happen to them? Is there an explanation?

Thanks

Eric

Saturday, March 24, 2012

Strange Error when viewing page

When I view my index.aspx page any time after the first time, I recieve the
following error:

[HttpException (0x80004005): Multiple controls with the same ID
'TitleBanner:_ctl0' were found. Trace requires that controls have unique
IDs.]
System.Web.TraceContext.AddNewControl(String id, String parentId, String
type, Int32 viewStateSize) +313
System.Web.UI.Control.BuildProfileTree(String parentId, Boolean
calcViewState) +201
System.Web.UI.Control.BuildProfileTree(String parentId, Boolean
calcViewState) +263
System.Web.UI.Control.BuildProfileTree(String parentId, Boolean
calcViewState) +263
System.Web.UI.Control.BuildProfileTree(String parentId, Boolean
calcViewState) +263
System.Web.UI.Page.ProcessRequestMain() +1633

TitleBanner is a user control on my page. Because I do not recieve this
error the very first time I view the page after compiling it, ASP.NET is
obviously remembering the control after I view the page the first time. I
find this error strange because _ctl0 is an automatically generated name, so
how can there be two controls with that name? I also find it strange that
the error only seems to occur on my index.aspx page, even though the control
is used in exactly the same way (same parameters and properties) on another
page in the same directory, and it does not give me an error there even when
I view it multiple times. Why might this be happening, and what might I be
able to do to fix it? Thanks.
--
Nathan Sokalski
njsokalski@dotnet.itags.org.hotmail.com
http://www.nathansokalski.com/Nathan,

First question,
Are you dynamicly building controls?

Cor
Hi,

If you are adding the control to the webpage via code do not add
it again when the page is posting back.

If not me.postback then
' add the control here
end if

Ken
---------

"Nathan Sokalski" wrote:

> When I view my index.aspx page any time after the first time, I recieve the
> following error:
> [HttpException (0x80004005): Multiple controls with the same ID
> 'TitleBanner:_ctl0' were found. Trace requires that controls have unique
> IDs.]
> System.Web.TraceContext.AddNewControl(String id, String parentId, String
> type, Int32 viewStateSize) +313
> System.Web.UI.Control.BuildProfileTree(String parentId, Boolean
> calcViewState) +201
> System.Web.UI.Control.BuildProfileTree(String parentId, Boolean
> calcViewState) +263
> System.Web.UI.Control.BuildProfileTree(String parentId, Boolean
> calcViewState) +263
> System.Web.UI.Control.BuildProfileTree(String parentId, Boolean
> calcViewState) +263
> System.Web.UI.Page.ProcessRequestMain() +1633
> TitleBanner is a user control on my page. Because I do not recieve this
> error the very first time I view the page after compiling it, ASP.NET is
> obviously remembering the control after I view the page the first time. I
> find this error strange because _ctl0 is an automatically generated name, so
> how can there be two controls with that name? I also find it strange that
> the error only seems to occur on my index.aspx page, even though the control
> is used in exactly the same way (same parameters and properties) on another
> page in the same directory, and it does not give me an error there even when
> I view it multiple times. Why might this be happening, and what might I be
> able to do to fix it? Thanks.
> --
> Nathan Sokalski
> njsokalski@.hotmail.com
> http://www.nathansokalski.com/
>
Yes, I am. The place that it looks like the error occurs (which is pretty
early in my code based on what I can tell, since the control it says it
finds multiple times is pretty early in the Control Tree it displays). A
note that I want to make about this control, however, is that is a control
that I generate in the Application_Start procedure and store in a collection
in the global.asax.vb file, so it is really only generated once (unless the
cache dependency removes it from cache, in which case it is generated
again). Here is my control tree, which you can see is pretty small since it
doesn't get very far:

Control Tree
Control Id Type Render Size Bytes (including children) Viewstate Size
Bytes (excluding children)
__PAGE ASP.index_aspx 0 0
_ctl0 System.Web.UI.LiteralControl 0 0
TitleBar System.Web.UI.HtmlControls.HtmlGenericControl 0 0
_ctl1 System.Web.UI.LiteralControl 0 0
_ctl2 System.Web.UI.ResourceBasedLiteralControl 0 0
Form1 System.Web.UI.HtmlControls.HtmlForm 0 0
_ctl3 System.Web.UI.LiteralControl 0 0
TitleBanner ASP.Banner_ascx 0 0
TitleBanner:lblTitle System.Web.UI.WebControls.Label 0 0
TitleBanner:_ctl0 System.Web.UI.LiteralControl 0 0

My other control, which the application never even gets to which I use for
navigation on all my pages, actually does generate the controls every time.
If you need any more info, I will be happy to give you anything I can.
Thanks.
--
Nathan Sokalski
njsokalski@.hotmail.com
http://www.nathansokalski.com/
"Cor Ligthert" <notmyfirstname@.planet.nl> wrote in message
news:%237wgeAkdFHA.2288@.TK2MSFTNGP14.phx.gbl...
> Nathan,
> First question,
> Are you dynamicly building controls?
> Cor
I do not add the user control via code, the user control is always there.
The basic layout of the control that it looks like the error is occurring in
is as follows:

LABEL CONTROL

imagecontrol imagecontrol imagecontrol

The basic purpose of the user control is to display the title and navigation
bar. The imagecontrols, which are the navigation, are generated when the
application is started in the Application_Start procedure, and are then
stored in a collection in the global.asax.vb file. The only time they would
be generated a second time would be if they were removed from the
application cache (I created cache dependencies for this). I also want to
point out that even though my diagram above says imagecontrol 3 times, the
page in error only places one there (other pages would place more, but this
page only has one). My control tree (or at least the part shown in the
error) is as follows:

Control Tree
Control Id Type Render Size Bytes (including children) Viewstate Size
Bytes (excluding children)
__PAGE ASP.index_aspx 0 0
_ctl0 System.Web.UI.LiteralControl 0 0
TitleBar System.Web.UI.HtmlControls.HtmlGenericControl 0 0
_ctl1 System.Web.UI.LiteralControl 0 0
_ctl2 System.Web.UI.ResourceBasedLiteralControl 0 0
Form1 System.Web.UI.HtmlControls.HtmlForm 0 0
_ctl3 System.Web.UI.LiteralControl 0 0
TitleBanner ASP.Banner_ascx 0 0
TitleBanner:lblTitle System.Web.UI.WebControls.Label 0 0
TitleBanner:_ctl0 System.Web.UI.LiteralControl 0 0

I am having trouble figuring out what the LiteralControl that it stops at
is, because the user control TitleBanner does not create or use any
LiteralControls. All I can think of is that somehow ASP.NET is labeling the
<BR> tag as a LiteralControl, even though the tag is just there. If there is
any more information that might be useful in figuring out the problem, let
me know and I will be happy to give it to you. Thanks.
--
Nathan Sokalski
njsokalski@.hotmail.com
http://www.nathansokalski.com/
"Ken Tucker [MVP]" <KenTuckerMVP@.discussions.microsoft.com> wrote in message
news:4185E94C-784F-4CCF-B060-555ADEC219BB@.microsoft.com...
> Hi,
> If you are adding the control to the webpage via code do not add
> it again when the page is posting back.
> If not me.postback then
> ' add the control here
> end if
> Ken
> ---------
> "Nathan Sokalski" wrote:
>> When I view my index.aspx page any time after the first time, I recieve
>> the
>> following error:
>>
>> [HttpException (0x80004005): Multiple controls with the same ID
>> 'TitleBanner:_ctl0' were found. Trace requires that controls have unique
>> IDs.]
>> System.Web.TraceContext.AddNewControl(String id, String parentId,
>> String
>> type, Int32 viewStateSize) +313
>> System.Web.UI.Control.BuildProfileTree(String parentId, Boolean
>> calcViewState) +201
>> System.Web.UI.Control.BuildProfileTree(String parentId, Boolean
>> calcViewState) +263
>> System.Web.UI.Control.BuildProfileTree(String parentId, Boolean
>> calcViewState) +263
>> System.Web.UI.Control.BuildProfileTree(String parentId, Boolean
>> calcViewState) +263
>> System.Web.UI.Page.ProcessRequestMain() +1633
>>
>> TitleBanner is a user control on my page. Because I do not recieve this
>> error the very first time I view the page after compiling it, ASP.NET is
>> obviously remembering the control after I view the page the first time. I
>> find this error strange because _ctl0 is an automatically generated name,
>> so
>> how can there be two controls with that name? I also find it strange that
>> the error only seems to occur on my index.aspx page, even though the
>> control
>> is used in exactly the same way (same parameters and properties) on
>> another
>> page in the same directory, and it does not give me an error there even
>> when
>> I view it multiple times. Why might this be happening, and what might I
>> be
>> able to do to fix it? Thanks.
>> --
>> Nathan Sokalski
>> njsokalski@.hotmail.com
>> http://www.nathansokalski.com/
>>
>>
>
Nathan,

I think that the way you are doing it, is so special, that I can not give
you any help in this.

Sorry

Cor

Thursday, March 22, 2012

Strange HTML button postback

I have a webform with lots of <asp:...controls but I need couple of buttons
that doesn't cause an automatic postback. I use javascript to handle these
buttons. I tried two approaches with different results:

<IMG onmouseup="src='Bitmaps/Controls/measure_over.bmp';"
onmousedown="src='Bitmaps/Controls/measure_pressed.bmp';"
id="measure" onmouseover="src='Bitmaps/Controls/measure_over.bmp';"
style="LEFT: 170px; WIDTH: 24px; POSITION: absolute; TOP: 2px; HEIGHT: 25px"
onclick="buttonClicked(this.id);"
onmouseout="src='Bitmaps/Controls/measure_btn.bmp';"
alt="" src="http://pics.10026.com/?src=Bitmaps/Controls/measure_btn.bmp"
This is working the way I want to, but I can't disable it as I can with a
button. I then replace the IMG with:

INPUT Type="image"

and it makes a postback every time I click on it. Why? A HTML control
should't do that, right? The script itself (buttonClicked) just fills a
hidden field.

/MiroFrom the MSDN Library about the <input typ="image" tag:

------------------------
INPUT type=image Element | input type=image Object
Creates an image control that, when clicked, causes the form to be
immediately submitted.
------------------------

Maybe add "onclick='return false;'" to the tag.

-Jason Kendall
JasonKendall@.hotmail.com

On Tue, 1 Feb 2005 05:55:13 -0800, "Miro"
<Miro@.discussions.microsoft.com> wrote:

>I have a webform with lots of <asp:...controls but I need couple of buttons
>that doesn't cause an automatic postback. I use javascript to handle these
>buttons. I tried two approaches with different results:
><IMG onmouseup="src='Bitmaps/Controls/measure_over.bmp';"
>onmousedown="src='Bitmaps/Controls/measure_pressed.bmp';"
>id="measure" onmouseover="src='Bitmaps/Controls/measure_over.bmp';"
>style="LEFT: 170px; WIDTH: 24px; POSITION: absolute; TOP: 2px; HEIGHT: 25px"
>onclick="buttonClicked(this.id);"
>onmouseout="src='Bitmaps/Controls/measure_btn.bmp';"
>alt="" src="http://pics.10026.com/?src=Bitmaps/Controls/measure_btn.bmp">
>This is working the way I want to, but I can't disable it as I can with a
>button. I then replace the IMG with:
>INPUT Type="image"
>and it makes a postback every time I click on it. Why? A HTML control
>should't do that, right? The script itself (buttonClicked) just fills a
>hidden field.
>/Miro

Strange HTML button postback

I have a webform with lots of <asp:...controls but I need couple of buttons
that doesn't cause an automatic postback. I use javascript to handle these
buttons. I tried two approaches with different results:
<IMG onmouseup="src='Bitmaps/Controls/measure_over.bmp';"
onmousedown="src='Bitmaps/Controls/measure_pressed.bmp';"
id="measure" onmouseover="src='Bitmaps/Controls/measure_over.bmp';"
style="LEFT: 170px; WIDTH: 24px; POSITION: absolute; TOP: 2px; HEIGHT: 25px"
onclick="buttonClicked(this.id);"
onmouseout="src='Bitmaps/Controls/measure_btn.bmp';"
alt="" src="http://pics.10026.com/?src=Bitmaps/Controls/measure_btn.bmp">
This is working the way I want to, but I can't disable it as I can with a
button. I then replace the IMG with:
INPUT Type="image"
and it makes a postback every time I click on it. Why? A HTML control
should't do that, right? The script itself (buttonClicked) just fills a
hidden field.
/MiroFrom the MSDN Library about the <input typ="image" tag:
----
--
INPUT type=image Element | input type=image Object
Creates an image control that, when clicked, causes the form to be
immediately submitted.
----
--
Maybe add "onclick='return false;'" to the tag.
-Jason Kendall
JasonKendall@.hotmail.com
On Tue, 1 Feb 2005 05:55:13 -0800, "Miro"
<Miro@.discussions.microsoft.com> wrote:

>I have a webform with lots of <asp:...controls but I need couple of buttons
>that doesn't cause an automatic postback. I use javascript to handle these
>buttons. I tried two approaches with different results:
><IMG onmouseup="src='Bitmaps/Controls/measure_over.bmp';"
>onmousedown="src='Bitmaps/Controls/measure_pressed.bmp';"
>id="measure" onmouseover="src='Bitmaps/Controls/measure_over.bmp';"
>style="LEFT: 170px; WIDTH: 24px; POSITION: absolute; TOP: 2px; HEIGHT: 25px
"
>onclick="buttonClicked(this.id);"
>onmouseout="src='Bitmaps/Controls/measure_btn.bmp';"
>alt="" src="http://pics.10026.com/?src=Bitmaps/Controls/measure_btn.bmp">
>This is working the way I want to, but I can't disable it as I can with a
>button. I then replace the IMG with:
>INPUT Type="image"
>and it makes a postback every time I click on it. Why? A HTML control
>should't do that, right? The script itself (buttonClicked) just fills a
>hidden field.
>/Miro

strange inconsistency referencing controls in Formview itemtemplate

Can anyone explain why in the following code, where btnCancel1 is a
Button inside the itemTemplate of the formview, the first call to
change the text of the button, in the Page_Load sub, works fine, but
the second call, in the bookFormView_ItemUpdated sub, throws an
exception (Object reference not set to an instance of an object)? And
if you know why, can you suggest a workaround?

Here is the code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
If Not Page.IsPostBack Then
bookFormView.ChangeMode(FormViewMode.ReadOnly)
Dim cancelButton As Button =
CType(bookFormView.FindControl("btnCancel1"), Button)
cancelButton.Text = "Cancel"
End If
End Sub

Protected Sub bookFormView_ItemUpdated(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.FormViewUpdatedEventArgs ) Handles
bookFormView.ItemUpdated
Dim cancelButton1 As Button =
CType(bookFormView.FindControl("btnCancel1"), Button)
cancelButton1.Text = "Done"
End Sub

The line of code where the error occurs is cancelButton1.Text = "Done"

Thanks in advance.

-- NedFollowup: In researching this I came across a comment that only the
controls in the current mode are accessible; if the formview is in edit
mode then only the controls in the <edititemtemplateare accessible,
if in read-only mode then only the controls in the <itemtemplateare
accessible. This might explain this except that an update is supposed
to automatically return the formview to read-only mode, right? Or does
that happen later (after the formview_itemupdated() has terminated)?
So I tried explicitly changing the mode to read-only within the
itemupdated subroutine, but I still get the same error.

Hope someone can relieve my frustration.

-- Ned

Ned Balzer wrote:

Quote:

Originally Posted by

Can anyone explain why in the following code, where btnCancel1 is a
Button inside the itemTemplate of the formview, the first call to
change the text of the button, in the Page_Load sub, works fine, but
the second call, in the bookFormView_ItemUpdated sub, throws an
exception (Object reference not set to an instance of an object)? And
if you know why, can you suggest a workaround?
>
Here is the code:
>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
If Not Page.IsPostBack Then
bookFormView.ChangeMode(FormViewMode.ReadOnly)
Dim cancelButton As Button =
CType(bookFormView.FindControl("btnCancel1"), Button)
cancelButton.Text = "Cancel"
End If
End Sub
>
Protected Sub bookFormView_ItemUpdated(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.FormViewUpdatedEventArgs ) Handles
bookFormView.ItemUpdated
Dim cancelButton1 As Button =
CType(bookFormView.FindControl("btnCancel1"), Button)
cancelButton1.Text = "Done"
End Sub
>
>
>
The line of code where the error occurs is cancelButton1.Text = "Done"
>
Thanks in advance.
>
-- Ned


1) Why not just use the control's variable? If the control has an id of
btnCancel1 and it's marked runat="server", then just do btnCancel1.Text =
"Done"

2) Are you using master pages? Control ID's change when placed into a
content placeholder on a master page. Use the DevToolBar to explore the DOM
and determine what your control's ID actually is on the client size.

"Ned Balzer" wrote:

Quote:

Originally Posted by

Can anyone explain why in the following code, where btnCancel1 is a
Button inside the itemTemplate of the formview, the first call to
change the text of the button, in the Page_Load sub, works fine, but
the second call, in the bookFormView_ItemUpdated sub, throws an
exception (Object reference not set to an instance of an object)? And
if you know why, can you suggest a workaround?
>
Here is the code:
>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
If Not Page.IsPostBack Then
bookFormView.ChangeMode(FormViewMode.ReadOnly)
Dim cancelButton As Button =
CType(bookFormView.FindControl("btnCancel1"), Button)
cancelButton.Text = "Cancel"
End If
End Sub
>
Protected Sub bookFormView_ItemUpdated(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.FormViewUpdatedEventArgs ) Handles
bookFormView.ItemUpdated
Dim cancelButton1 As Button =
CType(bookFormView.FindControl("btnCancel1"), Button)
cancelButton1.Text = "Done"
End Sub
>
>
>
The line of code where the error occurs is cancelButton1.Text = "Done"
>
Thanks in advance.
>
-- Ned
>
>


1) When I try that, I get an error in Visual Web Developer 2005: "Name
'btnCancel1' is not declared." It is marked runat="server" but I think
the problem arises because it is buried within the formview, so it's
not a normal button control.

2) No, I am not currently using master pages.

-- Ned

William Sullivan wrote:

Quote:

Originally Posted by

1) Why not just use the control's variable? If the control has an id of
btnCancel1 and it's marked runat="server", then just do btnCancel1.Text =
"Done"
>
2) Are you using master pages? Control ID's change when placed into a
content placeholder on a master page. Use the DevToolBar to explore the DOM
and determine what your control's ID actually is on the client size.
>
"Ned Balzer" wrote:
>

Quote:

Originally Posted by

Can anyone explain why in the following code, where btnCancel1 is a
Button inside the itemTemplate of the formview, the first call to
change the text of the button, in the Page_Load sub, works fine, but
the second call, in the bookFormView_ItemUpdated sub, throws an
exception (Object reference not set to an instance of an object)? And
if you know why, can you suggest a workaround?

Here is the code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
If Not Page.IsPostBack Then
bookFormView.ChangeMode(FormViewMode.ReadOnly)
Dim cancelButton As Button =
CType(bookFormView.FindControl("btnCancel1"), Button)
cancelButton.Text = "Cancel"
End If
End Sub

Protected Sub bookFormView_ItemUpdated(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.FormViewUpdatedEventArgs ) Handles
bookFormView.ItemUpdated
Dim cancelButton1 As Button =
CType(bookFormView.FindControl("btnCancel1"), Button)
cancelButton1.Text = "Done"
End Sub

The line of code where the error occurs is cancelButton1.Text = "Done"

Thanks in advance.

-- Ned


Well, it doesn't make sense to me, but I found the suggestion somewhere
and tried it: calling bookformview.databind() before attempting to
reference the object, and the error went away. Problem is, the button
text is not being changed either.

Hmmmmmm

Ned Balzer wrote:

Quote:

Originally Posted by

1) When I try that, I get an error in Visual Web Developer 2005: "Name
'btnCancel1' is not declared." It is marked runat="server" but I think
the problem arises because it is buried within the formview, so it's
not a normal button control.
>
2) No, I am not currently using master pages.
>
-- Ned
>
William Sullivan wrote:

Quote:

Originally Posted by

1) Why not just use the control's variable? If the control has an id of
btnCancel1 and it's marked runat="server", then just do btnCancel1.Text =
"Done"

2) Are you using master pages? Control ID's change when placed into a
content placeholder on a master page. Use the DevToolBar to explore the DOM
and determine what your control's ID actually is on the client size.

"Ned Balzer" wrote:

Quote:

Originally Posted by

Can anyone explain why in the following code, where btnCancel1 is a
Button inside the itemTemplate of the formview, the first call to
change the text of the button, in the Page_Load sub, works fine, but
the second call, in the bookFormView_ItemUpdated sub, throws an
exception (Object reference not set to an instance of an object)? And
if you know why, can you suggest a workaround?
>
Here is the code:
>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
If Not Page.IsPostBack Then
bookFormView.ChangeMode(FormViewMode.ReadOnly)
Dim cancelButton As Button =
CType(bookFormView.FindControl("btnCancel1"), Button)
cancelButton.Text = "Cancel"
End If
End Sub
>
Protected Sub bookFormView_ItemUpdated(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.FormViewUpdatedEventArgs ) Handles
bookFormView.ItemUpdated
Dim cancelButton1 As Button =
CType(bookFormView.FindControl("btnCancel1"), Button)
cancelButton1.Text = "Done"
End Sub
>
>
>
The line of code where the error occurs is cancelButton1.Text = "Done"
>
Thanks in advance.
>
-- Ned
>
>

Tuesday, March 13, 2012

Strange problem

I Have a strange problem. I have build a form in wich are some controls. Two textbox and one dropdown control.
The user can perform a search selecting a value in dropdown or inserting in textbox and click on search button.
My sub verify if dropdown control or textbox changed and build sql string.
But the strange think is that all run only when I use dropdown. If I insert value in textbox and not dropdown search don't work.
The code don't run. Why?
I have inserted OnTextChanged event in textbox html code and OnSelectedIndexChanged in dropdown html code but nothing to do!
HELP ME, PLEASE!You need to post your code so we can help you.