在Formview中显示新创建的记录(Display newly created record in Formview)
我在VS2012上使用asp.net这个表单。 首先,我搜索赞助人,然后去验证该顾客的信息。 该顾客信息显示在ItemTemplate(ReadOnly)中。 如果那不是他们正在寻找的赞助人,那么他们可以添加一个新的赞助人“新按钮”(asp.net代码)。 我能够获得新赞助人的ID(这是PK)。 但是,插入后我无法在表单上显示这个新创建的记录。 它仍然显示正在显示的记录。 由于这是一个formview我没有启用“分页”。
是否可以从datasource_inserted事件中调用pageload事件? 然后我可以传递新的顾客ID进行显示。 我将此ID声明为全局变量?
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load Dim lvPatronID As String lvPatronID = Request.QueryString("value1") If lvPatronID = "" Then frmPatronView.ChangeMode(FormViewMode.Insert) Else frmPatronView.ChangeMode(FormViewMode.ReadOnly) GvPatronID = lvPatronID lblPatronID.Text = GvPatronID End If Protected Sub PatronDS_Inserted(sender As Object, e As SqlDataSourceStatusEventArgs) Handles PatronDS.Inserted NewID = e.Command.Parameters("@PatronID").Value.ToString GvPatronID = NewID End Sub
I have this form on VS2012 with asp.net. First I do search for the patron, then go to verify information for that patron. This patron information is displayed in ItemTemplate(ReadOnly). If that is not the patron they are looking for then they can add a new patron with "New button" (asp.net code). I am able to get the id of the new Patron(which is PK). However I am not able to display this newly created record on the form after inserting. It still displays the record which was on display. Since this a formview I did not enable "Paging".
Is it possible to call the pageload event from datasource_inserted event? Then I can pass the new patron ID for display. I declared this ID as global variable?
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load Dim lvPatronID As String lvPatronID = Request.QueryString("value1") If lvPatronID = "" Then frmPatronView.ChangeMode(FormViewMode.Insert) Else frmPatronView.ChangeMode(FormViewMode.ReadOnly) GvPatronID = lvPatronID lblPatronID.Text = GvPatronID End If Protected Sub PatronDS_Inserted(sender As Object, e As SqlDataSourceStatusEventArgs) Handles PatronDS.Inserted NewID = e.Command.Parameters("@PatronID").Value.ToString GvPatronID = NewID End Sub
原文:https://stackoverflow.com/questions/19819173
最满意答案
您需要操纵页面的HTML。
我会使用
HtmlAgilityPack
来提取你想要的部分并将其重写为相同或另一个文件:Dim html = File.ReadAllText("c:\temp\htmlTest.htm") Dim doc = New HtmlAgilityPack.HtmlDocument() doc.LoadHtml(html) Dim target = doc.GetElementbyId("target") If target IsNot Nothing Then Dim body = doc.DocumentNode.SelectSingleNode("//body") body.RemoveAll() body.PrependChild(target) Using writer = File.OpenWrite("c:\temp\htmlTest2.htm") doc.Save(writer) End Using End If
现在你只需要在
WebBrowser
加载这个html。如果您想直接从Internet / Intranet获取HTML:
Dim client As New HtmlAgilityPack.HtmlWeb() Dim doc As HtmlAgilityPack.HtmlDocument = client.Load("http://yoururl.com") ' rest is the same as above(without doc.LoadHtml) '
You'll need to manipulate the HTML of the page.
I would use
HtmlAgilityPack
to extract the part you want and rewrite it to the same or another file:Dim html = File.ReadAllText("c:\temp\htmlTest.htm") Dim doc = New HtmlAgilityPack.HtmlDocument() doc.LoadHtml(html) Dim target = doc.GetElementbyId("target") If target IsNot Nothing Then Dim body = doc.DocumentNode.SelectSingleNode("//body") body.RemoveAll() body.PrependChild(target) Using writer = File.OpenWrite("c:\temp\htmlTest2.htm") doc.Save(writer) End Using End If
Now you just have to load this html in the
WebBrowser
.If you want to get the HTML directly from internet/intranet:
Dim client As New HtmlAgilityPack.HtmlWeb() Dim doc As HtmlAgilityPack.HtmlDocument = client.Load("http://yoururl.com") ' rest is the same as above(without doc.LoadHtml) '
相关问答
更多-
好,所以最后我相信我有一个解决方案。 Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("DIV") For Each curElement As HtmlElement In theElementCollection If curElement.OuterHtml.Contains("alert alert-danger bet") Then ...
-
单击WebBrowser控件中的按钮 - 工作示例: 带框架的主文件 - x.html: 文件放在框架中 - y.html - 带提交按钮:
-
1个问题:使用其他属性来查找该按钮 2问题:您可以关注WebBrowser Customization ,特别是“控制下载和执行”部分: WebBrowser Control使您可以控制下载,显示和执行的内容。 要获得此控制,您需要实现主机的IDispatch,以便它处理DISPID_AMBIENT_DLCONTROL。 实例化WebBrowser控件时,它将使用此ID调用IDispatch :: Invoke。 使用按位OR运算符将pvarResult设置为以下标志的组合,以指示您的首选项。 DLCTL_ ...
-
这适用于我对google.com。 这主要是上面评论中提到的同一问题的c#版本的翻译。 Dim text As String WebBrowser1.Document.ExecCommand("SelectAll", False, Nothing) WebBrowser1.Document.ExecCommand("Copy", False, Nothing) text = Clipboard.GetText() MessageBox.Show(text, "Text ...
-
这是因为它是一个弹出窗口(可能是ajax并且代码在webbrowser中是不可见的)。 但解决方案是在这里,使用此链接将100%工作: http : //www.airserver.com/register/PC 然后重定向回到你的下载页面,并做你正在做的任何事情。 It's because it's a pop up (probably ajax and the code is not viewable in the webbrowser). But the solution is here, use t ...
-
VB.NET Webbrowser如何显示我想要的指定内容(VB.NET Webbrowser How to display specified content I want)[2023-06-08]
您需要操纵页面的HTML。 我会使用HtmlAgilityPack来提取你想要的部分并将其重写为相同或另一个文件: Dim html = File.ReadAllText("c:\temp\htmlTest.htm") Dim doc = New HtmlAgilityPack.HtmlDocument() doc.LoadHtml(html) Dim target = doc.GetElementbyId("target") If target IsNot Nothing Then Dim bod ... -
您很可能不小心将Form的TransparencyKey()设置为White。 清除该字段,看看是否能解决问题。 You've most likely accidentally set the TransparencyKey() of the Form to White. Clear that field and see if that fixes the problem.
-
在vb.net中的Mouseover上获取元素的id(在webbrowser中)(Get id of element (in webbrowser) on Mouseover in vb.net)[2020-02-10]
要在MouseOver上获取元素的id,您必须: 1-声明一个HtmlDocument 。 2-将WebBrowser Document分配给HtmlDocument 。 3-创建一个事件处理程序,用于检索MouseOver上的id元素。 4-将事件处理程序分配给HtmlDocument 。 如下: Dim htmlDocument As HtmlDocument Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase ... -
webbrowser控件允许您访问网页中的元素,并且可以调用它们上的方法,因此只需单击按钮即可: webBrowser1.Document.All("yidHelperBtn").InvokeMember("click"); The webbrowser control lets you access elements within the webpage and you can invoke methods on them, so something as simple as this will cli ...
-
对于输入类型=“文件”的HTMLElement,由于安全原因, value属性是只读的 。 input type = file用户在控件中键入的值,文件名。 与其他控件不同,此值是只读的。 For HTMLElement of input type="file" value attribute is read-only, because of security reasons. input type=file The value, a file name, typed by the user into th ...