Showing posts with label click. Show all posts
Showing posts with label click. Show all posts

Monday, March 26, 2012

Trouble editing HTML Elements version 0.6

Hi
I just encountered something very weird. I opened an existing aspx fileto make some changes. When I click on an HTML element, such as a textbox, I get the open squares that say it is selected. The Propertieswindow opens up on the right but when I try to make any changes in thatwindow, the open squares become gray squares around the HTML element.Certain properties (e.g. Type) can be changed. Others such as ID cannot be changed. However I can go into the HTML code and make thechanges there. I am using version 0.6 of ASP.NET.
Any ideas on what happened? If it helps, I am working on the Guest Book example in Chapter 10 of Mike Pope's starter book.
Danny Low

version 0.6 of ASP.NET


As far as I know there has never been a ver. 0.6 of Asp.Net. You are either using ver. 1.0, 1.1 or 2.0. Are you perhaps talking about some kind of development tool here, like Visual Studio?

As far as I know there has never been a ver. 0.6 of Asp.Net.
When you ask for version number with Help->About the window thatpops up says version 0.6 build(812). This is what I downloaded from theasp.net download section.
Danny Low

What window is this? Asp.Net is part of the .NET Framework and does not come with an Interface. There are three versions of .NET; 1.0, 1.1 and 2.0. Is it Web Matrix your are referring to??
Yes, it is Web Matrix that I am referring to. All I did was save myaspx file at a convenient stop point and shut down my system for thenight. The next day when I resumed working on the sample program, I noticed the weird behavior of not being able to edit some propertiesof the page elements when in the Design mode. And it is not just theexisting elements but any new elements that I add to the page.
Danny

Trouble firing events in code behind of user control

Ahoy

I am trying to use an asp:linkbutton on a .ascx file (user control), but it does not seem to be firing the click event in the code behind. I have put breakpoints on the first line of the event and in the page load of the user control, but it does not get to any of these. All it does is it postbacks to the server and goes through the page load event of the actual form (.aspx) that the user control is sitting on.

Any ideas?

ThanksAhoy

I am trying to use an asp:linkbutton on a .ascx file (user control), but it does not seem to be firing the click event in the code behind. I have put breakpoints on the first line of the event and in the page load of the user control, but it does not get to any of these. All it does is it postbacks to the server and goes through the page load event of the actual form (.aspx) that the user control is sitting on.

Any ideas?

Thanks

How are you assigning the Click Event to teh LinkButton and how are you handling it?
The following code is placed on the .ascx for the linkbutton's click event

Private Sub lnkLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkLogin.Click

'code

End sub

...it just never goes thru this code
Hmm that should not happen. Are you sure you are running on "Debug" mode and ASP.Net "Debugging" is enabled?
Make sure you are reloading your controls onto the form after the postback, or else the events for them wont fire. Happened to me :wave:
Yeh that was my problem - wasnt reloading the user controls on postback.

thanks patch :thumb:

Trouble getting an "Update Quantities" Button Working

Hello,

I am trying to create a click handler on an update quantities button which updates the quantities with the textbox. I am using a datalist and have addressed the "ProductID" as the DataKeyField. Can someone please help me code this?

This is the code
--------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim productID As String = Request.Params("AddToCart" )
If Not productID Is Nothing Then
Dim cart As New ShoppingCart()
cart.AddProduct(productID)
End If
BindShoppingCart()
checkoutCodeLabel.Text = "Checkout Code: "
End If
End Sub

Private Sub BindShoppingCart()
Dim cart As New ShoppingCart()
list.DataSource = cart.GetProducts
list.DataKeyField = "ProductID"
list.DataBind()

If cart.GetTotalAmount = 0 Then
placeOrderButton.Enabled = False
Else
placeOrderButton.Enabled = True
End If

TotalAmount.Text = "Total amount:"

totalAmountLabel.Text = String.Format("{0:c}", cart.GetTotalAmount())
End Sub

Private Sub btnUpdateQuantity_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdateQuantity.Click
(WHAT DO I PUT HERE??????????)
End Sub

Thanks in advance!Where you can get the total after you click the update button and page post back? looks like all the code in page_load will not run for they are in "If Not Page.IsPostBack ".

Saturday, March 24, 2012

trouble with click triggered events

i have a datagrid with delete text links.

I want a confirmation to be made after clicking delete once.


protected void DataGrid1_Del(object sender, DataGridCommandEventArgs e)
{
// make sure things that are invisible stay that way. Also make sure all fields are still blank.
ClearForm();
DataGrid1.EditItemIndex= -1;

MsgLabel.Text = "Are you sure you want to delete the record?";
MsgLabel.Visible = true;
CancelBtn.Visible = true;
DeleteBtn.Visible = true;

} // end DataGrid1_Del

private void DeleteBtn_Click(object sender, System.EventArgs e)
{
String deleteCmd = "DELETE from Inventory where InvName = @dotnet.itags.org.InvName";

SqlCommand myCommand = new SqlCommand(deleteCmd, sqlConnection1);
myCommand.Parameters.Add(new SqlParameter("@dotnet.itags.org.InvName", SqlDbType.NVarChar, 20));
myCommand.Parameters["@dotnet.itags.org.InvName"].Value = DataGrid1.DataKeys[(int)e.Item.ItemIndex];****

myCommand.Connection.Open();
myCommand.ExecuteNonQuery();

myCommand.Connection.Close();
dataSet11.Clear();
sqlDataAdapter1.Fill(dataSet11);

DataGrid1.DataBind();
}

What this code is SUPPOSED to do is, when the delete event is triggered, it will ask you if you are sure you want to delete the record. Upon clicking either delete or cancel, you will call the corresponding function.

The problem here is that, in my DeleteBtn_Click function, it does not recognize e.Item.ItemIndex, b/c this function e is System.EventArgs, instead of DataGridCommandEventArgs. (line is marked ****)

Does anyone have any suggestions to accomplish what I'm trying to do here?

Thanks,
TomIf I understand correctly, in "DataGrid1_Del()" can you save the "itemindex" in a session object and further use it in "DeleteBtn_Click()"?
Hope this helps
Yugang

_______________________

This posting is provided "AS IS" with no warranties, and confers no rights.
could you direct me to info on sessions? That is outside my "knowledge base." :D
Inside "DataGrid1_Del()" use code to record itemindex:
Session.Add("ItemIndex", e.Item.ItemIndex)

Inside "DeleteBtn_Click" get value from session:
Dim itenIndex As Integer = CInt(Session.Item("ItemIndex"))

For complete introduction, please refer:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconsessionstate.asp

Hope this helps
Yugang
I will check the link you provided, thanks.

Initially, when I modify my code as you suggested, in the:

int itemIndex = CInt(Session.Item("ItemIndex"))

