Monday, March 26, 2012
Trouble getting jpg to display in image control
My company is changing its logo and I am having trouble getting my
existing image controls in asp.net apps to read the new jpg. I do not
need to programmatically change them, as they are static, but when
using the new jpegs I only get the little red x. I have added the new
jpg to the project, I can see it right there when I go to set the
image url of the control, and when I double click from the solution
explorer it displays properly in Photo Editor but no luck in my
control. Creating new controls and changing existing ones produces
the same result. I am able to use a new gif, but I am unhappy with
the image quality.
Any suggestions would be great.You'll want to make sure that the URL isn't pointing to your local file
system (file:) rather than a regular IIS url.
Also, is this inside the firewall? Are you using the same filename for the
new image?
Some intranets have very aggressive caching. You might defeat it by
changing the name of the .jpg if you haven't already tried that. Or ask the
security admin to dump the cache.
Just tossing out some ideas....
"Brian Hanson" <bdhanson@.mcdermott.com> wrote in message
news:169b400f.0312010828.2ad4bcb9@.posting.google.c om...
> Hi,
> My company is changing its logo and I am having trouble getting my
> existing image controls in asp.net apps to read the new jpg. I do not
> need to programmatically change them, as they are static, but when
> using the new jpegs I only get the little red x. I have added the new
> jpg to the project, I can see it right there when I go to set the
> image url of the control, and when I double click from the solution
> explorer it displays properly in Photo Editor but no luck in my
> control. Creating new controls and changing existing ones produces
> the same result. I am able to use a new gif, but I am unhappy with
> the image quality.
> Any suggestions would be great.
Trouble programatically getting form values on PostBack
protected System.Web.UI.WebControls.RadioButtonList rblSymbols;
protected System.Web.UI.WebControls.CheckBox chkPublish;
protected System.Web.UI.WebControls.DropDownList ddlSubject;
protected System.Web.UI.WebControls.TextBox txtEntry;
protected System.Web.UI.WebControls.Button btnSave;
The btnSave_Click(object sender, System.EventArgs e) is properly registered in the InitializeComponent() method. Inside the btnSave_Click() method, I call another function to save to the db which works fine. However, when I attempt to reference the values of those items, they are not set properly. It's as if the IPostBackDataHandler.LoadPostData() method in the Init of the page lifecycle is not being done at all. Any ideas? So far, I have had to result to the following until this is figured out:
YUCK!:
**********************
myObj.Entry = Request["txtEntry"];
Preferred:
**********************
myObj.Entry = txtEntry.Text;
Thanks in advance for any insight you might have.
--ChadIs it possible you've disabled Viewstate at some point?
Peter,
Yes, itIS possible. In fact, I have done just that on several of my controls. Is this the problem? I will try re-enabling. I have read so much on the pros and cons of keeping it turned on. Is is safe to assume that if I wish to program as described above, I need to keep viewstate enabled?
--Chad
Heh... yeah, that could be the problem :)
ViewState is the mechanism by which your controls' properties are persisted across postbacks. If you want to grab myControl.Text, for example, you must have Viewstate enabled.
On the other hand, if you don't mind grabbing values from the Request.Form collection, you can kill Viewstate with impunity.
Cheers,
Peter - thanks for clearing this up for me! Very helpful!
--Chad
Trouble referencing controls within list controls
in each row. The CustomValidator fires a function that compares all
TextBoxes for equality. The algorithm for comparison is
straightforward:
*PSEUDOCODE*
for i=1 thru ( Container.Length-1 )
for j=i+1 thru ( Container.Length-1 )
if ( TextBox[i]==TextBox[j] )
TRUE
It would be even faster if instead of starting with 1 everytime, I set
i to get the index of the current Container row.
Problem is I'm having trouble referencing the TextBoxes within the
DataGrid. I've studied msdn
(http://msdn.microsoft.com/library/d...bformspages.asp)
but the concept still baffles me.
Specifically, what I try to do is store the TextBoxes for comparison
in an array:
Dim ControlName As String' temporary
ControlName = OurDataGrid.Controls(i).UniqueID
aObjFirst(0) = CType( Me.FindControl(ControlName & "First"), TextBox
)
ControlName = OurDataGrid.Controls(j).UniqueID
aObjFirst(1) = CType( Me.FindControl(ControlName & "First"), TextBox
)
' If first names match...
If ( aObjFirst(0).Text=aObjFirst(1).Text ) Then
...
(Yes, I'm comparing first names.) However, this always warns me that
j is out of range. And getting back to the msdn, it seems to be
discouraging the technique of name concatenation I used to get at the
controls I want.
Can anyone follow where I'm going with this and provide some
insightful direction?--or a totally different approach would be welcome. Anything that
could help, really.
I just thought of a less repetitive algorithm.
Provided I can dynamically obtain the index of the current row:
*PSEUDOCODE*
for i=currentIndex thru ( DataGrid.Controls.Count-1 )
if ( TextBox[currentIndex].Text==TextBox[i].Text )
TRUE
Problem is I still need help referencing the individual TextBox
controls that my DataGrid generates. I have a feeling the solution
lies with the UniqueID property, but I still can't solve it on my own.
> I have a DataGrid containing a TextBox control and a CustomValidator
> in each row. The CustomValidator fires a function that compares all
> TextBoxes for equality. The algorithm for comparison is
> straightforward:
> *PSEUDOCODE*
> for i=1 thru ( Container.Length-1 )
> for j=i+1 thru ( Container.Length-1 )
> if ( TextBox[i]==TextBox[j] )
> TRUE
...
> Specifically, what I try to do is store the TextBoxes for comparison
> in an array:
>Dim aObjFirst(2) As TextBox
> Dim ControlName As String' temporary
> ControlName = OurDataGrid.Controls(i).UniqueID
> aObjFirst(0) = CType(Me.FindControl(ControlName & "First"), TextBox)
> ControlName = OurDataGrid.Controls(j).UniqueID
> aObjFirst(1) = CType(Me.FindControl(ControlName & "First"), TextBox)
> ' If first names match...
> If ( aObjFirst(0).Text=aObjFirst(1).Text ) Then
> ...
> (Yes, I'm comparing first names.) However, this always warns me that
> j is out of range. And getting back to the msdn, it seems to be
> discouraging the technique of name concatenation I used to get at the
> controls I want.
> Can anyone follow where I'm going with this and provide some
> insightful direction?
Same question, different day, (hopefully) worded more clearly.
I have a DataGrid containing a TextBox control and a CustomValidator in
each row.
The CustomValidator fires a subroutine that compares all TextBoxes the
DataGrid generates for equality.
The algorithm is pretty straightforward:
*PSEUDOCODE*
senderIndex = the row in the DataGrid of the sender
FOR ( i=senderIndex+1 ) THRU ( last Row of the DataGrid )
IF ( TextBox[i].Text==TextBox[senderIndex].Text )
TRUE
However, I'm stuck in my attempts to formally code this algorithm:
*CODE*
Sub HasDupe(sender as Object, e as EventArgs)
Dim objFirst As Textbox
value.IsValid = False
For ( i = SENDER_INDEX+1 ) To ( DataGrid.Controls.Count-1 )
' get the control in row i with the same ID as the
sender
objFirst =
OurDataGrid.Items(i).FindControl(sender.ControlToV alidate)
If ( objFirst.Text=sender.Text )
value.IsValid = True
End If
Next
End Sub
I /think/ my only problem is the "SENDER_INDEX"--I can't figure out how
to reveal the row number of the sender. This is my question.
(But if any other part of my code looks screwy, I'd appreciate input on
that as well.)
(Here's an answer I received from another post, that _works._
--E.)
Use can use the parent control to find the index. All Controls have
parents and children, you can move up and down the node list to find
the one you are looking for. You can shorten the code, I just wanted to
make sure you saw the levels. Also a while back I was trying to deal
with CustomValidators in datagrids, I seem to recall some issues with
that just FYI. Hope this helps AuSable Troutbum
'Find the The control that is firing event
Dim valCustomControl As New CustomValidator
valCustomControl = sender
'Find the Parent Cell of Validation Control
Dim cell As TableCell = valCustomControl.Parent
'Find the Datagrid Item
Dim dgItem As DataGridItem = cell.Parent
'Set the Row
Dim myRow As DataRow =
DataSet.Tables("YourTableName").Rows(dgItem.ItemIndex)
Trouble referencing controls within list controls
in each row. The CustomValidator fires a function that compares all
TextBoxes for equality. The algorithm for comparison is
straightforward:
*PSEUDOCODE*
for i=1 thru ( Container.Length-1 )
for j=i+1 thru ( Container.Length-1 )
if ( TextBox[i]==TextBox[j] )
TRUE
It would be even faster if instead of starting with 1 everytime, I set
i to get the index of the current Container row.
Problem is I'm having trouble referencing the TextBoxes within the
DataGrid. I've studied msdn
(http://msdn.microsoft.com/library/d...bformspages.asp)
but the concept still baffles me.
Specifically, what I try to do is store the TextBoxes for comparison
in an array:
Dim ControlName As String ' temporary
ControlName = OurDataGrid.Controls(i).UniqueID
aObjFirst(0) = CType( Me.FindControl(ControlName & "First"), TextBox
)
ControlName = OurDataGrid.Controls(j).UniqueID
aObjFirst(1) = CType( Me.FindControl(ControlName & "First"), TextBox
)
' If first names match...
If ( aObjFirst(0).Text=aObjFirst(1).Text ) Then
..
(Yes, I'm comparing first names.) However, this always warns me that
j is out of range. And getting back to the msdn, it seems to be
discouraging the technique of name concatenation I used to get at the
controls I want.
Can anyone follow where I'm going with this and provide some
insightful direction?--or a totally different approach would be welcome. Anything that
could help, really.
I just thought of a less repetitive algorithm.
Provided I can dynamically obtain the index of the current row:
*PSEUDOCODE*
for i=currentIndex thru ( DataGrid.Controls.Count-1 )
if ( TextBox[currentIndex].Text==TextBox[i].Text )
TRUE
Problem is I still need help referencing the individual TextBox
controls that my DataGrid generates. I have a feeling the solution
lies with the UniqueID property, but I still can't solve it on my own.
> I have a DataGrid containing a TextBox control and a CustomValidator
> in each row. The CustomValidator fires a function that compares all
> TextBoxes for equality. The algorithm for comparison is
> straightforward:
> *PSEUDOCODE*
> for i=1 thru ( Container.Length-1 )
> for j=i+1 thru ( Container.Length-1 )
> if ( TextBox[i]==TextBox[j] )
> TRUE
>
...
> Specifically, what I try to do is store the TextBoxes for comparison
> in an array:
> Dim aObjFirst(2) As TextBox
> Dim ControlName As String ' temporary
> ControlName = OurDataGrid.Controls(i).UniqueID
> aObjFirst(0) = CType(Me.FindControl(ControlName & "First"), TextBox)
> ControlName = OurDataGrid.Controls(j).UniqueID
> aObjFirst(1) = CType(Me.FindControl(ControlName & "First"), TextBox)
> ' If first names match...
> If ( aObjFirst(0).Text=aObjFirst(1).Text ) Then
> ...
> (Yes, I'm comparing first names.) However, this always warns me that
> j is out of range. And getting back to the msdn, it seems to be
> discouraging the technique of name concatenation I used to get at the
> controls I want.
> Can anyone follow where I'm going with this and provide some
> insightful direction?
Same question, different day, (hopefully) worded more clearly.
I have a DataGrid containing a TextBox control and a CustomValidator in
each row.
The CustomValidator fires a subroutine that compares all TextBoxes the
DataGrid generates for equality.
The algorithm is pretty straightforward:
*PSEUDOCODE*
senderIndex = the row in the DataGrid of the sender
FOR ( i=senderIndex+1 ) THRU ( last Row of the DataGrid )
IF ( TextBox[i].Text==TextBox[senderIndex].Text )
TRUE
However, I'm stuck in my attempts to formally code this algorithm:
*CODE*
Sub HasDupe(sender as Object, e as EventArgs)
Dim objFirst As Textbox
value.IsValid = False
For ( i = SENDER_INDEX+1 ) To ( DataGrid.Controls.Count-1 )
' get the control in row i with the same ID as the
sender
objFirst =
OurDataGrid.Items(i).FindControl(sender.ControlToValidate)
If ( objFirst.Text=sender.Text )
value.IsValid = True
End If
Next
End Sub
I /think/ my only problem is the "SENDER_INDEX"--I can't figure out how
to reveal the row number of the sender. This is my question.
(But if any other part of my code looks screwy, I'd appreciate input on
that as well.)
(Here's an answer I received from another post, that _works._
--E.)
Use can use the parent control to find the index. All Controls have
parents and children, you can move up and down the node list to find
the one you are looking for. You can shorten the code, I just wanted to
make sure you saw the levels. Also a while back I was trying to deal
with CustomValidators in datagrids, I seem to recall some issues with
that just FYI. Hope this helps AuSable Troutbum
'Find the The control that is firing event
Dim valCustomControl As New CustomValidator
valCustomControl = sender
'Find the Parent Cell of Validation Control
Dim cell As TableCell = valCustomControl.Parent
'Find the Datagrid Item
Dim dgItem As DataGridItem = cell.Parent
'Set the Row
Dim myRow As DataRow =
DataSet.Tables("YourTableName").Rows(dgItem.ItemIndex)
Saturday, March 24, 2012
trouble setting text values in custom controls
i have created a simple custom control with a simple text label on it. This is the ascx code for my control.
I have removed the compiler generated stuff to save space.
It has a simple text label on it - called lbBanner
PublicClass BannerAndGrid 'this is my custom control class
Inherits System.Web.UI.UserControl
ProtectedWithEvents lbBannerAs System.Web.UI.WebControls.Label 'this is my text label on my custom control
PrivateSub Page_Init(ByVal senderAs System.Object,ByVal eAs System.EventArgs)HandlesMyBase.InitInitializeComponent()
EndSub
PublicProperty Banner() ' this property should get/set the text field on the text labale on my custom control
Get
Return lbBanner.Text
EndGet
Set(ByVal Value)
lbBanner.Text = Value'WHEN I DO THIS I GET AN ERROR SAYING THAT THE OBJECT IS NOT SET TO AN INSTANCE OF THE OBJECT
EndSet
EndProperty
EndClass
I instantiate my control thus:
dim aControl as BannerAndGrid
aControl = new BannerAndGrid
aControl.Banner = "abc" ---see above property Banner--when I do this I get a reference error - WHY ?
I cannot see why I cannot set values within my control by using properties to set/get values.
Am I doing something wrong or is there a better way?
All help greatly appreciated.
Cheers.
When you are dynamically creating UserControls you should use LoadControl, rather than instantiating it in the way you are doing. For example:
dim aControl as BannerAndGrid
aControl = CType(LoadControl("/location/of/BannerAndGrid.ascx"), BannerAndGrid)
aControl.Banner = "abc" 'This will work.
Thanks Steven - the above solution worked perfectly.
Cheers
Chas (Canterbury,UK)
Trouble Using Custom Controls
------------------------
I've read a few articles and have put together a custom control. At the moment it simply outputs today's date for testing purposes. My asp page has two key lines.
Code:
<%@dotnet.itags.org. Register TagPrefix="CustomASP" Namespace="DBControls" Assembly="DBCalendar" %>
...
<CustomASP:DBCalendar Runat="Server" /
When I surf to the page I get:
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load type DBControls.DBCalendar from assembly DBCalendar, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null.
Line 26: <CustomASPB:DCalendar Runat="Server" />
Is there some variable I have to toggle in order to start using my own controls? I have it compiled and in the /bin subdirectory.Have you included the DLL for the custom control in your project?
If it makes any difference, I'm using Web Matrix, which may explain why I'm clueless what you mean when you ask if I've included that in my project.
In case someone stumbles upon this googling:
I solved my (two problems).
First, my function didn't have an arguementless constructor which apparantly is required.
Second, I used REGASM to register the DLL (Needs to have both the arguementless constructor above and admin rights on the server). Once this was done, the DLL worked properly.
This is only useful when developing with the ASP.NET Web Matrix, it's my understanding that Visual Studio.Net does this all for you.
Thursday, March 22, 2012
Trouble with Rename Controls
When I drag a control to the page, eg, a Label , the IDE automatically created a Label on the page and in the property named it with "Label1", then when I try to change the name "Label1" and press enter, I always poped up this error message
"Property value is not valid. Details: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
So I cannot change the controlID. The same as when I create other controls.
Is this a common problem?
I haven't see such problem before. Have you encountered other memory issues?
Sometimes after I restarted my computer, there would be no problem.
So I think this is just my very own case related to the underlying bugs in my computer.
Thanks!
Tuesday, March 13, 2012
Troubles reference this pointer in external class file
directory. I'm getting a _Defaullt could not be found, missing
directive or assembly reference error. Very simple example below.
Default.aspx.cs:
using System;
using System.Web.UI;
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Class1.UpdateButtonText(this);
}
}
Class1.cs
using System;
public class Class1
{
public Class1()
{
}
public static void UpdateButtonText(_Default global_Default)
{
}
}
Peter Kellner
http://peterkellner.netThis is impossible as the App_Code directory is compiled prior to your aspx
files.
-Brock
http://staff.develop.com/ballen
> I'm wanting to reference page controls from a cs file in the app_code
> directory. I'm getting a _Defaullt could not be found, missing
> directive or assembly reference error. Very simple example below.
> Default.aspx.cs:
> using System;
> using System.Web.UI;
> public partial class _Default : Page
> {
> protected void Page_Load(object sender, EventArgs e)
> {
> }
> protected void Button1_Click(object sender, EventArgs e)
> {
> Class1.UpdateButtonText(this);
> }
> }
> --
> Class1.cs
> using System;
> public class Class1
> {
> public Class1()
> {
> }
> public static void UpdateButtonText(_Default global_Default)
> {
> }
> }
> Peter Kellner
> http://peterkellner.net
On Fri, 9 Jun 2006 23:24:03 +0000 (UTC), Brock Allen
<ballen@.NOSPAMdevelop.com> wrote:
>This is impossible as the App_Code directory is compiled prior to your aspx
>files.
>-Brock
>http://staff.develop.com/ballen
>
Thanks,
Makes sense to me now. When I moved Class2 directly into the aspx.cs
file it of course worked. Hadn't really thought about the order of
compilation.
-peter
----
using System;
using System.Web.UI;
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Class2.UpdateButtonText(this);
}
}
public class Class2
{
public Class2()
{
}
public static void UpdateButtonText(_Default global_Default)
{
throw new Exception("The method or operation is not
implemented.");
}
}
Peter Kellner
http://peterkellner.net
Troubles reference this pointer in external class file
directory. I'm getting a _Defaullt could not be found, missing
directive or assembly reference error. Very simple example below.
Default.aspx.cs:
using System;
using System.Web.UI;
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Class1.UpdateButtonText(this);
}
}
------
Class1.cs
using System;
public class Class1
{
public Class1()
{
}
public static void UpdateButtonText(_Default global_Default)
{
}
}
Peter Kellner
http://peterkellner.netThis is impossible as the App_Code directory is compiled prior to your aspx
files.
-Brock
http://staff.develop.com/ballen
> I'm wanting to reference page controls from a cs file in the app_code
> directory. I'm getting a _Defaullt could not be found, missing
> directive or assembly reference error. Very simple example below.
> Default.aspx.cs:
> using System;
> using System.Web.UI;
> public partial class _Default : Page
> {
> protected void Page_Load(object sender, EventArgs e)
> {
> }
> protected void Button1_Click(object sender, EventArgs e)
> {
> Class1.UpdateButtonText(this);
> }
> }
> ------
> Class1.cs
> using System;
> public class Class1
> {
> public Class1()
> {
> }
> public static void UpdateButtonText(_Default global_Default)
> {
> }
> }
> Peter Kellner
> http://peterkellner.net
On Fri, 9 Jun 2006 23:24:03 +0000 (UTC), Brock Allen
<ballen@.NOSPAMdevelop.com> wrote:
>This is impossible as the App_Code directory is compiled prior to your aspx
>files.
>-Brock
>http://staff.develop.com/ballen
>
Thanks,
Makes sense to me now. When I moved Class2 directly into the aspx.cs
file it of course worked. Hadn't really thought about the order of
compilation.
-peter
----------------
using System;
using System.Web.UI;
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Class2.UpdateButtonText(this);
}
}
public class Class2
{
public Class2()
{
}
public static void UpdateButtonText(_Default global_Default)
{
throw new Exception("The method or operation is not
implemented.");
}
}
Peter Kellner
http://peterkellner.net