Trying to find ClientID of web form - Update

N

Neo Geshel

This works:

<form>
<asp:TextBox id="name" />
<%= name.ClientID %>
</form>

But this DOES NOT work:

<form>
<datagrid id="dg">
<asp:TextBox id="name" />
<%= name.ClientID %>
</datagrid>
</form>

and throws an error of:
Compilation Error
Compiler Error Message: BC30451: Name 'name' is not declared.

Any ida why???

TIA
....Geshel
--
**********************************************************************
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
**********************************************************************
 
T

Tom.PesterDELETETHISSS

I tried to run your code but they even lack runat=server. Try to make a better
effort before posting code.

Cheers,
Tom Pester
 
J

Juan T. Llibre

This works fine :

<form runat="server">
<datagrid id="dg">
<asp:TextBox id="name" Runat="Server" />
<%=name.ClientID %>
</datagrid>
</form>
 
J

Juan T. Llibre

I just realized you are trying to use an asp.net datagrid control,
but are using html <datagrid...> syntax.

You can't insert a textbox inside a datagrid unless
you declare it in code as an ItemTemplate.

That's why you're getting the "Name 'name' is not declared." error.

Try this, if it suits you.

<form runat="server">
<asp:datagrid id="dg" runat="server">
</asp:DataGrid>
<asp:TextBox id="name" runat="Server" />
<br/>
<%=name.ClientID %>
</form>

If you want a textbox inserted inside a datagrid,
you'd do well to study Scott Mitchell's excellent datagrid tutorial :
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

The 9th part of the tutorial explains how to do what you want to do:
http://aspnet.4guysfromrolla.com/articles/090902-1.aspx
 
N

Neo Geshel

Juan said:
This works fine :

<form runat="server">
<datagrid id="dg">
<asp:TextBox id="name" Runat="Server" />
<%=name.ClientID %>
</datagrid>
</form>


Unfortunately, not for me. It throws that error, and I don't know why.
Any clues?

...Geshel
--
**********************************************************************
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
**********************************************************************
 
N

Neo Geshel

Juan said:
I just realized you are trying to use an asp.net datagrid control,
but are using html <datagrid...> syntax.

You can't insert a textbox inside a datagrid unless
you declare it in code as an ItemTemplate.

That's why you're getting the "Name 'name' is not declared." error.

Try this, if it suits you.

<form runat="server">
<asp:datagrid id="dg" runat="server">
</asp:DataGrid>
<asp:TextBox id="name" runat="Server" />
<br/>
<%=name.ClientID %>
</form>

If you want a textbox inserted inside a datagrid,
you'd do well to study Scott Mitchell's excellent datagrid tutorial :
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

The 9th part of the tutorial explains how to do what you want to do:
http://aspnet.4guysfromrolla.com/articles/090902-1.aspx

*sigh*

Here I was hoping to save having to post nearly 300 lines of code by
providing a simplified illustration. Really, I didn't fall off the
turnip truck yesterday. I actually have a decent idea of what I should
be doing. I'm just missing a few pieces of the puzzle.

But since you've already thrown down the gauntlet, I hope you don't mind
putting your big mouth where your (probably even bigger) ego is and
going through my code to see what might be up.

Well, here goes:

<!-- begin code -->