line, Session does not have a definition for "Item." (C#)

Are you sure this is correct? Like I said, I'll be checking that link.
Sorry to provide you with VB Code. For C# the code should be:
int itemIndex = int.Parse(Session["ItemIndex"].ToString())
Thanks
Yugang
cool deal, so what should I use in this line?

myCommand.Parameters["@.InvName"].Value = DataGrid1.DataKeys[(int)e.Item.ItemIndex];

What would I replace e.Item.ItemIndex with?

thanks Yugang!
ooops, as i clicked post, i saw what i was looking at, stupid me. I put

myCommand.Parameters["@.InvName"].Value = DataGrid1.DataKeys[itemIndex];

right?
Yes. Please try it
Thanks
Yugang
worked like a charm, much thanks Yugang!!!

Tom
I would stay away from the Session object (this also goes with Application) object. They have many problems (like thread affinity) which cause scaling problems.

trouble with click events on dynamically created link buttons

I've read quite a few different message on various boards and for some
reason I'm still having trouble wrapping my head around this viewstate
maintenance and trying to get these dynamically created link buttons
to stay wired up to their click events.

I have what is basically a simply survey question generation page. The
page first displays a few static fields and a dropdownlist of various
options for the user to select. When the user selects an option from
the list the page will generate a new table with 5 rows of textboxes,
drop down lists, and link buttons (to delete a row if desired). There
is also a static insert button to allow users to add additional rows
if needed.

Saving the data in the fields during postback isn't an issue, but I'm
stuck in two situations depending on how I adjust the code. First is
that I put the rebuilding of the controls in the Page_load and users
are forced to click twice on the static Insert Row button to add a row
or they have to click twice on a dynamic Delete Row link button to
remove a row. If I take the rebuilding of the controls out of the
Page_Load then the Insert Row button works fine, but clicking on a
Delete Row link button causes the click event to not fire and all the
dynamic controls disappear from the page.

Does anyone have any suggestions on what I need to do to fix this so
it's written correctly and will operate as intended? (if you need more
detail or code please ask)

Thank you for your help.

--Code Snippets (this setup requires 2 clicks on a button before the
click event appears to do anything--

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then
LoadQuestionTypes()
End If

RebuildControls()

End Sub
--------
Private Sub ddlQuestionType_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ddlQuestionType.SelectedIndexChanged

...
BuildEmptyFive()
...

End Sub
--------
Private Sub BuildEmptyFive()

Dim IDArray As New ArrayList
Dim tblAnswers As New Table
Dim x As Integer

For x = 1 To 5

Dim row As New TableRow
Dim ID As String

ID = Left(System.Guid.NewGuid.ToString, 8)

Dim cell1 As New TableCell
cell1.Controls.Add(BuildTextBox("txtChoice-" & ID, 140))

Dim cell2 As New TableCell
cell2.Controls.Add(BuildDropDownList("ddlFamily-" & ID, 150,
"Family"))

Dim cell3 As New TableCell
cell3.Controls.Add(BuildDropDownList("ddlAttribute-" & ID, 150,
"Attributes"))

Dim cell4 As New TableCell
cell4.Controls.Add(BuildTextBox("txtScore-" & ID, 40))

Dim cell5 As New TableCell
cell5.Controls.Add(BuildLinkButton("lnkDelete-" & ID))

row.Cells.Add(cell1)
row.Cells.Add(cell2)
row.Cells.Add(cell3)
row.Cells.Add(cell4)
row.Cells.Add(cell5)

tblAnswers.Rows.Add(row)
IDArray.Add(ID)
Next

plhDynControls.Controls.Add(tblAnswers)

'Insert Array containing ID of each row
If IsNothing(ViewState.Item("IDArray")) Then
ViewState.Add("IDArray", IDArray)
Else
ViewState.Item("IDArray") = IDArray
End If

End Sub
----------
Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnInsert.Click

'Add a new ID to the viewstate which will cause a new row to be
inserted when the viewstate is rebuilt
Dim IDArray As ArrayList
IDArray = CType(ViewState.Item("IDArray"), ArrayList)
IDArray.Add(Left(Guid.NewGuid.ToString, 8))
ViewState.Item("IDArray") = IDArray

'RebuildControls() 'unremark this and remove from page_load to get
insert button to work perfectly (delete no workie though)

End If

End Sub
----------
Private Sub lnkDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)

Dim IDArray As ArrayList
IDArray = CType(ViewState.Item("IDArray"), ArrayList)

Dim ID As String = Right(CType(sender, LinkButton).ID.ToString, 8)
IDArray.RemoveAt(IDArray.IndexOf(ID))

ViewState.Item("IDArray") = IDArray

End Sub
-----------
this is how I generate the link button dynamically
Private Function BuildLinkButton(ByVal name As String) As LinkButton

Dim lnkLink As New LinkButton
lnkLink.ID = name
lnkLink.Text = "Delete"
AddHandler lnkLink.Click, AddressOf lnkDelete_Click

Return lnkLink

End Function
-----------
Private Sub RebuildControls()

If IsNothing(ViewState.Item("IDArray")) Then
Exit Sub
End If

Dim IDArray As ArrayList
IDArray = CType(ViewState.Item("IDArray"), ArrayList)

Dim tblAnswers As New Table
Dim x As Integer

For x = 0 To IDArray.Count - 1

Dim row As New TableRow

Dim cell1 As New TableCell
cell1.Controls.Add(BuildTextBox("txtChoice-" &
Convert.ToString(IDArray.Item(x)), 140, Request.Form.Item("txtChoice-"
& Convert.ToString(IDArray.Item(x)))))

Dim cell2 As New TableCell
cell2.Controls.Add(BuildDropDownList("ddlFamily-" &
Convert.ToString(IDArray.Item(x)), 150, "Family",
Request.Form.Item("ddlFamily-" & Convert.ToString(IDArray.Item(x)))))

Dim cell3 As New TableCell
cell3.Controls.Add(BuildDropDownList("ddlAttribute-" &
Convert.ToString(IDArray.Item(x)), 150, "Attributes",
Request.Form.Item("ddlAttribute-" &
Convert.ToString(IDArray.Item(x)))))

Dim cell4 As New TableCell
cell4.Controls.Add(BuildTextBox("txtScore-" &
Convert.ToString(IDArray.Item(x)), 40, Request.Form.Item("txtScore-" &
Convert.ToString(IDArray.Item(x)))))

Dim cell5 As New TableCell
cell5.Controls.Add(BuildLinkButton("lnkDelete-" &
Convert.ToString(IDArray.Item(x))))

row.Cells.Add(cell1)
row.Cells.Add(cell2)
row.Cells.Add(cell3)
row.Cells.Add(cell4)
row.Cells.Add(cell5)

tblAnswers.Rows.Add(row)

Next

plhDynControls.Controls.Add(tblAnswers)

End Sub
---------
Let me know if seeing anything else might help. Thanks again.Amoril

