I have very strange issues. I have used Update Panels before and never had issues but because I am grouping listviews I get the issues. I have about 4 Update Panels on a page which I call by using the panelname.update() in code behind, and used to all work.
Then because I had to group a bunch of listviews inside each other I had to use a PageLoad to DataBind rather than actually putting the data sources on the asp page. The data all works with Listview when page loads, but now the update panels don't work on async postback at all.
If I take out uppnlSOL.Update() in code behind all the rest start working again. The update panel that causes the issue is the same one that contains the listview with the DataBind.
ASP page has all panels have childrenastriggers="false" UpdateMode="Conditional" hence I call them all from code behind. I also tried removing the uppnlSOL.Update() from code behind and placing a trigger on the uppnlSOL on the asp page. As soon as it launches I get same result. I removed the trigger then the other 3 panels work again. I need all 4 working and
I am confused, its almost like its rendering while its trying to do the update panel or something. I even tried a pause for 3 seconds after DataBind then trying updatepanel.Update() and all 4 still didn't work.
I will try to put some code below of what is sort of going on.
Protected Sub Packing_Load(sender As Object, e As EventArgs) Handles Me.Load
If IsPostBack = False Then
lvSOLGrpDelAdd.DataSource = tblDespatchA.DespatchPackSOLGrpDelAdd_Get(IDSO:=hdnIDSO.Value)
lvSOLGrpDelAdd.DataBind()
End If
End Sub
Protected Sub lvSOLGrpDelAdd_RowDataBound(sender As Object, e As ListViewItemEventArgs) Handles lvSOLGrpDelAdd.ItemDataBound
Dim lvSOLGrpDelMeth As ListView = DirectCast(e.Item.FindControl("lvSOLGrpDelMeth"), ListView)
lvSOLGrpDelMeth.DataSource = tblDespatchA.DespatchPackSOLGrpDelMeth_Get(IDSO:=hdnIDSO.Value, IDGrpDelAdd:=DataBinder.Eval(e.Item.DataItem, "IDGrpDelAdd"))
lvSOLGrpDelMeth.DataBind()
End Sub
Protected Sub lvSOLGrpDelMeth_RowDataBound(sender As Object, e As ListViewItemEventArgs)
Dim lvSOL As ListView = DirectCast(e.Item.FindControl("lvSOL"), ListView)
lvSOL.DataSource = tblDespatchA.DespatchPackSOL_Get(IDSO:=hdnIDSO.Value, IDGrpDelAdd:=DataBinder.Eval(e.Item.DataItem, "IDGrpDelAdd").ToString, IDGrpDelMeth:=DataBinder.Eval(e.Item.DataItem, "IDGrpDelMeth").ToString)
lvSOL.DataBind()
End Sub
Protected Sub btnAllocateLine_Click(sender As Object, e As EventArgs)
Dim lvRow As Object = DirectCast(sender, Object).Parent
Dim hdnIDSOL As HiddenField = DirectCast(lvRow.FindControl("hdnIDSOL"), HiddenField)
Dim lstQtyAvail As DropDownList = DirectCast(lvRow.FindControl("lstQtyAvail"), DropDownList)
tblDespatchA.DespatchPackSOLAllocate_Save(IDSO:=hdnIDSO.Value, IDSOL:=hdnIDSOL.Value, AllocateQty:=lstQtyAvail.SelectedValue)
Bind()
End Sub
Protected Sub Bind()
uppnlDOL.DataBind()
uppnlDOL.Update()
uppnlDBox.DataBind()
uppnlDBox.Update()
uppnlFooter.DataBind()
uppnlFooter.Update()
'I HAVE TO REGET FROM DATABASE CHANGES THAT HAVE HAPPEN AND
'I KNOW THIS BIT WORKS BECAUSE I HAVE TESTED THE DATA.
lvSOLGrpDelAdd.DataSource = tblDespatchA.DespatchPackSOLGrpDelAdd_Get(IDSO:=hdnIDSO.Value)
lvSOLGrpDelAdd.DataBind()
uppnlSOL.Update() ' THIS BIT WHEN I PUT IN THIS MAKES ALL THE OTHER PANELS CRASH
End Sub
Here we go again I answer my own question because nobody would help, but I will help anyone else with similar situation because I'm nice.
The reason it crashed all the other panels is because on my ASP.net page had some generated code in there using <% Response.Write("stuff here") %> and because of using the Response.Write caused it crash.
The Update Panels are doing a async post back and me calling a Response.Write() at the same time as PanelName.Update() caused this issue. I am looking for another method to write to the screen without using response.write and that would solve my 2nd problem.
Any Ideas would be appreciated.
Related
Wasn't able to find anything about this situation:
I have two RadDatePicker inside RadGrid for start and end date change
<telerik:RadDatePicker ID="rdpStartDate" Skin="Library" EnableEmbeddedSkins="false" CommandName="StartDateChange" runat="server" />
By itself, they work fine, but now I have a situation when I need to call method when their value has been changed (CommandName was added for this)
I know how to do this outside RadGrid, basically:
Protected Sub rdpStartDateChanged(ByVal sender As Object, ByVal e As Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs) Handles rdpStartDate.SelectedDateChanged
...
...
End Sub
But I wasn't able to do this inside RadGrid, because nothings seems to trigger it.
I tried to catch my command with this (works for buttons at least):
Protected Sub rgLibraryItemCommand(ByVal sender As Object, ByVal e As GridCommandEventArgs) Handles rgLibrary.ItemCommand
But, no, it doesn't see CommandName="StartDateChange"
What I need to do to be able to catch those Date change events if RadDatePicker
is placed inside RadGrid?
You need to identify the control inside the grid which triggers the action. I'm not sure which is the way for Rad to do that but it should be similar this:
Private Sub DataGridView1_ButtonClick(sender As DataGridView, e As DataGridViewCellEventArgs) _
Handles DataGridView1.CellButtonClick
'TODO - Button Clicked - Execute Code Here
End Sub
So you need to find the events for the DataGridViewRow for Rad and substitute them with the ones cell clicking events. This example should get you started.
Subscribing to an event on a control inside a RadGrid does not work the same way, because there could be multiple copies of the control or even none at all, depending on how many records are in the Data Source. Therefore, in order to subscribe to events on these controls, you have to do it manually after the data is bound, either in the ItemCreated event or ItemDataBound event.
Protected Sub rgLibraryItemCreated(ByVal sender as Object, ByVal e As GridItemEventArgs) Handles rgLibrary.ItemCreated
If TypeOf e.Item Is GridDataItem Then
Dim item As GridDataItem = e.Item
Dim rdpStartDate As RadDatePicker = item.FindControl("rdpStartDate")
AddHandler rdpStartDate.SelectedDateChanged, AddressOf rdpStartDateChanged
End If
End Sub
on textbox blank, i wanted to clear my gridview source
But i was not able to do it in vb.net.
After referring several answers i tried following unsuccessfull attempts:
grdUsers.rows.clear() : Does not work with vb.net
grdUsers.DataSource=""
grdUsers.columns.clear()
But it does not worked out.
Please help me to clear my datasource of gridview.
If your DataGridView is bound to a DataSource and you want to clear it then you can use the Nothing keyword followed by a DataBind().
grdUsers.DataSource = Nothing
grdUsers.DataBind()
Here is more information on the DataBind() method.
If you want to clear your rows when the text is empty in TextBox1, you would create a TextChanged event for your textbox ...
Private Sub TextBox1_TextChanged(sender As Object, e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text.Trim = "" Then
grdUsers.DataSource = Nothing
grdUsers.DataBind()
End If
End Sub
The Repeater control in the following test case contains two runat="server" DIVs. Each one of them gets a TextBox appened to them through the ItemCreated event of the Repeater. Both of the have AutoPostBack=True, and TextChanged event wired to txt_TextChanged. However, only the TextBox from the first level properly points to the event on the postBack of the page. The second level TextBox also causes the postBack to occur, but its value does not persist in the VIEWSTATE as well as the event does not fire.
Here's a direct link to the test case in a .zip file (uploaded to my personal website), as well as all the code needed. The project is built in VS2010 using .NET Framework 4, but the problem also exists in 1.1, 2, and 3.5.
Anybody has any ideas on what is wrong and how to make this work?
ASPX
<asp:Repeater ID="rep" runat="server">
<ItemTemplate>
<!-- first level works -->
<div id="divOutside" runat="server">
<!-- second level doesn't work -->
<div id="divInside" runat="server"></div>
</div>
</ItemTemplate>
</asp:Repeater>
Code-Behind
Public Class WebForm1
Inherits System.Web.UI.Page
Private Sub WebForm1_Init(sender As Object, e As System.EventArgs) Handles Me.Init
If Not IsPostBack Then
Dim Table As New DataTable()
Table.Columns.Add("Column1")
Dim Row As DataRow = Table.NewRow()
Row("Column1") = ""
Table.Rows.Add(Row)
rep.DataSource = Table
rep.DataBind()
End If
End Sub
Private Sub repTest_ItemCreated(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rep.ItemCreated
' outside
Dim divOutside As HtmlGenericControl = DirectCast(e.Item.FindControl("divOutside"), HtmlGenericControl)
Dim txtInput As New TextBox
With txtInput
.ID = "txtInputOutside"
.AutoPostBack = True
.Text = "Event gets called, value persists accross postBack."
.Width = 400
End With
AddHandler txtInput.TextChanged, AddressOf txt_TextChanged
divOutside.Controls.Add(txtInput)
' inside
Dim divInside As HtmlGenericControl = DirectCast(e.Item.FindControl("divInside"), HtmlGenericControl)
txtInput = New TextBox
With txtInput
.ID = "txtInputInside"
.AutoPostBack = True
.Text = "Event NOT called, value is lost during postBack."
.Width = 400
End With
AddHandler txtInput.TextChanged, AddressOf txt_TextChanged
divInside.Controls.Add(txtInput)
End Sub
Protected Sub txt_TextChanged(sender As Object, e As EventArgs)
End Sub
End Class
Is there any reason why the textboxes have to be added to the divs dynamically? why not just put them in the aspx page with the repeater then on itemdatabound enable/disable or do whatever you need to do. That should work fine.
By the way, if you were to use panels instead of divs your on the fly approach will work.
Here's a link to Microsoft Connect, where I reported this is an official bug:
https://connect.microsoft.com/VisualStudio/feedback/details/652655/asp-net-bug-in-event-linking-of-2nd-level-dynamic-controls
It contains 2 PARTIAL workarounds that work in the uploaded files section, if anybody is interested or encounters the same problem, as well as details to what I found in the Workarounds tab.
To keep it short, it is the order of getting references to the containers and the order the TextBoxes are appended to their appropriate containers which either causes the issue or works as expected.
But, not to forget the most important point, the only reason the first-level TextBox is there in the first place is to showcase what I want as functionality. If the first-level TextBox does not get appended at all, then both workarounds fail to provide any sort of fix. Please keep that in mind when reviewing that problem - finding a workaround that revolves around changing the order of the items is not an actual solution or a fully working workaround!
Thanks everyone for the input!
I have a checkbox and a panel inside of a FormView control, and I need to access them from the code behind in order to use the checkbox to determine whether or not the panel is visible. This is the code that I originally used, but since I put the controls inside of the FormView, it no longer works.
Protected Sub checkGenEd_CheckedChanged(ByVal sender As Object, _
ByVal e As System.EventArgs)
If checkGenEd.Checked = True Then
panelOutcome.Visible = True
Else
panelOutcome.Visible = False
End If
End Sub
I've started to figure this out based on other questions I looked up on here, but all of them were in C# instead of VB, so this is as far as I got:
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
If FormView1.CurrentMode = FormViewMode.Edit Then
End If
End Sub
So yeah I'm not sure exactly how to finish it. I'm sorry, this might be pretty basic, but I'm new at this and any help would be appreciated!
EDIT: here's my code now:
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
If FormView1.CurrentMode = FormViewMode.Edit Then
CheckBox checkGenEd = formview1.FindControl("checkGenEd");
Panel panelOutcome = formview1.FindControl("panelOutcome");
End If
End Sub
It's also saying that checkGenEd and panelOutcome are not declared.
EDIT: I changed my code to this but it still doesn't work:
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
If FormView1.CurrentMode = FormViewMode.Edit Then
Dim checkGenEd As CheckBox = FormView1.FindControl("checkGenEd")
Dim panelOutcome As Panel = FormView1.FindControl("panelOutcome")
If checkGenEd.Checked = True Then
panelOutcome.Visible = True
Else
panelOutcome.Visible = False
End If
End If
End Sub
There aren't any errors anymore, but nothing happens when I click the checkbox. I think there needs to be some kind of event to trigger it but I don't know how you can put an event handler inside of an event handler.
With FormView, you have to use find control, as in:
CheckBox checkGenEd = (CheckBox)formview1.FindControl("checkGenEd");
Panel panelOutcome = (Panel)formview1.FindControl("panelOutcome");
You cannot reference a control directly by ID.
HTH.
In VB you need use Directcast
Dim chk As Checkbox = DirectCast(Me.FormView1.FindControl("checkgen"), Checkbox)
FormView has its own event framework. A normal control within a FormView won't generate the postback events you are looking for. I initially made the same mistake. I wanted, like you, to generate some kind of postback that could be intercepted at the server end. Once we get back to the server we can look at the values in checkboxes etc depending on whatever business rules apply. This is what I did.
First of all put all relevant controls within an
<EditItemTemplate>
section within the FormView. (There are other Template tags that may be more appropriate). To generate the postback have a button (for example) like the one below. (This has to be within the EditItemTemplate section as well):
<asp:linkbutton id="UpdateButton"
text="Update"
commandname="Update"
runat="server"/>
You can intercept this at the server with the FormView event ItemCommand. For example:
Private Sub FormView1_ItemCommand(sender As Object, e As System.Web.UI.WebControls.FormViewCommandEventArgs) Handles FormView1.ItemCommand
'your code here
End Sub
Once you are back at the server you can then start looking at the various controls to see what they hold, using findControl if necessary. The button command shown above is an example so you might want to use another control.
i am using the WebBrowser control in asp.net page. here is the simple code:
Public Class _Default
Inherits System.Web.UI.Page
Private WithEvents browser As WebBrowser
Dim th As New Threading.Thread(AddressOf ThreadStart)
Sub ThreadStart()
browser = New WebBrowser
AddHandler browser.DocumentCompleted, AddressOf browser_DocumentCompleted
browser.Navigate("http://www.someurl.com/")
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
th.SetApartmentState(Threading.ApartmentState.STA)
th.Start()
th.Join()
End Sub
Private Sub browser_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
If browser.Document IsNot Nothing Then
Dim textbox As HtmlElement = browser.Document.GetElementById("txt1")
textbox.InnerText = "some text"
Dim button As HtmlElement = browser.Document.GetElementById("btn1")
button.InvokeMember("click")
End If
End Sub
End Class
the problem is that the webbrowser's DocumentCompleted event is not being handled. It looks like the page request finishes before anything else could happen.
what's the solution to this problem?
I really recommend reading this article(He won a price for it..)
Using the WebBrowser Control in ASP.NET
http://www.codeproject.com/KB/aspnet/WebBrowser.aspx
His solution is to create 3 threads for it to work..
I'm not sure but I have some concerns about the way you wrote your code.
You are creating and initializing your thread as soon as your class instance is created. This is before the form has been loaded.
I can't say for sure this couldn't work but I would definitely recommend creating the thread in your Load event handler, just before you use it.
I wrote some similar code in C# to generate a website thumbnail. Although that code does not use the DocumentCompleted event, I played with that event when I wrote it and it seemed to work okay. You can compare my code to yours.
Also, I should mention I have one hosting account where the code doesn't work. It seems to simply die when I call Thread.Join. However, it doesn't appear that's the issue you're running into.