<%@ Page Language="VB" Debug="true" %>
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.OleDb" %>
<% @Import Namespace="System.Configuration" %>
<% @Import Namespace="System.Web.UI" %>
<% @Import Namespace="System.Web.UI.WebControls" %>
<% @Import Namespace="System.Web.UI.HtmlControls" %>
<% @Import Namespace="System.IO" %>
<% @Import Namespace="System.Drawing" %>
<% @Import Namespace="System.Drawing.Imaging" %>
<%@ OutputCache Duration="20" VaryByParam="*" Location="None"
VaryByHeader="User-Agent"%>
<%@ Register TagPrefix="METZ" TagName="Meta" Src="/ssi/meta.ascx" %>
<%@ Register TagPrefix="METZ" TagName="Head" Src="/ssi/head.ascx" %>
<%@ Register TagPrefix="METZ" TagName="Foot" Src="/ssi/foot.ascx" %>
<METZ:Meta Id="ctlMeta" Runat="Server" />
<METZ:Head Id="ctlHead" Runat="Server" />
<script runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Sub BindData()
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
Dim myCmd as New OleDbCommand("SELECT * FROM tblNews", myConn)
myConn.Open()
dg.DataSource = myCmd.ExecuteReader(CommandBehavior.CloseConnection)
dg.DataBind()
myConn.Close()
End Sub
Sub dg_Edit(sender As Object, e As DataGridCommandEventArgs)
dg.ShowFooter = False
dg.EditItemIndex = e.Item.ItemIndex
BindData()
End Sub
Sub dg_Update(sender As Object, e As DataGridCommandEventArgs)
Dim imgContent as Object = e.Item.Cells(3).Controls(1)
Dim imgStream As Stream = imgContent.PostedFile.InputStream()
Dim imgLen As Integer = imgContent.PostedFile.ContentLength
Dim imgType as String = imgContent.PostedFile.ContentType
If Not imgStream Is Nothing And imgLen > 0 And (imgType =
"image/jpeg" Or imgType = "image/pjpeg") Then 'If new image was selected
for upload, then author intends to replace original image with new one
Dim imgBin() as Byte
imgBin = createThumbnail(imgStream, 200, 200)
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
Dim myCmd as New OleDbCommand("UPDATE tblNews SET [Date]=@Date,
[Title]=@Title, [Image]=@Image, [Comment]=@Comment WHERE [ID]=@ID", myConn)
myConn.Open()
myCmd.CommandType = CommandType.Text
myCmd.Parameters.Add("@Date", OleDbType.Date).Value =
String.Format("{0:dddd, dd MMMMM, yyyy}",
Convert.ToDateTime(e.Item.Cells(1).Controls(0)))'CType(e.Item.Cells(1).Controls(0),
Textbox).Text
myCmd.Parameters.Add("@Title", OleDbType.VarWChar).Value =
CType(e.Item.Cells(2).Controls(1), Textbox).Text.Replace("'","’")
myCmd.Parameters.Add("@Image", OleDbType.LongVarBinary).Value = imgBin
myCmd.Parameters.Add("@Comment", OleDbType.LongVarWChar).Value =
CType(e.Item.Cells(4).Controls(1), Textbox).Text.Replace("'","’")
myCmd.Parameters.Add("@ID", OleDbType.Integer).Value =
e.Item.Cells(0).Text
myCmd.ExecuteNonQuery()
myConn.Close()
dg.ShowFooter = True
dg.EditItemIndex = -1
BindData()
Else 'If no new image was selected for upload, then author only
intends to update the name and/or comments
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
Dim myCmd as New OleDbCommand("UPDATE tblNews SET [Date]=@Date,
[Title]=@Title, [Comment]=@Comment WHERE [ID]=@ID", myConn)
myConn.Open()
myCmd.CommandType = CommandType.Text
Dim strDate as String = CType(e.Item.Cells(1).Controls(0),
Textbox).Text
strDate = "#" & strDate & "#"
myCmd.Parameters.Add("@Date", OleDbType.Date).Value = "#" & strDate
& "#"'CType(e.Item.Cells(1).Controls(0), Textbox).Text
myCmd.Parameters.Add("@Title", OleDbType.VarWChar).Value =
CType(e.Item.Cells(2).Controls(1), Textbox).Text.Replace("'","’")
myCmd.Parameters.Add("@Comment", OleDbType.LongVarWChar).Value =
CType(e.Item.Cells(4).Controls(1), Textbox).Text.Replace("'","’")
myCmd.Parameters.Add("@ID", OleDbType.Integer).Value =
e.Item.Cells(0).Text
myCmd.ExecuteNonQuery()
myConn.Close()
dg.ShowFooter = True
dg.EditItemIndex = -1
BindData()
End If
End Sub
Sub dg_Cancel(sender As Object, e As DataGridCommandEventArgs)
dg.ShowFooter = True
dg.EditItemIndex = -1
BindData()
End Sub
Sub dg_Delete(sender As Object, e As DataGridCommandEventArgs)
If e.CommandName = "Delete" Then
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
Dim myCmd as New OleDbCommand("DELETE * From tblNews WHERE [ID] =
@ID", myConn)
myConn.Open()
myCmd.CommandType = CommandType.Text
myCmd.Parameters.Add("@ID", OleDbType.Integer).Value =
dg.DataKeys(e.Item.ItemIndex)
myCmd.ExecuteNonQuery()
myConn.Close()
dg.ShowFooter = True
dg.EditItemIndex = -1
BindData()
End If
End Sub
Sub dg_Insert(sender As Object, e As DataGridCommandEventArgs)
If e.CommandName = "Insert" Then
Dim imgContent as Object = e.Item.Cells(3).Controls(1)
Dim imgStream As Stream = imgContent.PostedFile.InputStream()
Dim imgLen As Integer = imgContent.PostedFile.ContentLength
Dim imgType as String = imgContent.PostedFile.ContentType
If Not imgStream Is Nothing And imgLen > 0 And (imgType =
"image/jpeg" Or imgType = "image/pjpeg") Then
Dim imgBin() as Byte
imgBin = createThumbnail(imgStream, 200, 200)
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
Dim myCmd as New OleDbCommand("INSERT INTO tblNews ([Date],
[Title], [Image], [Comment]) VALUES (@Date, @Title, @Image, @Comment)",
myConn)
myConn.Open()
myCmd.CommandType = CommandType.Text
myCmd.Parameters.Add("@Date", OleDbType.Date).Value =
CType(e.Item.Cells(1).Controls(0), Textbox).Text
myCmd.Parameters.Add("@Title", OleDbType.VarWChar).Value =
CType(e.Item.Cells(2).Controls(1), Textbox).Text.Replace("'","’")
myCmd.Parameters.Add("@Image", OleDbType.LongVarBinary).Value =
imgBin
myCmd.Parameters.Add("@Comment", OleDbType.LongVarWChar).Value =
CType(e.Item.Cells(4).Controls(1), Textbox).Text.Replace("'","’")
myCmd.ExecuteNonQuery()
myConn.Close()
dg.EditItemIndex = -1
BindData()
Else
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
Dim myCmd as New OleDbCommand("INSERT INTO tblNews ([Date],
[Title], [Comment]) VALUES (@Date, @Title, @Comment)", myConn)
myConn.Open()
myCmd.CommandType = CommandType.Text
myCmd.Parameters.Add("@Date", OleDbType.Date).Value =
CType(e.Item.Cells(1).Controls(0), Textbox).Text
myCmd.Parameters.Add("@Title", OleDbType.VarWChar).Value =
CType(e.Item.Cells(2).Controls(1), Textbox).Text.Replace("'","’")
myCmd.Parameters.Add("@Comment", OleDbType.LongVarWChar).Value =
CType(e.Item.Cells(4).Controls(1), Textbox).Text.Replace("'","’")
myCmd.ExecuteNonQuery()
myConn.Close()
dg.EditItemIndex = -1
BindData()
End If
End If
End Sub
Private Function createThumbnail(ByVal ImageStream As Stream, ByVal
tWidth As Double, ByVal tHeight As Double) As Byte()
Dim g As System.Drawing.Image
=System.Drawing.Image.FromStream(ImageStream)
Dim thumbSize As New Size()
thumbSize =NewthumbSize(g.Width, g.Height, tWidth, tHeight)
Dim imgOutput As New Bitmap(g, thumbSize.Width, thumbSize.Height)
Dim imgStream As New MemoryStream()
Dim thisFormat = g.RawFormat
imgOutput.Save(imgStream, thisFormat)
Dim imgbin(imgStream.Length) As Byte
imgStream.Position = 0
Dim intStatus as Integer = imgStream.Read(imgbin, 0, imgbin.Length)
g.Dispose()
imgOutput.Dispose()
Return imgbin
End Function
Function NewthumbSize(ByVal currentwidth As Double, ByVal currentheight
As Double, ByVal newWidth As Double, ByVal newHeight As Double)
Dim tempMultiplier As Double
If currentheight > currentwidth Then ' portrait
tempMultiplier = newHeight / currentheight
Else
tempMultiplier = newWidth / currentwidth
End If
Dim NewSize As New Size(CInt(currentwidth * tempMultiplier),
CInt(currentheight * tempMultiplier))
Return NewSize
End Function
Function FormatData(sItem) as String
FormatData=sItem.Replace(vbcrlf,"<br />")
End Function
</script>
<div id="content">
<div class="floatright">
<div id="timer"></div>
You are here: <a href="/default.aspx">Home</a> » News &amp; Info »
<b>News</b>
</div>
<h2>News - News Edit</h2>
<p>Here is where you add the latest news title, as well as an “eyecatch
photo†(something appropriately gorgeous) and a short description(a
paragraph or two) about the news.</p>
<p>Please Remember:</p>
<ul class="alert">
<li>If you are to <strong><em>EVER</em></strong> delete a News entry,
please understand that everything in that entry, including photos and
their associated comments, will also be deleted. Irreversably. You have
been warned.</li>
<li>All fields except the Image field must be filled, otherwise you
will get a very abrupt and nasty error message from the server itself.
As a computer, it gets very cranky when it’s given stuff it can’t work
with. You have been warned.</li>
</ul>
<form id="Form1" method="post" runat="server"
enctype="multipart/form-data">
<asp:datagrid id="dg" runat="server"
showheader="true"
showfooter="true"
autogeneratecolumns="False"
edititemstyle-backcolor="#ffcccc"
oneditcommand="dg_Edit"
onupdatecommand="dg_Update"
oncancelcommand="dg_Cancel"
ondeletecommand="dg_Delete"
onitemcommand="dg_Insert"
datakeyfield="ID"
cellpadding="10"
width="758">
<HeaderStyle backcolor="#000000" forecolor="#ffffff" font-bold="true"
horizontalalign="center" />
<ItemStyle backcolor="#ffffff" forecolor="#000000" />
<AlternatingItemStyle backcolor="#cccccc" />
<Columns>
<asp:BoundColumn DataField="ID" HeaderText="ID" ReadOnly="true"
Visible="false" />
<asp:TemplateColumn HeaderText="Date">
<FooterTemplate>
<asp:TextBox ID="add_Date" Text='<%# DateTime.Now.ToString("dddd, dd
MMMM, yyyy") %>' Runat="Server" style="display: none;" />
<img src="/images/cal.png" alt="Choose Calendar Date"
id="calendar_trigger" /> <span id="show_date"><%=
DateTime.Now.ToString("dddd, dd MMMM, yyyy") %></span>
<script type="text/javascript">
Calendar.setup({
inputField : "", // id of the input field
displayArea : "show_date", // ID of the span where
the date is to be shown
button : "calendar_trigger", // trigger button
(well, IMG in our case)
align : "br", // alignment (defaults to "Bl")
singleClick : true
});
</script>



<!-- this actually fails with the error message -->
<%= add_Date.ClientID %>



</FooterTemplate>
<ItemTemplate>
<%# String.Format("{0:dddd, dd MMMMM, yyyy}",
Convert.ToDateTime(Container.DataItem("Date"))) %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="edit_Date" Text='<%# String.Format("{0:dddd, dd MMMMM,
yyyy}", Convert.ToDateTime(Container.DataItem("Date"))) %>'
Runat="Server" style="display: none;" />
<img src="/images/cal.png" alt="Choose Calendar Date"
id="calendar_trigger" /> <span id="show_date"><%#
String.Format("{0:dddd, dd MMMMM, yyyy}",
Convert.ToDateTime(Container.DataItem("Date"))) %></span>
<script type="text/javascript">
Calendar.setup({
inputField : "", // id of the input field
displayArea : "show_date", // ID of the span where
the date is to be shown
button : "calendar_trigger", // trigger button
(well, IMG in our case)
align : "br", // alignment (defaults to "Bl")
singleClick : true
});
</script>