You cannot use NewGuid function for ids because it'll generate different id
on every call (it means also on every postback) so events for all dynamically
created controls will not be fired. And you want be able to find a value
entered by the user. Use x (loop counter) with contact prefix instead. Have
also in mind you should recreate controls in page_init (but do not access
viewstate at this stage because it's simply not collected yet) as they will
automatically recreate their state.

Hope it helps

"Amoril" wrote:

Quote:

Originally Posted by

I've read quite a few different message on various boards and for some
reason I'm still having trouble wrapping my head around this viewstate
maintenance and trying to get these dynamically created link buttons
to stay wired up to their click events.
>
I have what is basically a simply survey question generation page. The
page first displays a few static fields and a dropdownlist of various
options for the user to select. When the user selects an option from
the list the page will generate a new table with 5 rows of textboxes,
drop down lists, and link buttons (to delete a row if desired). There
is also a static insert button to allow users to add additional rows
if needed.
>
Saving the data in the fields during postback isn't an issue, but I'm
stuck in two situations depending on how I adjust the code. First is
that I put the rebuilding of the controls in the Page_load and users
are forced to click twice on the static Insert Row button to add a row
or they have to click twice on a dynamic Delete Row link button to
remove a row. If I take the rebuilding of the controls out of the
Page_Load then the Insert Row button works fine, but clicking on a
Delete Row link button causes the click event to not fire and all the
dynamic controls disappear from the page.
>
Does anyone have any suggestions on what I need to do to fix this so
it's written correctly and will operate as intended? (if you need more
detail or code please ask)
>
Thank you for your help.
>
--Code Snippets (this setup requires 2 clicks on a button before the
click event appears to do anything--
>
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
>
If Not IsPostBack Then
LoadQuestionTypes()
End If
>
RebuildControls()
>
End Sub
--------
Private Sub ddlQuestionType_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ddlQuestionType.SelectedIndexChanged
>
...
BuildEmptyFive()
...
>
End Sub
--------
Private Sub BuildEmptyFive()
>
Dim IDArray As New ArrayList
Dim tblAnswers As New Table
Dim x As Integer
>
For x = 1 To 5
>
Dim row As New TableRow
Dim ID As String
>
ID = Left(System.Guid.NewGuid.ToString, 8)
>
Dim cell1 As New TableCell
cell1.Controls.Add(BuildTextBox("txtChoice-" & ID, 140))
>
Dim cell2 As New TableCell
cell2.Controls.Add(BuildDropDownList("ddlFamily-" & ID, 150,
"Family"))
>
Dim cell3 As New TableCell
cell3.Controls.Add(BuildDropDownList("ddlAttribute-" & ID, 150,
"Attributes"))
>
Dim cell4 As New TableCell
cell4.Controls.Add(BuildTextBox("txtScore-" & ID, 40))
>
Dim cell5 As New TableCell
cell5.Controls.Add(BuildLinkButton("lnkDelete-" & ID))
>
row.Cells.Add(cell1)
row.Cells.Add(cell2)
row.Cells.Add(cell3)
row.Cells.Add(cell4)
row.Cells.Add(cell5)
>
tblAnswers.Rows.Add(row)
IDArray.Add(ID)
Next
>
plhDynControls.Controls.Add(tblAnswers)
>
'Insert Array containing ID of each row
If IsNothing(ViewState.Item("IDArray")) Then
ViewState.Add("IDArray", IDArray)
Else
ViewState.Item("IDArray") = IDArray
End If
>
End Sub
----------
Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnInsert.Click
>
'Add a new ID to the viewstate which will cause a new row to be
inserted when the viewstate is rebuilt
Dim IDArray As ArrayList
IDArray = CType(ViewState.Item("IDArray"), ArrayList)
IDArray.Add(Left(Guid.NewGuid.ToString, 8))
ViewState.Item("IDArray") = IDArray
>
'RebuildControls() 'unremark this and remove from page_load to get
insert button to work perfectly (delete no workie though)
>
End If
>
End Sub
----------
Private Sub lnkDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
>
Dim IDArray As ArrayList
IDArray = CType(ViewState.Item("IDArray"), ArrayList)
>
Dim ID As String = Right(CType(sender, LinkButton).ID.ToString, 8)
IDArray.RemoveAt(IDArray.IndexOf(ID))
>
ViewState.Item("IDArray") = IDArray
>
End Sub
-----------
this is how I generate the link button dynamically
Private Function BuildLinkButton(ByVal name As String) As LinkButton
>
Dim lnkLink As New LinkButton
lnkLink.ID = name
lnkLink.Text = "Delete"
AddHandler lnkLink.Click, AddressOf lnkDelete_Click
>
Return lnkLink
>
End Function
-----------
Private Sub RebuildControls()
>
If IsNothing(ViewState.Item("IDArray")) Then
Exit Sub
End If
>
Dim IDArray As ArrayList
IDArray = CType(ViewState.Item("IDArray"), ArrayList)
>
Dim tblAnswers As New Table
Dim x As Integer
>
For x = 0 To IDArray.Count - 1
>
Dim row As New TableRow
>
Dim cell1 As New TableCell
cell1.Controls.Add(BuildTextBox("txtChoice-" &
Convert.ToString(IDArray.Item(x)), 140, Request.Form.Item("txtChoice-"
& Convert.ToString(IDArray.Item(x)))))
>
Dim cell2 As New TableCell
cell2.Controls.Add(BuildDropDownList("ddlFamily-" &
Convert.ToString(IDArray.Item(x)), 150, "Family",
Request.Form.Item("ddlFamily-" & Convert.ToString(IDArray.Item(x)))))
>
Dim cell3 As New TableCell
cell3.Controls.Add(BuildDropDownList("ddlAttribute-" &
Convert.ToString(IDArray.Item(x)), 150, "Attributes",
Request.Form.Item("ddlAttribute-" &
Convert.ToString(IDArray.Item(x)))))
>
Dim cell4 As New TableCell
cell4.Controls.Add(BuildTextBox("txtScore-" &
Convert.ToString(IDArray.Item(x)), 40, Request.Form.Item("txtScore-" &
Convert.ToString(IDArray.Item(x)))))
>
Dim cell5 As New TableCell
cell5.Controls.Add(BuildLinkButton("lnkDelete-" &
Convert.ToString(IDArray.Item(x))))
>
row.Cells.Add(cell1)
row.Cells.Add(cell2)
row.Cells.Add(cell3)
row.Cells.Add(cell4)
row.Cells.Add(cell5)
>
tblAnswers.Rows.Add(row)
>
Next
>
plhDynControls.Controls.Add(tblAnswers)
>
End Sub
---------
Let me know if seeing anything else might help. Thanks again.
>
>


The only place that I use NewGuid to assign the ID's is in the
BuildEmptyFive sub (only fired after the user selects an item from the
drop down), for RebuildingControls sub I pull the ID's out of the
IDArray in the ViewState, so that shouldn't be an issue.

Moving the RebuildControls() sub from Page_Load to Page_Init actually
made the issue worse, now when I click on the static Insert Row button
or the dynamics link buttons to delete a row, all the dynamic controls
disappear. The static button fires it's event, but the link buttons
don't. Perhaps I'm not understanding what you mean by that since
without accessing the IDArray in the viewstate I won't know how many
controls need to be recreated.

Any more detail you could provide would be appreciated.
Hi again,

Oh yes, you're right but no need for that. it's easier to use row index and
a constant prefix for a particular control type (attribute, score,etc). I'll
try to provide a fully working example later on today.

take care
--
Milosz

"Amoril" wrote:

Quote:

Originally Posted by

The only place that I use NewGuid to assign the ID's is in the
BuildEmptyFive sub (only fired after the user selects an item from the
drop down), for RebuildingControls sub I pull the ID's out of the
IDArray in the ViewState, so that shouldn't be an issue.
>
Moving the RebuildControls() sub from Page_Load to Page_Init actually
made the issue worse, now when I click on the static Insert Row button
or the dynamics link buttons to delete a row, all the dynamic controls
disappear. The static button fires it's event, but the link buttons
don't. Perhaps I'm not understanding what you mean by that since
without accessing the IDArray in the viewstate I won't know how many
controls need to be recreated.
>
Any more detail you could provide would be appreciated.
>
>


Hi again,

Actually we have to use guid because you can delete row, which i didn't pick
up before. Anyway, i created fully working example for you. You should be
fine from this point

-- begin aspx code --

<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="false" CodeFile="Survey.aspx.vb"
Inherits="Survey" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList runat="server" ID="questions" AutoPostBack="true">
<asp:ListItem Text="Please Select a Question..." />
<asp:ListItem Text="What are your names?" />
<asp:ListItem Text="Name all girlfriends you have had in your life" />
</asp:DropDownList>
<asp:Panel runat="server" ID="container" />
<asp:Panel runat="server" ID="surveyOptions">
<asp:Button ID="btnAddRow" runat="server" Text="Add row" />
<asp:Button ID="btnSubmit" runat="server" Text="Submit Survey"/>
</asp:Panel>
</div>
</form>
</body>
</html>
-- end aspx code --

-- begin vb.net code --

Partial Class Survey
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
RecreateRows()
End Sub

Protected Sub questions_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles questions.SelectedIndexChanged

Const DefaultRowCount As Integer = 5

' clear everything
IDs.Clear()

If CType(sender, DropDownList).SelectedIndex >= 0 Then
' create x default empty rows
For i As Integer = 1 To DefaultRowCount
IDs.Add(GenerateId())
Next
End If

RecreateRows()

End Sub

Private Sub RecreateRows()

container.Controls.Clear()

For Each id As String In IDs
AddAnswerRow(id)
Next

surveyOptions.Visible = IDs.Count 0

End Sub

Private Const RowIdPrefix As String = "row"
Private Const TextBoxIdPrefix As String = "txt"
Private Const DropDownListIdPrefix As String = "ddl"

Private Sub AddAnswerRow(ByVal id As String)

Dim panel As Panel
Dim textBox As TextBox
Dim linkButton As LinkButton
Dim dropDownList As DropDownList

' row panel
panel = New Panel()
panel.ID = RowIdPrefix & id

' answer text box
textBox = New TextBox()
textBox.ID = TextBoxIdPrefix & id

' delete button
linkButton = New LinkButton()
linkButton.ID = "btn" & id
linkButton.Text = "delete"
linkButton.CommandArgument = id
AddHandler linkButton.Command, New CommandEventHandler(AddressOf
DeleteAnswerRow)

dropDownList = New DropDownList()
dropDownList.ID = DropDownListIdPrefix & id
dropDownList.Items.Add(New ListItem("Value0", "0"))
dropDownList.Items.Add(New ListItem("Value1", "1"))
dropDownList.Items.Add(New ListItem("Value2", "2"))

panel.Controls.Add(textBox)
panel.Controls.Add(dropDownList)
panel.Controls.Add(linkButton)
container.Controls.Add(panel)

End Sub

Private Sub DeleteAnswerRow(ByVal source As Object, ByVal e As
CommandEventArgs)

Dim id As String = CType(e.CommandArgument, String)
Dim control As Control = container.FindControl(RowIdPrefix & id)

If (Not control Is Nothing) Then
container.Controls.Remove(control)

Dim index As Integer = IDs.IndexOf(id)
If index <-1 Then
IDs.RemoveAt(index)
End If

End If

End Sub

Private ReadOnly Property IDs() As ArrayList
Get
Dim value As Object = ViewState("IDs")
If value Is Nothing Then
value = New ArrayList()
ViewState("IDs") = value
End If
Return value
End Get
End Property

Private Function GenerateId() As String
Return Guid.NewGuid().ToString("N")
End Function

Protected Sub btnAddRow_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnAddRow.Click

Dim id As String = GenerateId()

IDs.Add(id)
AddAnswerRow(id)

End Sub

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click

' obtain results
Dim textBox As TextBox
Dim dropDownList As DropDownList

For Each id As String In IDs

'
' text box value
'
textBox = CType(container.FindControl(TextBoxIdPrefix & id), TextBox)

If (Not textBox Is Nothing) Then
Dim textBoxValue As String = textBox.Text
End If

'
' drop down list selected value
'
dropDownList = CType(container.FindControl(DropDownListIdPrefix & id),
DropDownList)

If (Not dropDownList Is Nothing) Then
Dim dropDownListValue As String = dropDownList.SelectedValue
End If

Next

End Sub

End Class

-- end vb.net code --
Milosz

"Milosz Skalecki [MCAD]" wrote:

Quote:

Originally Posted by

Hi again,
>
Oh yes, you're right but no need for that. it's easier to use row index and
a constant prefix for a particular control type (attribute, score,etc). I'll
try to provide a fully working example later on today.
>
take care
--
Milosz
>
>
"Amoril" wrote:
>

Quote:

Originally Posted by

The only place that I use NewGuid to assign the ID's is in the
BuildEmptyFive sub (only fired after the user selects an item from the
drop down), for RebuildingControls sub I pull the ID's out of the
IDArray in the ViewState, so that shouldn't be an issue.

Moving the RebuildControls() sub from Page_Load to Page_Init actually
made the issue worse, now when I click on the static Insert Row button
or the dynamics link buttons to delete a row, all the dynamic controls
disappear. The static button fires it's event, but the link buttons
don't. Perhaps I'm not understanding what you mean by that since
without accessing the IDArray in the viewstate I won't know how many
controls need to be recreated.

Any more detail you could provide would be appreciated.


Excellent, thank you very much for your help, it's working great.

trouble with click events on dynamically created link buttons

I've read quite a few different message on various boards and for some
reason I'm still having trouble wrapping my head around this viewstate
maintenance and trying to get these dynamically created link buttons
to stay wired up to their click events.
I have what is basically a simply survey question generation page. The
page first displays a few static fields and a dropdownlist of various
options for the user to select. When the user selects an option from
the list the page will generate a new table with 5 rows of textboxes,
drop down lists, and link buttons (to delete a row if desired). There
is also a static insert button to allow users to add additional rows
if needed.
Saving the data in the fields during postback isn't an issue, but I'm
stuck in two situations depending on how I adjust the code. First is
that I put the rebuilding of the controls in the Page_load and users
are forced to click twice on the static Insert Row button to add a row
or they have to click twice on a dynamic Delete Row link button to
remove a row. If I take the rebuilding of the controls out of the
Page_Load then the Insert Row button works fine, but clicking on a
Delete Row link button causes the click event to not fire and all the
dynamic controls disappear from the page.
Does anyone have any suggestions on what I need to do to fix this so
it's written correctly and will operate as intended? (if you need more
detail or code please ask)
Thank you for your help.
--Code Snippets (this setup requires 2 clicks on a button before the
click event appears to do anything--
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
LoadQuestionTypes()
End If
RebuildControls()
End Sub
--
Private Sub ddlQuestionType_SelectedIndexChanged(ByV
al sender As
System.Object, ByVal e As System.EventArgs) Handles
ddlQuestionType.SelectedIndexChanged
...
BuildEmptyFive()
...
End Sub
--
Private Sub BuildEmptyFive()
Dim IDArray As New ArrayList
Dim tblAnswers As New Table
Dim x As Integer
For x = 1 To 5
Dim row As New TableRow
Dim ID As String
ID = Left(System.Guid.NewGuid.ToString, 8)
Dim cell1 As New TableCell
cell1.Controls.Add(BuildTextBox("txtChoice-" & ID, 140))
Dim cell2 As New TableCell
cell2.Controls.Add(BuildDropDownList("ddlFamily-" & ID, 150,
"Family"))
Dim cell3 As New TableCell
cell3.Controls.Add(BuildDropDownList("ddlAttribute-" & ID, 150,
"Attributes"))
Dim cell4 As New TableCell
cell4.Controls.Add(BuildTextBox("txtScore-" & ID, 40))
Dim cell5 As New TableCell
cell5.Controls.Add(BuildLinkButton("lnkDelete-" & ID))
row.Cells.Add(cell1)
row.Cells.Add(cell2)
row.Cells.Add(cell3)
row.Cells.Add(cell4)
row.Cells.Add(cell5)
tblAnswers.Rows.Add(row)
IDArray.Add(ID)
Next
plhDynControls.Controls.Add(tblAnswers)
'Insert Array containing ID of each row
If IsNothing(ViewState.Item("IDArray")) Then
ViewState.Add("IDArray", IDArray)
Else
ViewState.Item("IDArray") = IDArray
End If
End Sub
--
Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnInsert.Click
'Add a new ID to the viewstate which will cause a new row to be
inserted when the viewstate is rebuilt
Dim IDArray As ArrayList
IDArray = CType(ViewState.Item("IDArray"), ArrayList)
IDArray.Add(Left(Guid.NewGuid.ToString, 8))
ViewState.Item("IDArray") = IDArray
'RebuildControls() 'unremark this and remove from page_load to get
insert button to work perfectly (delete no workie though)
End If
End Sub
--
Private Sub lnkDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim IDArray As ArrayList
IDArray = CType(ViewState.Item("IDArray"), ArrayList)
Dim ID As String = Right(CType(sender, LinkButton).ID.ToString, 8)
IDArray.RemoveAt(IDArray.IndexOf(ID))
ViewState.Item("IDArray") = IDArray
End Sub
--
this is how I generate the link button dynamically
Private Function BuildLinkButton(ByVal name As String) As LinkButton
Dim lnkLink As New LinkButton
lnkLink.ID = name
lnkLink.Text = "Delete"
AddHandler lnkLink.Click, AddressOf lnkDelete_Click
Return lnkLink
End Function
--
Private Sub RebuildControls()
If IsNothing(ViewState.Item("IDArray")) Then
Exit Sub
End If
Dim IDArray As ArrayList
IDArray = CType(ViewState.Item("IDArray"), ArrayList)
Dim tblAnswers As New Table
Dim x As Integer
For x = 0 To IDArray.Count - 1
Dim row As New TableRow
Dim cell1 As New TableCell
cell1.Controls.Add(BuildTextBox("txtChoice-" &
Convert.ToString(IDArray.Item(x)), 140, Request.Form.Item("txtChoice-"
& Convert.ToString(IDArray.Item(x)))))
Dim cell2 As New TableCell
cell2.Controls.Add(BuildDropDownList("ddlFamily-" &
Convert.ToString(IDArray.Item(x)), 150, "Family",
Request.Form.Item("ddlFamily-" & Convert.ToString(IDArray.Item(x)))))
Dim cell3 As New TableCell
cell3.Controls.Add(BuildDropDownList("ddlAttribute-" &
Convert.ToString(IDArray.Item(x)), 150, "Attributes",
Request.Form.Item("ddlAttribute-" &
Convert.ToString(IDArray.Item(x)))))
Dim cell4 As New TableCell
cell4.Controls.Add(BuildTextBox("txtScore-" &
Convert.ToString(IDArray.Item(x)), 40, Request.Form.Item("txtScore-" &
Convert.ToString(IDArray.Item(x)))))
Dim cell5 As New TableCell
cell5.Controls.Add(BuildLinkButton("lnkDelete-" &
Convert.ToString(IDArray.Item(x))))
row.Cells.Add(cell1)
row.Cells.Add(cell2)
row.Cells.Add(cell3)
row.Cells.Add(cell4)
row.Cells.Add(cell5)
tblAnswers.Rows.Add(row)
Next
plhDynControls.Controls.Add(tblAnswers)
End Sub
--
Let me know if seeing anything else might help. Thanks again.Amoril
You cannot use NewGuid function for ids because it'll generate different id
on every call (it means also on every postback) so events for all dynamicall
y
created controls will not be fired. And you want be able to find a value
entered by the user. Use x (loop counter) with contact prefix instead. Have
also in mind you should recreate controls in page_init (but do not access
viewstate at this stage because it’s simply not collected yet) as they wil
l
automatically recreate their state.
Hope it helps
"Amoril" wrote:

> I've read quite a few different message on various boards and for some
> reason I'm still having trouble wrapping my head around this viewstate
> maintenance and trying to get these dynamically created link buttons
> to stay wired up to their click events.
> I have what is basically a simply survey question generation page. The
> page first displays a few static fields and a dropdownlist of various
> options for the user to select. When the user selects an option from
> the list the page will generate a new table with 5 rows of textboxes,
> drop down lists, and link buttons (to delete a row if desired). There
> is also a static insert button to allow users to add additional rows
> if needed.
> Saving the data in the fields during postback isn't an issue, but I'm
> stuck in two situations depending on how I adjust the code. First is
> that I put the rebuilding of the controls in the Page_load and users
> are forced to click twice on the static Insert Row button to add a row
> or they have to click twice on a dynamic Delete Row link button to
> remove a row. If I take the rebuilding of the controls out of the
> Page_Load then the Insert Row button works fine, but clicking on a
> Delete Row link button causes the click event to not fire and all the
> dynamic controls disappear from the page.
> Does anyone have any suggestions on what I need to do to fix this so
> it's written correctly and will operate as intended? (if you need more
> detail or code please ask)
> Thank you for your help.
> --Code Snippets (this setup requires 2 clicks on a button before the
> click event appears to do anything--
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> If Not IsPostBack Then
> LoadQuestionTypes()
> End If
> RebuildControls()
> End Sub
> --
> Private Sub ddlQuestionType_SelectedIndexChanged(ByV
al sender As
> System.Object, ByVal e As System.EventArgs) Handles
> ddlQuestionType.SelectedIndexChanged
> ...
> BuildEmptyFive()
> ...
> End Sub
> --
> Private Sub BuildEmptyFive()
> Dim IDArray As New ArrayList
> Dim tblAnswers As New Table
> Dim x As Integer
> For x = 1 To 5
> Dim row As New TableRow
> Dim ID As String
> ID = Left(System.Guid.NewGuid.ToString, 8)
> Dim cell1 As New TableCell
> cell1.Controls.Add(BuildTextBox("txtChoice-" & ID, 140))
> Dim cell2 As New TableCell
> cell2.Controls.Add(BuildDropDownList("ddlFamily-" & ID, 150,
> "Family"))
> Dim cell3 As New TableCell
> cell3.Controls.Add(BuildDropDownList("ddlAttribute-" & ID, 150,
> "Attributes"))
> Dim cell4 As New TableCell
> cell4.Controls.Add(BuildTextBox("txtScore-" & ID, 40))
> Dim cell5 As New TableCell
> cell5.Controls.Add(BuildLinkButton("lnkDelete-" & ID))
> row.Cells.Add(cell1)
> row.Cells.Add(cell2)
> row.Cells.Add(cell3)
> row.Cells.Add(cell4)
> row.Cells.Add(cell5)
> tblAnswers.Rows.Add(row)
> IDArray.Add(ID)
> Next
> plhDynControls.Controls.Add(tblAnswers)
> 'Insert Array containing ID of each row
> If IsNothing(ViewState.Item("IDArray")) Then
> ViewState.Add("IDArray", IDArray)
> Else
> ViewState.Item("IDArray") = IDArray
> End If
> End Sub
> --
> Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnInsert.Click
> 'Add a new ID to the viewstate which will cause a new row to be
> inserted when the viewstate is rebuilt
> Dim IDArray As ArrayList
> IDArray = CType(ViewState.Item("IDArray"), ArrayList)
> IDArray.Add(Left(Guid.NewGuid.ToString, 8))
> ViewState.Item("IDArray") = IDArray
> 'RebuildControls() 'unremark this and remove from page_load to get
> insert button to work perfectly (delete no workie though)
> End If
> End Sub
> --
> Private Sub lnkDelete_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
> Dim IDArray As ArrayList
> IDArray = CType(ViewState.Item("IDArray"), ArrayList)
> Dim ID As String = Right(CType(sender, LinkButton).ID.ToString, 8)
> IDArray.RemoveAt(IDArray.IndexOf(ID))
> ViewState.Item("IDArray") = IDArray
> End Sub
> --
> this is how I generate the link button dynamically
> Private Function BuildLinkButton(ByVal name As String) As LinkButton
> Dim lnkLink As New LinkButton
> lnkLink.ID = name
> lnkLink.Text = "Delete"
> AddHandler lnkLink.Click, AddressOf lnkDelete_Click
> Return lnkLink
> End Function
> --
> Private Sub RebuildControls()
> If IsNothing(ViewState.Item("IDArray")) Then
> Exit Sub
> End If
> Dim IDArray As ArrayList
> IDArray = CType(ViewState.Item("IDArray"), ArrayList)
> Dim tblAnswers As New Table
> Dim x As Integer
> For x = 0 To IDArray.Count - 1
> Dim row As New TableRow
> Dim cell1 As New TableCell
> cell1.Controls.Add(BuildTextBox("txtChoice-" &
> Convert.ToString(IDArray.Item(x)), 140, Request.Form.Item("txtChoice-"
> & Convert.ToString(IDArray.Item(x)))))
> Dim cell2 As New TableCell
> cell2.Controls.Add(BuildDropDownList("ddlFamily-" &
> Convert.ToString(IDArray.Item(x)), 150, "Family",
> Request.Form.Item("ddlFamily-" & Convert.ToString(IDArray.Item(x)))))
> Dim cell3 As New TableCell
> cell3.Controls.Add(BuildDropDownList("ddlAttribute-" &
> Convert.ToString(IDArray.Item(x)), 150, "Attributes",
> Request.Form.Item("ddlAttribute-" &
> Convert.ToString(IDArray.Item(x)))))
> Dim cell4 As New TableCell
> cell4.Controls.Add(BuildTextBox("txtScore-" &
> Convert.ToString(IDArray.Item(x)), 40, Request.Form.Item("txtScore-" &
> Convert.ToString(IDArray.Item(x)))))
> Dim cell5 As New TableCell
> cell5.Controls.Add(BuildLinkButton("lnkDelete-" &
> Convert.ToString(IDArray.Item(x))))
> row.Cells.Add(cell1)
> row.Cells.Add(cell2)
> row.Cells.Add(cell3)
> row.Cells.Add(cell4)
> row.Cells.Add(cell5)
> tblAnswers.Rows.Add(row)
> Next
> plhDynControls.Controls.Add(tblAnswers)
> End Sub
> --
> Let me know if seeing anything else might help. Thanks again.
>
The only place that I use NewGuid to assign the ID's is in the
BuildEmptyFive sub (only fired after the user selects an item from the
drop down), for RebuildingControls sub I pull the ID's out of the
IDArray in the ViewState, so that shouldn't be an issue.
Moving the RebuildControls() sub from Page_Load to Page_Init actually
made the issue worse, now when I click on the static Insert Row button
or the dynamics link buttons to delete a row, all the dynamic controls
disappear. The static button fires it's event, but the link buttons
don't. Perhaps I'm not understanding what you mean by that since
without accessing the IDArray in the viewstate I won't know how many
controls need to be recreated.
Any more detail you could provide would be appreciated.
Hi again,
Oh yes, you're right but no need for that. it's easier to use row index and
a constant prefix for a particular control type (attribute, score,etc). I'll
try to provide a fully working example later on today.
take care
--
Milosz
"Amoril" wrote:

> The only place that I use NewGuid to assign the ID's is in the
> BuildEmptyFive sub (only fired after the user selects an item from the
> drop down), for RebuildingControls sub I pull the ID's out of the
> IDArray in the ViewState, so that shouldn't be an issue.
> Moving the RebuildControls() sub from Page_Load to Page_Init actually
> made the issue worse, now when I click on the static Insert Row button
> or the dynamics link buttons to delete a row, all the dynamic controls
> disappear. The static button fires it's event, but the link buttons
> don't. Perhaps I'm not understanding what you mean by that since
> without accessing the IDArray in the viewstate I won't know how many
> controls need to be recreated.
> Any more detail you could provide would be appreciated.
>
Hi again,
Actually we have to use guid because you can delete row, which i didn't pick
up before. Anyway, i created fully working example for you. You should be
fine from this point
-- begin aspx code --
<%@. Page Language="VB" AutoEventWireup="false" CodeFile="Survey.aspx.vb"
Inherits="Survey" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList runat="server" ID="questions" AutoPostBack="true">
<asp:ListItem Text="Please Select a Question..." />
<asp:ListItem Text="What are your names?" />
<asp:ListItem Text="Name all girlfriends you have had in your life" />
</asp:DropDownList>
<asp:Panel runat="server" ID="container" />
<asp:Panel runat="server" ID="surveyOptions">
<asp:Button ID="btnAddRow" runat="server" Text="Add row" />
<asp:Button ID="btnSubmit" runat="server" Text="Submit Survey"/>
</asp:Panel>
</div>
</form>
</body>
</html>
-- end aspx code --
-- begin vb.net code --
Partial Class Survey
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
RecreateRows()
End Sub
Protected Sub questions_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles questions.SelectedIndexChanged
Const DefaultRowCount As Integer = 5
' clear everything
IDs.Clear()
If CType(sender, DropDownList).SelectedIndex >= 0 Then
' create x default empty rows
For i As Integer = 1 To DefaultRowCount
IDs.Add(GenerateId())
Next
End If
RecreateRows()
End Sub
Private Sub RecreateRows()
container.Controls.Clear()
For Each id As String In IDs
AddAnswerRow(id)
Next
surveyOptions.Visible = IDs.Count > 0
End Sub
Private Const RowIdPrefix As String = "row"
Private Const TextBoxIdPrefix As String = "txt"
Private Const DropDownListIdPrefix As String = "ddl"
Private Sub AddAnswerRow(ByVal id As String)
Dim panel As Panel
Dim textBox As TextBox
Dim linkButton As LinkButton
Dim dropDownList As DropDownList
' row panel
panel = New Panel()
panel.ID = RowIdPrefix & id
' answer text box
textBox = New TextBox()
textBox.ID = TextBoxIdPrefix & id
' delete button
linkButton = New LinkButton()
linkButton.ID = "btn" & id
linkButton.Text = "delete"
linkButton.CommandArgument = id
AddHandler linkButton.Command, New CommandEventHandler(AddressOf
DeleteAnswerRow)
dropDownList = New DropDownList()
dropDownList.ID = DropDownListIdPrefix & id
dropDownList.Items.Add(New ListItem("Value0", "0"))
dropDownList.Items.Add(New ListItem("Value1", "1"))
dropDownList.Items.Add(New ListItem("Value2", "2"))
panel.Controls.Add(textBox)
panel.Controls.Add(dropDownList)
panel.Controls.Add(linkButton)
container.Controls.Add(panel)
End Sub
Private Sub DeleteAnswerRow(ByVal source As Object, ByVal e As
CommandEventArgs)
Dim id As String = CType(e.CommandArgument, String)
Dim control As Control = container.FindControl(RowIdPrefix & id)
If (Not control Is Nothing) Then
container.Controls.Remove(control)
Dim index As Integer = IDs.IndexOf(id)
If index <> -1 Then
IDs.RemoveAt(index)
End If
End If
End Sub
Private ReadOnly Property IDs() As ArrayList
Get
Dim value As Object = ViewState("IDs")
If value Is Nothing Then
value = New ArrayList()
ViewState("IDs") = value
End If
Return value
End Get
End Property
Private Function GenerateId() As String
Return Guid.NewGuid().ToString("N")
End Function
Protected Sub btnAddRow_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnAddRow.Click
Dim id As String = GenerateId()
IDs.Add(id)
AddAnswerRow(id)
End Sub
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click
' obtain results
Dim textBox As TextBox
Dim dropDownList As DropDownList
For Each id As String In IDs
'
' text box value
'
textBox = CType(container.FindControl(TextBoxIdPrefix & id), TextBox)
If (Not textBox Is Nothing) Then
Dim textBoxValue As String = textBox.Text
End If
'
' drop down list selected value
'
dropDownList = CType(container.FindControl(DropDownListIdPrefix & id),
DropDownList)
If (Not dropDownList Is Nothing) Then
Dim dropDownListValue As String = dropDownList.SelectedValue
End If
Next
End Sub
End Class
-- end vb.net code --
Milosz
"Milosz Skalecki [MCAD]" wrote:
> Hi again,
> Oh yes, you're right but no need for that. it's easier to use row index an
d
> a constant prefix for a particular control type (attribute, score,etc). I'
ll
> try to provide a fully working example later on today.
> take care
> --
> Milosz
>
> "Amoril" wrote:
>
Excellent, thank you very much for your help, it's working great.

Thursday, March 22, 2012

Trouble with getting start ?

Hi everyone,

I have a problem with getting my project run. I put everything in my .aspx design but when i click "Start", IE appears with nothing inside and the address in IE is empty ? Anyone helps me pleaseDid you specify your start page?, if not in VS right click and PICK "Set as Start Page"...
I am using Web Matrix, where should i right click ? I didn't see "Set as Start Page" ?
Hi Harmonic,

I've been using .net web matrix for just about a week so i might say something wrong or that doesn't make much sense, but anyway I had your same problem and this is what i do:

I save my files in a folder called "test" which i created in my root folder (wwwroot) of IIS

then i open my browser and navigate to http://localhost/test/nameofthefile.aspx

hope it helps

trouble with image

Hi guys,
I'm a beginner of asp.net:( When I click a
(System.Web.UI.WebControls.)Button on a page,of course,its' click event has
been assigned,the images on this page should be refreshed,right?These
images' imageurl are such as "getpic.aspx?id=xxx".But refresh doesn't
happen,why?
Much thanx.Presumably because the browser has cached the image that was at that
URL previously. If you want to load a different image for each screen
refresh then add a random number, or datestamp to the URL for your
image, that way the browser receives a different URL and will
redownload the image.
"Flinky Wisty Pomm" <Pathogenix@.gmail.com> wrote in message
news:1144079199.958679.87150@.v46g2000cwv.googlegroups.com...
> Presumably because the browser has cached the image that was at that
> URL previously. If you want to load a different image for each screen
> refresh then add a random number, or datestamp to the URL for your
> image, that way the browser receives a different URL and will
> redownload the image.
>
For a production environment, where the image may not change much, then I
would recommend removing the auto-generated number so that the cache
displays the image. Otherwise, the client may download more than it needs
too...<shrug>
Mythran
Thanx for your advice.My current problem: in the button click event,picture
stored in db is changed. "GetPic.aspx?id=xxx" is used to get pic from
db.What I want is after click,the image on this page should display the new
content(reload from db).But now db has updated successfully,the page is
still here,no change.
"Flinky Wisty Pomm" <Pathogenix@.gmail.com>
':1144079199.958679.87150@.v46g2000cwv.googlegroups.com...
> Presumably because the browser has cached the image that was at that
> URL previously. If you want to load a different image for each screen
> refresh then add a random number, or datestamp to the URL for your
> image, that way the browser receives a different URL and will
> redownload the image.
>
"removing the auto-generated number so that the cache displays the image"
Sorry but I have no idea how to remove,thanx.
"Mythran" <kip_potter@.hotmail.comREMOVETRAIL>
':eeIMsezVGHA.5044@.TK2MSFTNGP09.phx.gbl...
> "Flinky Wisty Pomm" <Pathogenix@.gmail.com> wrote in message
> news:1144079199.958679.87150@.v46g2000cwv.googlegroups.com...
> For a production environment, where the image may not change much, then I
> would recommend removing the auto-generated number so that the cache
> displays the image. Otherwise, the client may download more than it needs
> too...<shrug>
> Mythran
>
Much thanx,Flinky Wisty Pomm && Mythran:)
I got it,add a RequiredFieldValidator on the page and bind it to any
control,then nothing bother me:) But who can tell me why?puzzling
"tjer" <tj@.tj.edu.cn> д?:#jIoo1xVGHA.5288@.TK2MSFTNGP14.phx.gbl...
> Hi guys,
> I'm a beginner of asp.net:( When I click a
> (System.Web.UI.WebControls.)Button on a page,of course,its' click event
has
> been assigned,the images on this page should be refreshed,right?These
> images' imageurl are such as "getpic.aspx?id=xxx".But refresh doesn't
> happen,why?
> Much thanx.
>

