Error in CallbackUpdateSchema.Callback
BC30506 Visual Basic AND ASP.net Handles clause requires a WithEvents variable defined in the containing type or one of its base types. Callback
Imports DevExpress.Xpo
Imports DevExpress.Data.Filtering
Imports DevExpress.Xpo.DB
Public Class UpdateSchema
Inherits System.Web.UI.Page
Dim uow As UnitOfWork
Private Sub Page_Init(sender As Object, e As EventArgs) Handles Me.Init
uow = XpoHelper.GetNewUnitOfWork
End Sub
Protected Sub CallbackUpdateSchema_Callback(source As Object, e As DevExpress.Web.CallbackEventArgs) Handles CallbackUpdateSchema.Callback
uow.UpdateSchema()
uow.CreateObjectTypeRecords()
End Sub
End Class
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="UpdateSchema.aspx.vb" %>
<%# Register assembly="DevExpress.Xpo.v18.2, Version=18.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Xpo" tagprefix="dx" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxButton ID="ASPxButtonUpdateSchema" runat="server" AutoPostBack="False" Text="Update Schema">
<ClientSideEvents Click="function(s, e) {CallbackUpdateSchema.PerformCallback();}" />
</dx:ASPxButton>
<dx:ASPxCallback ID="CallbackUpdateSchema" runat="server" ClientInstanceName="CallbackUpdateSchema">
</dx:ASPxCallback>
</div>
</form>
</body>
</html>
Use the overridable method OnInit
https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.page.oninit?view=netframework-4.8#System_Web_UI_Page_OnInit_System_EventArgs_
Events are meant for users. For sub-classing, you should use overridable methods instead.
Protected Overrides Sub OnInit(e As EventArgs)
MyBase.OnInit()
uow = XpoHelper.GetNewUnitOfWork
End Sub
Related
When btnSave Clicked, it will call function check().
If check() return true, the page will postback and call the btnSave_Click event.
But I think it should be check the RequiredFieldValidator first before it call fucntion check().
How can I fix it?
In Default.aspx
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="TestValidation._Default" %>
<!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></title>
</head>
<script type="text/javascript">
function check() {
return confirm("Real?");
}
</script>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" Display="Dynamic" ValidationGroup="vldGrp">AA</asp:RequiredFieldValidator>
<asp:Button ID="btnSave" runat="server" ValidationGroup="vldGrp" Text="Save" OnClientClick="return check();" />
<asp:ValidationSummary ID="vldSum" runat="server" DisplayMode="List" ShowSummary="False" ValidationGroup="vldGrp" ShowMessageBox="True" />
</div>
</form>
</body>
</html>
In Default.aspx.vb
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
End Sub
End Class
Check for the required field validator inside the function first and then perform the operations inside the function as:
function check() {
var validation = <%= RequiredFieldValidator1.ClientID %>;
if(validation.isValid()){
return confirm("Real?");
}
}
If there are many required field validators, and you need to invoke all of those, try:
function check() {
if (Page_ClientValidate()) {
return confirm("Real?");
}
}
Or even based on the name of your ValidationGroup (incase you need to invoke only selected validators)
function check() {
if (Page_ClientValidate('your group name')) {
return confirm("Real?");
}
}
Or else you can also check for the validation on server side,
Sub ValidateBtn_Click(sender As Object, e As EventArgs)
Page.Validate()
If (Page.IsValid) Then
DoSomething()
End If
End Sub
i have a problem on inheriting classes that have ASCX markup pages attached to it. See, i wrote the following ASCX markup and Codebehind:
ASCX
<%# Control Language="vb" AutoEventWireup="false" CodeBehind="HeaderBlock.ascx.vb" Inherits="CentralWeb.EMP.UI.HeaderBlock" %>
<h1>
<abbr><%= Me.Label></abbr>
<span>
<asp:Button ID="saveandreturnbutton" Text="Salvar e Voltar..." runat="server" CssClass="saveandback" />
<asp:Button ID="savebutton" Text="Salvar..." runat="server" CssClass="save" />
<asp:Button ID="return_results" Text="Voltar..." runat="server" CssClass="back" />
</span>
</h1>
Codebehind
Namespace EMP.UI
Public Class HeaderBlock
Inherits System.Web.UI.WebControls.UserControl
Protected saveandreturnbutton As Global.System.Web.UI.WebControls.Button
Protected savebutton As Global.System.Web.UI.WebControls.Button
Protected return_results As Global.System.Web.UI.WebControls.Button
Public Overridable Sub TakeAction(ByVal eventId As Integer)
'NOTHING, THIS IS THE BASE CLASS
End Sub
Private Sub saveandreturn_Click(ByVal sender As Object, ByVal e As Global.System.EventArgs) Handles saveandreturnbutton.Click
Me.TakeAction(3)
End Sub
Private Sub savebutton_Click(ByVal sender As Object, ByVal e As Global.System.EventArgs) Handles savebutton.Click
Me.TakeAction(2)
End Sub
Private Sub return_results_Click(ByVal sender As Object, ByVal e As Global.System.EventArgs) Handles return_results.Click
Me.TakeAction(1)
End Sub
End Class
End Namespace
Then, my intention is to use this base class (that have a markup), and inherit it to a non-marked up class, and refer it on a page. Like this:
Namespace EMP.UI
Public Class FrontHeader
Inherits EMP.UI.HeaderBlock
Public Overrides Sub TakeAction(ByVal I As Integer)
'CHILD CLASS ACTIONS HERE
End Sub
End Class
End Namespace
What's wrong on that test?
EDITION
After talking a litle with Tim, i'd like to do somthing like this:
<%# Control Language="vb" AutoEventWireup="false" CodeBehind="HeaderBlock.ascx.vb" Inherits="CentralWeb.EMP.UI.HeaderBlock" %>
<h1>
<abbr><%= Me.Label></abbr>
<span>
<asp:Button ID="saveandreturnbutton" Text="Salvar e Voltar..." runat="server" CssClass="saveandback" />
<asp:Button ID="savebutton" Text="Salvar..." runat="server" CssClass="save" />
<asp:Button ID="return_results" Text="Voltar..." runat="server" CssClass="back" />
</span>
</h1>
<div class="fields">
PLACE HERE CONTROLS DEPENDING ON THE PAGE WHERE THIS CLASS IS...
</div>
[Disclaimer: the original question had no Inherits System.Web.UI.UserControl]
You need to inherit from UserControl:
Public Class HeaderBlock
Inherits System.Web.UI.UserControl
....
But in general i would not inherit a class from a UserControl since that is a frontend control which should not contain too much business logic. If you want to "extend" it you could simply put another UserControl in it. The UserControl can contain one or multiple other controls, so a modular concept.
I am using Visual Studio 2010, VB.NET, target framework .NET 4.0.
I have a GridView which I am binding to some object collection, with a CommandField column that should allow edit of the selected row.
I am setting the EditIndex property correctly in the RowEditing eventhandler.
The problem is: When I click the "Edit" link that is generated, nothing apparently happens, the row gets rendered again in "view mode", not "edit mode".
But if I do some random postback, like clicking my "doNothing" button, the row gets rendered in "edit mode" in the next postback.
I have managed to reproduce the problem in the following code:
ASPX:
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="MyForm.aspx.vb" Inherits="MySandBox.MyForm" %>
<%# Register Src="MyControl.ascx" TagName="MyControl" TagPrefix="uc1" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="gvInfrator" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:CommandField ShowEditButton="true" />
<asp:BoundField HeaderText="MyField" DataField="MyField" />
</Columns>
</asp:GridView>
<asp:Button ID="btnDoNothing" runat="server" Text="Just do a postback" />
</form>
</body>
</html>
Code Behind:
Public Class MyDto
Public Property MyField As String
End Class
Public Class MyForm
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.BindMyData()
End Sub
Private Sub BindMyData()
Dim myData As New MyDto
myData.MyField = "My field value"
Me.gvInfrator.DataSource = New MyDto() {myData}
Me.gvInfrator.DataBind()
End Sub
Protected Sub gvInfrator_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvInfrator.RowEditing
Me.BindMyData()
Me.gvInfrator.EditIndex = e.NewEditIndex
End Sub
End Class
Am I doing something wrong? Is this a bug in .NET Framework 4? Is there any workaround?
You need to bind your data after you set the EditIndex of your GridView.
Protected Sub gvInfrator_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvInfrator.RowEditing
Me.gvInfrator.EditIndex = e.NewEditIndex
Me.BindMyData()
End Sub
I am trying to design a form using VB.Net for WebForms. I have been following the following link My label's text isn't changing on page_load asp.net. But the solution there is not working for me. I already have Handles Me.Load defined for my Page_Load event handler, however the result is a "blank" page, with the HTML output below.
form.aspx:
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="form.aspx.vb" Inherits="MyApp.form" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test</title>
</head>
<body>
<asp:Label id="vcode" runat="server" />
</body>
</html>
form.aspx.vb:
Imports System.Web
Public Class form
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
vcode.Text = "Why not?"
End Sub
End Class
HTML Output:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
Test
</title></head>
<body>
<span id="vcode"></span>
</body>
</html>
I suspect it has to do with the Inherits attribute, but if I take out Page_load from that class definition, I get an error:
Statement is not valid in a namespace
I also tried setting the AutoEventWireup attribute on the page to true, but no change.. still blank label.
What am I missing here?
Try adding a namespace like so:
Namespace MyApp
Public Class form Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
vcode.Text = "Why not?"
End Sub
End Class
End Namespace
Hi
I have a simple aspx file with 2 text boxes and an ajax autocomplete extender attached to textbox2
<%# Page Language="VB" AutoEventWireup="false" CodeFile="test4.aspx.vb" Inherits="test4" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!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">
<body>
<form id="form1" runat="server">
<div id="content">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server">
</asp:TextBox><br />
<asp:TextBox ID="TextBox2" runat="server">
</asp:TextBox>
</div>
<asp:AutoCompleteExtender ID="load_textBox2" TargetControlID="TextBox2" ServiceMethod="GetModelName"
UseContextKey="True" runat="server">
</asp:AutoCompleteExtender>
</form>
</body>
</html>
What i am trying to do is to call the pagemethod "GetModelName" form the aspx.vb to fillup the textbox2 with the relevent data
This is the aspx.vb code
Imports System.Web.Services
Partial Class test4
Inherits System.Web.UI.Page
Dim Model_Name_old As String()()
Dim mod_code As String()
Dim mod_name As String()
Dim cod_upper As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
//calling webservice that retunrs a jagged array
Dim ins As New localhost_insert_model.dbModel
Model_Name_old = ins.get_Model_Name("A")
mod_code = Model_Name_old(0)
mod_name = Model_Name_old(1)
cod_upper = Model_Name_old(0).GetUpperBound(0)
End Sub
<WebMethod()>
Public Function GetModelName() As String()
Return mod_name
End Function
End Class
This not working.. How can i make it work???.
Your function should be shared:
<WebMethod()>
Public Shared Function GetModelName() As String()
Return mod_name
End Function
Check that EnablePageMethods="true" in the script manager tag.