<!-- this actually fails with the error message -->
<%= edit_Date.ClientID %>



</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Name">
<FooterTemplate>
<asp:TextBox ID="add_Title" MaxLength="50" Runat="Server" />
</FooterTemplate>
<ItemTemplate>
<%# Container.DataItem("Title") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="edit_Title" MaxLength="50" Text='<%#
Container.DataItem("Title") %>' Runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Image">
<FooterTemplate>
<input type="file" id="add_Image" Runat="server" />
</FooterTemplate>
<ItemTemplate>
<img src="/displayimage.aspx?table=tblNews&id=<%#
Container.DataItem("ID") %>" alt="Thumbnail" />
</ItemTemplate>
<EditItemTemplate>
<input type="file" id="edit_Image" Runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Comment">
<FooterTemplate>
<asp:TextBox ID="add_Comment" Columns="30" Rows="4"
TextMode="MultiLine" Wrap="True" Runat="Server" />
</FooterTemplate>
<ItemTemplate>
<%# FormatData(Container.DataItem("Comment")) %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="edit_Comment" Columns="30" Rows="4"
TextMode="MultiLine" Wrap="True" Text='<%# Container.DataItem("Comment")
%>' Runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn HeaderText="Edit" EditText="Edit"
ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" />
<asp:TemplateColumn HeaderText="Delete">
<FooterTemplate>
<asp:Button CommandName="Insert" Text="Add" ID="btnAdd"
Runat="server" />
</FooterTemplate>
<ItemTemplate>
<asp:Button CommandName="Delete" Text="Delete" ID="btnDel"
Runat="server" />
</ItemTemplate>
<ItemStyle HorizontalAlign="center" />
<FooterStyle HorizontalAlign="center" />
</asp:TemplateColumn>
</Columns>
</asp:datagrid><%= add_Date.ClientID %>
</form>
</div>
<METZ:Foot Id="ctlFoot" Runat="Server" />