trouble with image

Hi guys,

I'm a beginner of asp.net:( When I click a
(System.Web.UI.WebControls.)Button on a page,of course,its' click event has
been assigned,the images on this page should be refreshed,right?These
images' imageurl are such as "getpic.aspx?id=xxx".But refresh doesn't
happen,why?

Much thanx.Presumably because the browser has cached the image that was at that
URL previously. If you want to load a different image for each screen
refresh then add a random number, or datestamp to the URL for your
image, that way the browser receives a different URL and will
redownload the image.
"Flinky Wisty Pomm" <Pathogenix@.gmail.com> wrote in message
news:1144079199.958679.87150@.v46g2000cwv.googlegro ups.com...
> Presumably because the browser has cached the image that was at that
> URL previously. If you want to load a different image for each screen
> refresh then add a random number, or datestamp to the URL for your
> image, that way the browser receives a different URL and will
> redownload the image.

For a production environment, where the image may not change much, then I
would recommend removing the auto-generated number so that the cache
displays the image. Otherwise, the client may download more than it needs
too...<shrug
Mythran
Thanx for your advice.My current problem: in the button click event,picture
stored in db is changed. "GetPic.aspx?id=xxx" is used to get pic from
db.What I want is after click,the image on this page should display the new
content(reload from db).But now db has updated successfully,the page is
still here,no change.