<!-- End Code -->

Have fun.

...Geshel
--
**********************************************************************
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
**********************************************************************
 
J

Juan T. Llibre

re:
I hope you don't mind putting your big mouth where your (probably even bigger) ego is

Maybe when you acquire some manners.

That, sir, was uncalled for.







But since you've already thrown down the gauntlet, I hope you don't mind
putting your big mouth where your (probably even bigger) ego is and
going through my code to see what might be up.
 
C

Cor Ligthert

Neo,

In these newsgroups is almost everybody helping for free (Including Juan).
You can take an answer as it is. I have earlier seen that the way you thread
answers in not inviting to give you answers. Probably am I not the only one
who has seen this.

I saw no parts in the help from Juan were I could add something, therefore I
don't understand your behaviour.

This message is meant to help you.

Cor
 
T

Tom.PesterDELETETHISSS

And there you go again missing the basic etiquette of newsgroup posting.
You give us 2 pages of code instead of isolating the problem to its bear
minimum in a controlled environment.
This is not to pester you but isolating the problem actually helps solving
the problem yourself and a reader will actually try to run the code (ic the
sample has a database dependency too)

If you want us to help you I suggest you change your attitude or read a newsgroup
posting FAQ. No flame intended.

Cheers,
Tom Pester
Juan said:
I just realized you are trying to use an asp.net datagrid control,
but are using html <datagrid...> syntax.

You can't insert a textbox inside a datagrid unless you declare it in
code as an ItemTemplate.

That's why you're getting the "Name 'name' is not declared." error.

Try this, if it suits you.

<form runat="server">
<asp:datagrid id="dg" runat="server">
</asp:DataGrid>
<asp:TextBox id="name" runat="Server" />
<br/>
<%=name.ClientID %>
</form>
If you want a textbox inserted inside a datagrid,
you'd do well to study Scott Mitchell's excellent datagrid tutorial :
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx
The 9th part of the tutorial explains how to do what you want to do:
http://aspnet.4guysfromrolla.com/articles/090902-1.aspx
*sigh*

Here I was hoping to save having to post nearly 300 lines of code by
providing a simplified illustration. Really, I didn't fall off the
turnip truck yesterday. I actually have a decent idea of what I should
be doing. I'm just missing a few pieces of the puzzle.

But since you've already thrown down the gauntlet, I hope you don't
mind

putting your big mouth where your (probably even bigger) ego is and
going through my code to see what might be up.

Well, here goes:

<!-- begin code -->

<%@ Page Language="VB" Debug="true" %>
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.OleDb" %>
<% @Import Namespace="System.Configuration" %>
<% @Import Namespace="System.Web.UI" %>
<% @Import Namespace="System.Web.UI.WebControls" %>
<% @Import Namespace="System.Web.UI.HtmlControls" %>
<% @Import Namespace="System.IO" %>
<% @Import Namespace="System.Drawing" %>
<% @Import Namespace="System.Drawing.Imaging" %>
<%@ OutputCache Duration="20" VaryByParam="*" Location="None"
VaryByHeader="User-Agent"%>
<%@ Register TagPrefix="METZ" TagName="Meta" Src="/ssi/meta.ascx" %
<%@ Register TagPrefix="METZ" TagName="Head" Src="/ssi/head.ascx" %

<%@ Register TagPrefix="METZ" TagName="Foot" Src="/ssi/foot.ascx" %