"Flinky Wisty Pomm" <Pathogenix@.gmail.com>
??:1144079199.958679.87150@.v46g2000cwv.googleg roups.com...
> Presumably because the browser has cached the image that was at that
> URL previously. If you want to load a different image for each screen
> refresh then add a random number, or datestamp to the URL for your
> image, that way the browser receives a different URL and will
> redownload the image.
"removing the auto-generated number so that the cache displays the image"

Sorry but I have no idea how to remove,thanx.

"Mythran" <kip_potter@.hotmail.comREMOVETRAIL>
??:eeIMsezVGHA.5044@.TK2MSFTNGP09.phx.gbl...
> "Flinky Wisty Pomm" <Pathogenix@.gmail.com> wrote in message
> news:1144079199.958679.87150@.v46g2000cwv.googlegro ups.com...
> > Presumably because the browser has cached the image that was at that
> > URL previously. If you want to load a different image for each screen
> > refresh then add a random number, or datestamp to the URL for your
> > image, that way the browser receives a different URL and will
> > redownload the image.
> For a production environment, where the image may not change much, then I
> would recommend removing the auto-generated number so that the cache
> displays the image. Otherwise, the client may download more than it needs
> too...<shrug>
> Mythran
Much thanx,Flinky Wisty Pomm && Mythran:)

I got it,add a RequiredFieldValidator on the page and bind it to any
control,then nothing bother me:) But who can tell me why?puzzling

"tjer" <tj@.tj.edu.cn> д?:#jIoo1xVGHA.5288@.TK2MSFTNGP14.phx.gbl ...
> Hi guys,
> I'm a beginner of asp.net:( When I click a
> (System.Web.UI.WebControls.)Button on a page,of course,its' click event
has
> been assigned,the images on this page should be refreshed,right?These
> images' imageurl are such as "getpic.aspx?id=xxx".But refresh doesn't
> happen,why?
> Much thanx.

Trouble with popups

I have a aspx page and I want to do a popup to another page when my page is loaded and when click a button into a data grid. How can I do it ?

I have tried the next but It don`t work.
with a button out of a datagrid it works fine.

miboton is the name of a button in an itemtemplate into a datagrid. The compiler not recognize the name of the control. Why is it in a datagrid??

thanks in advance

Sub Page_Load(sender As Object, e As EventArgs)
openpopup(miboton,"http://www.baanfans.com", "ventana", 200, 300)
end Sub

Sub OpenPopUp(ByVal opener As System.Web.UI.WebControls.WebControl, ByVal PagePath As String, ByVal windowName As String, ByVal width As Integer, ByVal height As Integer)

Dim clientScript As String
Dim windowAttribs As String

windowAttribs = "width=" & width & "px," & _
"height=" & height & "px," & _
"left='+((screen.width -" & width & ") / 2)+'," & _
"top='+ (screen.height - " & height & ") / 2+'"

clientScript = "window.open('" & PagePath & "','" & windowName & "','" & windowAttribs & "');return false;"
opener.Attributes.Add("onclick", clientScript)

End SubMaybe you can take a look atthis control.

Grz, Kris.
Hello, you would like to check this link:Pop Up Window.

Good Luck.
the code that I posted above works fine. The trouble is what I want is to do a pop up when my page is loaded and click a button that it is in an item template. I have any trouble to do the popup with a button alone.

thanks for your reply.
Hello, could u please check this article.Embedding Java Scripts in ASP.NET

Good Luck.