<METZ:Meta Id="ctlMeta" Runat="Server" />
<METZ:Head Id="ctlHead" Runat="Server" />
<script runat="server">
Sub Page Load(sender as Object, e as EventArgs)
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Sub BindData()
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
Dim myCmd as New OleDbCommand("SELECT * FROM tblNews", myConn)
myConn.Open()
dg.DataSource =
myCmd.ExecuteReader(CommandBehavior.CloseConnection)
dg.DataBind()
myConn.Close()
End Sub
Sub dg Edit(sender As Object, e As DataGridCommandEventArgs)
dg.ShowFooter = False
dg.EditItemIndex = e.Item.ItemIndex
BindData()
End Sub
Sub dg Update(sender As Object, e As DataGridCommandEventArgs)
Dim imgContent as Object = e.Item.Cells(3).Controls(1)
Dim imgStream As Stream = imgContent.PostedFile.InputStream()
Dim imgLen As Integer = imgContent.PostedFile.ContentLength
Dim imgType as String = imgContent.PostedFile.ContentType
If Not imgStream Is Nothing And imgLen > 0 And (imgType =
"image/jpeg" Or imgType = "image/pjpeg") Then 'If new image was
selecte
d
for upload, then author intends to replace original image with new one
Dim imgBin() as Byte
imgBin = createThumbnail(imgStream, 200, 200)
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
Dim myCmd as New OleDbCommand("UPDATE tblNews SET [Date]=@Date,
[Title]=@Title, [Image]=@Image, [Comment]=@Comment WHERE [ID]=@ID
", myConn)
myConn.Open()
myCmd.CommandType = CommandType.Text
myCmd.Parameters.Add("@Date", OleDbType.Date).Value =
String.Format("{0:dddd, dd MMMMM, yyyy}",
Convert.ToDateTime(e.Item.Cells(1).Controls(0)))'CType(e.Item.Cells(1)
.Co
ntrols(0),
Textbox).Text
myCmd.Parameters.Add("@Title", OleDbType.VarWChar).Value =
CType(e.Item.Cells(2).Controls(1), Textbox).Text.Replace("'","'")
myCmd.Parameters.Add("@Image", OleDbType.LongVarBinary).Value =
im
gBin
myCmd.Parameters.Add("@Comment", OleDbType.LongVarWChar).Value =
CType(e.Item.Cells(4).Controls(1), Textbox).Text.Replace("'","'")
myCmd.Parameters.Add("@ID", OleDbType.Integer).Value =
e.Item.Cells(0).Text
myCmd.ExecuteNonQuery()
myConn.Close()
dg.ShowFooter = True
dg.EditItemIndex = -1
BindData()
Else 'If no new image was selected for upload, then author only
intends to update the name and/or comments
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
Dim myCmd as New OleDbCommand("UPDATE tblNews SET [Date]=@Date,
[Title]=@Title, [Comment]=@Comment WHERE [ID]=@ID", myConn)
myConn.Open()
myCmd.CommandType = CommandType.Text
Dim strDate as String = CType(e.Item.Cells(1).Controls(0),
Textbox).Text
strDate = "#" & strDate & "#"
myCmd.Parameters.Add("@Date", OleDbType.Date).Value = "#" &
strDat
e
& "#"'CType(e.Item.Cells(1).Controls(0), Textbox).Text
myCmd.Parameters.Add("@Title", OleDbType.VarWChar).Value =
CType(e.Item.Cells(2).Controls(1), Textbox).Text.Replace("'","'")
myCmd.Parameters.Add("@Comment", OleDbType.LongVarWChar).Value =
CType(e.Item.Cells(4).Controls(1), Textbox).Text.Replace("'","'")

myCmd.Parameters.Add("@ID", OleDbType.Integer).Value =
e.Item.Cells(0).Text
myCmd.ExecuteNonQuery()
myConn.Close()
dg.ShowFooter = True
dg.EditItemIndex = -1
BindData()
End If
End Sub
Sub dg Cancel(sender As Object, e As DataGridCommandEventArgs)
dg.ShowFooter = True
dg.EditItemIndex = -1
BindData()
End Sub
Sub dg Delete(sender As Object, e As DataGridCommandEventArgs)
If e.CommandName = "Delete" Then
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
Dim myCmd as New OleDbCommand("DELETE * From tblNews WHERE [ID] =
@ID", myConn)
myConn.Open()
myCmd.CommandType = CommandType.Text
myCmd.Parameters.Add("@ID", OleDbType.Integer).Value =
dg.DataKeys(e.Item.ItemIndex)
myCmd.ExecuteNonQuery()
myConn.Close()
dg.ShowFooter = True
dg.EditItemIndex = -1
BindData()
End If
End Sub
Sub dg Insert(sender As Object, e As DataGridCommandEventArgs)
If e.CommandName = "Insert" Then
Dim imgContent as Object = e.Item.Cells(3).Controls(1)
Dim imgStream As Stream = imgContent.PostedFile.InputStream()
Dim imgLen As Integer = imgContent.PostedFile.ContentLength
Dim imgType as String = imgContent.PostedFile.ContentType
If Not imgStream Is Nothing And imgLen > 0 And (imgType =
"image/jpeg" Or imgType = "image/pjpeg") Then
Dim imgBin() as Byte
imgBin = createThumbnail(imgStream, 200, 200)
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
Dim myCmd as New OleDbCommand("INSERT INTO tblNews ([Date],
[Title], [Image], [Comment]) VALUES (@Date, @Title, @Image,
@Comment)",
myConn)
myConn.Open()
myCmd.CommandType = CommandType.Text
myCmd.Parameters.Add("@Date", OleDbType.Date).Value =
CType(e.Item.Cells(1).Controls(0), Textbox).Text
myCmd.Parameters.Add("@Title", OleDbType.VarWChar).Value =
CType(e.Item.Cells(2).Controls(1), Textbox).Text.Replace("'","'")
myCmd.Parameters.Add("@Image", OleDbType.LongVarBinary).Value =

imgBin
myCmd.Parameters.Add("@Comment", OleDbType.LongVarWChar).Value
=
CType(e.Item.Cells(4).Controls(1), Textbox).Text.Replace("'","'")

myCmd.ExecuteNonQuery()
myConn.Close()
dg.EditItemIndex = -1
BindData()
Else
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
Dim myCmd as New OleDbCommand("INSERT INTO tblNews ([Date],
[Title], [Comment]) VALUES (@Date, @Title, @Comment)", myConn)
myConn.Open()
myCmd.CommandType = CommandType.Text
myCmd.Parameters.Add("@Date", OleDbType.Date).Value =
CType(e.Item.Cells(1).Controls(0), Textbox).Text
myCmd.Parameters.Add("@Title", OleDbType.VarWChar).Value =
CType(e.Item.Cells(2).Controls(1), Textbox).Text.Replace("'","'")
myCmd.Parameters.Add("@Comment", OleDbType.LongVarWChar).Value
=

CType(e.Item.Cells(4).Controls(1), Textbox).Text.Replace("'","'")

myCmd.ExecuteNonQuery()
myConn.Close()
dg.EditItemIndex = -1
BindData()
End If
End If
End Sub
Private Function createThumbnail(ByVal ImageStream As Stream, ByVal
tWidth As Double, ByVal tHeight As Double) As Byte()
Dim g As System.Drawing.Image
=System.Drawing.Image.FromStream(ImageStream)
Dim thumbSize As New Size()
thumbSize =NewthumbSize(g.Width, g.Height, tWidth, tHeight)
Dim imgOutput As New Bitmap(g, thumbSize.Width, thumbSize.Height)
Dim imgStream As New MemoryStream()
Dim thisFormat = g.RawFormat
imgOutput.Save(imgStream, thisFormat)
Dim imgbin(imgStream.Length) As Byte
imgStream.Position = 0
Dim intStatus as Integer = imgStream.Read(imgbin, 0, imgbin.Length)
g.Dispose()
imgOutput.Dispose()
Return imgbin
End Function
Function NewthumbSize(ByVal currentwidth As Double, ByVal
currentheight
As Double, ByVal newWidth As Double, ByVal newHeight As Double)
Dim tempMultiplier As Double
If currentheight > currentwidth Then ' portrait
tempMultiplier = newHeight / currentheight
Else
tempMultiplier = newWidth / currentwidth
End If
Dim NewSize As New Size(CInt(currentwidth * tempMultiplier),
CInt(currentheight * tempMultiplier))
Return NewSize
End Function
Function FormatData(sItem) as String
FormatData=sItem.Replace(vbcrlf,"<br />")
End Function
</script>
<div id="content">
<div class="floatright">
<div id="timer"></div>
You are here: <a href="/default.aspx">Home</a> » News &amp; Inf
o »
<b>News</b>
</div>
<h2>News - News Edit</h2>
<p>Here is where you add the latest news title, as well as an "e
yecatch
photo" (something appropriately gorgeous) and a short description
(a
paragraph or two) about the news.</p>
<p>Please Remember:</p>
<ul class="alert">
<li>If you are to <strong><em>EVER</em></strong> delete a News
entry,
please understand that everything in that entry, including photos and
their associated comments, will also be deleted. Irreversably. You
have
been warned.</li>
<li>All fields except the Image field must be filled, otherwise you
will get a very abrupt and nasty error message from the server itself.
As a computer, it gets very cranky when it's given stuff it can
t work
with. You have been warned.</li>
</ul>
<form id="Form1" method="post" runat="server"
enctype="multipart/form-data">
<asp:datagrid id="dg" runat="server"
showheader="true"
showfooter="true"
autogeneratecolumns="False"
edititemstyle-backcolor="#ffcccc"
oneditcommand="dg Edit"
onupdatecommand="dg Update"
oncancelcommand="dg Cancel"
ondeletecommand="dg Delete"
onitemcommand="dg Insert"
datakeyfield="ID"
cellpadding="10"
width="758">
<HeaderStyle backcolor="#000000" forecolor="#ffffff" font-bold="
true"
horizontalalign="center" />
<ItemStyle backcolor="#ffffff" forecolor="#000000" />
<AlternatingItemStyle backcolor="#cccccc" />
<Columns>
<asp:BoundColumn DataField="ID" HeaderText="ID" ReadOnly="true
"
Visible="false" />
<asp:TemplateColumn HeaderText="Date">
<FooterTemplate>
<asp:TextBox ID="add Date" Text='<%# DateTime.Now.ToString("dddd, dd
MMMM, yyyy") %>' Runat="Server" style="display: none;" />
<img src="/images/cal.png" alt="Choose Calendar Date"
id="calendar trigger" /> <span id="show date"><%=
DateTime.Now.ToString("dddd, dd MMMM, yyyy") %></span>
<script type="text/javascript">
Calendar.setup({
inputField : "", // id of the input field
displayArea : "show date", // ID of the span
where
the date is to be shown
button : "calendar trigger", // trigger button
(well, IMG in our case)
align : "br", // alignment (defaults to
"B
l")
singleClick : true
});
</script>
<!-- this actually fails with the error message --> <%= add
Date.ClientID %>

</FooterTemplate>
<ItemTemplate>
<%# String.Format("{0:dddd, dd MMMMM, yyyy}",
Convert.ToDateTime(Container.DataItem("Date"))) %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="edit Date" Text='<%# String.Format("{0:dddd, dd MMM
MM,
yyyy}", Convert.ToDateTime(Container.DataItem("Date"))) %>'
Runat="Server" style="display: none;" />
<img src="/images/cal.png" alt="Choose Calendar Date"
id="calendar trigger" /> <span id="show date"><%#
String.Format("{0:dddd, dd MMMMM, yyyy}",
Convert.ToDateTime(Container.DataItem("Date"))) %></span>
<script type="text/javascript">
Calendar.setup({
inputField : "", // id of the input field
displayArea : "show date", // ID of the span
where
the date is to be shown
button : "calendar trigger", // trigger button
(well, IMG in our case)
align : "br", // alignment (defaults to
"B
l")
singleClick : true
});
</script>
<!-- this actually fails with the error message --> <%= edit
Date.ClientID %>

</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Name">
<FooterTemplate>
<asp:TextBox ID="add Title" MaxLength="50" Runat="Server"
/>
</FooterTemplate>
<ItemTemplate>
<%# Container.DataItem("Title") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="edit Title" MaxLength="50" Text='<%#
Container.DataItem("Title") %>' Runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Image">
<FooterTemplate>
<input type="file" id="add Image" Runat="server" />
</FooterTemplate>
<ItemTemplate>
<img src="/displayimage.aspx?table=tblNews&id=<%#
Container.DataItem("ID") %>" alt="Thumbnail" />
</ItemTemplate>
<EditItemTemplate>
<input type="file" id="edit Image" Runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Comment">
<FooterTemplate>
<asp:TextBox ID="add Comment" Columns="30" Rows="4"
TextMode="MultiLine" Wrap="True" Runat="Server" />
</FooterTemplate>
<ItemTemplate>
<%# FormatData(Container.DataItem("Comment")) %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="edit Comment" Columns="30" Rows="4"
TextMode="MultiLine" Wrap="True" Text='<%# Container.DataItem("Comm
ent")
%>' Runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn HeaderText="Edit" EditText="Edit"
ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" />
<asp:TemplateColumn HeaderText="Delete">
<FooterTemplate>
<asp:Button CommandName="Insert" Text="Add" ID="btnAdd"
Runat="server" />
</FooterTemplate>
<ItemTemplate>
<asp:Button CommandName="Delete" Text="Delete" ID="btnDel"
Runat="server" />
</ItemTemplate>
<ItemStyle HorizontalAlign="center" />
<FooterStyle HorizontalAlign="center" />
</asp:TemplateColumn>
</Columns>
</asp:datagrid><%= add Date.ClientID %>
</form>
</div>
<METZ:Foot Id="ctlFoot" Runat="Server" />
<!-- End Code -->

Have fun.

...Geshel
 
N

Neo Geshel

Juan said:
re:



Maybe when you acquire some manners.

That, sir, was uncalled for.

Yes, but so was your condescending tone, and your act of treating me
like someone who didn't even know the basics. If I was really doing my
DataGrids like that, do you think that finding the ClientID would really
be at the top of my priority list? I don't think so.

The first rule in creating any piece of code is to start with the
basics, and add things as you go along. As the saying goes, "you cannot
climb a mountain in a single step". I started out with a basic DataGrid,
and then added features (add, edit, delete, etc.) as I went along,
testing all the while to ensure I wasn't making major mistakes. Now I
have advanced to the point where I need to be able to provide the ID of
a form element to a piece of client-side JavaScript (for a pop-up DHTML
calendar). Since ASP.NET changes the ID that a form element is given to
something of its own choosing, I needed to pass this client-side ID on
to the JavaScript so it could fill the form field with the results.

My problem came when I tried to call this client-side ID. While this
works quite well:

<%= dg.ClientID %>

because "dg" is the ID of the DataGrid; I get a return of "dg", which is
the client-side ID of the Table that the DataGrid creates. However, when
I do this:

<%= formelement.ClientID %>

where "formelement" is the ID that I give an <asp:textbox />, I get the
error message no matter what I do. I cannot retrieve the client-side ID
of a form element once it is within a DataGrid, and I am stumped.

Since I have run into that problem, I have looked at over 500+ web pages
trying to discover why calling the client ID of a form element that is
within a DataGrid does not work for me. Simply put, I have tried my best
to do my homework ahead of time. To this date, I have not found an
answer. I tried to get an answer from this group by posting a stylized
chunk of code that *might* have saved me from having to post ~300 lines
of code, but instead I get a very condescending answer from you that
makes me feel like I'm a total idiot for having even THOUGHT about
posting to this ng (your reply, translated: "Go back to nursery school,
you can't even read yet!").

Since you treated me like I had just fallen off the turnip truck, like
some wet-behind-the-ears brat that needed to be treated with kid gloves
and spoon-fed the basics, I simply decided to hold up a mirror to show
you how it felt. Not a nice feeling, is it?

Next time, try not to assume the worst, ok? I tend to be like Clark Kent
- without the impressive alter ego - (insults don't affect me much), but
when you automatically assumed that I didn't even know the basics
(without even bothering to check my actual skill level or ask for my
source), I became just a wee bit pissed off. If I wasn't even getting my
DataGrid correct, I highly doubt that finding the ClientID of a form
element would even be on my radar. Hell, the asp.net parser would have
thrown errors for the DataGrid long before it would have complained
about my attempts to find the ClientID of a form element. As an MVP, you
should have known this.

Cheers.
....Geshel
--
**********************************************************************
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
**********************************************************************
 
N

Neo Geshel

Cor said:
Neo,

In these newsgroups is almost everybody helping for free (Including Juan).
You can take an answer as it is. I have earlier seen that the way you thread
answers in not inviting to give you answers. Probably am I not the onlyone
who has seen this.

I saw no parts in the help from Juan were I could add something, therefore I
don't understand your behaviour.

This message is meant to help you.

Cor

It wasn't so much *what* he said, Cor. It was *how* he said it.

He:
• Automatically assumed that I knew NOTHING, based on an intentionally
short snippet (~6 lines) of code
• Didn't even ask for my full source, to see if his assumption was
correct or not
• Pointed me toward docs that I would have *had* to master long before I
got to this stage ("you're an idiot, go back to the basics!")

Yes, there are a lot of newbies in these ng's, but I am asking a very
specific question that requires being able to do a whole bunch of things
correctly first (including correctly creating a DataGrid). If I wasn't
doing my DataGrid's correctly, the ASP.NET parser would complain about
*that* long before it complained about my attempts to retrieve the
ClientID of a form element.

Perhaps I got a little rough with him, but he could have handled things
a lot differently as well. I'm not an idiot, and I've tried my best to
do my homework (15+ Google searches and 500+ web pages) before I turned
to these ng's. I might not be an MVP, but that's no reason to treat me
like a simpleton.

...Geshel
--
**********************************************************************
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
**********************************************************************
 
J

Juan T. Llibre

re:
Perhaps I got a little rough with him

You sure did, and undeservedly, I'll add.

re:
I'm not an idiot

You sure acted like one.

re:
I might not be an MVP

Please keep that out of this discussion.

You already started this thread by claiming that you had
checked "25+ MVP sites" when -actually- *none* of the
sites you linked to are MVP sites.

So, this is the *second* time in this thread that you are unfair to MVPs.

You have some sort of "MVPness envy" and lashed out angrily
at me imagining an attitude that only exists in your mind as a
way to compensate for your having a hard time with some code.

We all have problems.
Most of us don't blame others, and particularly not MVPs, for them.







Perhaps I got a little rough with him
I'm not an idiot
I might not be an MVP


....Geshel
 
C

Chad Z. Hower aka Kudzu

Juan T. Llibre said:
You sure did, and undeservedly, I'll add.

re:

You sure acted like one.

I have an idea.

The rest of us dont care who called who what - Can we just stop it please? These are technical
groups. If you guys really want to duke it out, Im sure email would suffice or some other
newsgroup.




--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/
 
T

Tom.PesterDELETETHISSS

Ill keep it short since putting energy in this probably isnt rewarded.
Can you point out what's so offending about his post included below?

Go and spread your negative energy somewhere else. And Juan, thx for helping
me with my post dude!

Cheers,
Tom Pester
 
J

Juan T. Llibre

Perhaps a sense of what's fair should enter into
technical discussions on occasion, Chad.

If you know me, you know that I *never* enter into
discussions other than technical ones, but this was
just not the way to be greeted on a fine Sunday morning.

I didn't deserve that. Period.
 
C

Cor Ligthert

Juan,

I did not like it at all what you wrote in your message before this one.
However I think that it is better to follow the advice from Kudzu.

(When you want to know what I did not like. You are in my opinion feeding in
that an anti MVP behaviour. There is in my opinion no need for that).

Cor
 
N

Neo Geshel

Ill keep it short since putting energy in this probably isnt rewarded.
Can you point out what's so offending about his post included below?

Then I, too, will try to keep it short.

He:
• Automatically assumed that I knew NOTHING, based on an *intentionally*
short snippet (~6 lines) of code (to save having to post ~300 lines)
• Didn't even ask for my full source, to see if his assumption was
correct or not
• Pointed me toward docs that I would have *had* to master long before I
got to this stage ("you're an idiot, go back to the basics!")

It wasn't so much *what* he said as *how* he said it.
Go and spread your negative energy somewhere else.

Whatever. I had posted a *symbolic representation* of what I was trying
to do (~6 lines of hyper-simplified pseudo-code), and from that he
assumed I was a noob, a total newbie. He didn't ask for my source,
didn't confirm if what I posted was a cut-and-paste from my source
(which it wasn't).

Hell, my original question never even got answered. I should have just
posted my full source in the beginning (all ~300 lines, just to *prove*
that I am "doing the basics" correctly), and none of this would have
ever happened. Mea Culpa. I learn something new every day.

..Geshel
--
**********************************************************************
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
**********************************************************************
 
J

Juan T. Llibre

I'm going to post my last comment on this thread.

re:
(When you want to know what I did not like. You are in my opinion feeding in that an
anti MVP behaviour. There is in my opinion no need for that).

Cor,

Look at his very first post to this thread :

---000---
"About 25+ web sites I visited recommend..."

"why did the other 25+ MVP's (who recommended this method)
also get it wrong?"

As a hint, here are a few URL's where it gives the exact method that
fails for me:
http://www.syncfusion.com/FAQ/aspnet/WEB_c5c.aspx (#28.10, link doesn't
work)
http://www.startvbdotnet.com/aspsite/controls/default.aspx
http://www.thecodeproject.com/aspnet/resource_files_in_asp_net.asp
http://youngpup.net/2004/distro (second scrollbox)
http://www.ondotnet.com/pub/a/dotnet/2003/09/15/aspnet.html?page=last&x-order=date
---000---

That is, clearly, an attempt to smear MVPs by
claiming that the advice we give is "wrong".

Now, check to see exactly how many of the sites he posted
links to are run by MVPs. I'll save you the trouble : exactly none!

His response to that ? "Okay, so I exaggerate a little."

Then, his next comment is : "As an MVP, you should have known this.",
trying -again- to smear MVPs in the worst possible way by implying
that I, an MVP, should have known about code problems in code that
he had not posted yet.

Then, he erupts with : "I hope you don't mind putting
your big mouth where your (probably even bigger) ego"

To finalize, he spits this : "I might not be an MVP,
but that's no reason to treat me like a simpleton."

Those quotes reveal a tendency to smear MVPs, and while I've seen
comments like those come and go, these were the last straw for me.

Cor, *nobody* has treated him like a simpleton. I certainly didn't.

I offered an explanation. If he felt it was too simple an explanation,
pointing that out would have sufficed, without the need to repeatedly
smear neither me nor my fellow MVPs.

So, that's it. This is my last comment.

I'm off to try to mend my nice summer sunday.
It's such a beautiful sunny day, too !
 
C

Cor Ligthert

Neo,

Juan does not know you. He tried to help you. I really don't know what that
has to do with that he is awarded as MVP or the way you find that he threats
you.

You need an answer and in the way you write now, you will probably never get
it from a newsgroup.

This is the last time I give you this advice any reply on this will not be
answered by me.

Cor
 
N

Neo Geshel

Juan said:
re:

Please keep that out of this discussion.

You already started this thread by claiming that you had
checked "25+ MVP sites" when -actually- *none* of the
sites you linked to are MVP sites.

So, this is the *second* time in this thread that you are unfair to MVPs.

You have some sort of "MVPness envy" and lashed out angrily
at me imagining an attitude that only exists in your mind as a
way to compensate for your having a hard time with some code.

Fine. Allow me to amend that sentence to, "I might not be *at the skill
level of* an MVP..."

I have nothing against MVP's. My first mention was that I had gone to
many, many sites, a number of whom had articles from MVP's. Probably a
badly worded statement, mea culpa. The second mention was to point out
that I am not close your skill level yet, but I'm also nowhere near a
beginner's level. I know the basics well enough.

I would also like to make a partial apology. While I don't believe I
overreacted, I do believe that my reply was a bit too much of a personal
attack. To use a metaphor, I lunged when I should have parried. For
that, I apologise about the "big mouth" and "ego" statements.

....Geshel
--
**********************************************************************
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
**********************************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top