WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery' - c#

I am designing a web form for registration purpose with the drag and drop interface. When I add validation control like RegularExpressionValidator and required RequiredFieldValidator it shows this above titled message when I run it.

Turns out i found the solution.
You just need to write this in your C# code
protected void Page_Load(object sender, EventArgs e)
{
this.UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None;
}
for beginners just double click the components of your page while you are not in debugging mode double clicking a text field will direct you to the C# page.

Related

Textbox_Enter event not does nothing

I want to be able to tell when the user cliked on a textbox and is in "edit" mode. Everywhere I look I see the textbox_Enter and textbox_Leave events being used with the instructions within that and it works fine. For me however it doesn't do anything. I tried elimination as many outside factors as possible, including creating a brand new project just for testing purposes and copied some code samples yet again nothing happens when I click on the textbox. I'm using Visual Studio 2017 on Windows 10 with Visual C# Application Windows Form (.NET Framework)
Also here's a sample of the code I try to use if it helps for whatever reason
private void textbox_Enter(object sender, ControlEventArgs e)
{
label.Text = "ok";
}
First of all the type of the e parameter is not correct: It must be EventArgs, not ControlEventArgs:
private void textbox_Enter(object sender, EventArgs e)
{
// Do something
}
Second, you need to register the event in the forms designer with the textbox control in the properties window:
You need to wire up this method to the textbox enter event. Select the control and then look at the events section in the properties tab.

Handling Page lifecycle events

I am a VB.NET Developer trying to learn C# in my spare time. Please see the code below:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Load += Form1_Load;//event handler code
}
private void Form1_Load(object sender, EventArgs e)
{
string test = "got here";
}
}
This is a Windows Form app. If I add the event handler code to the constructor then Form1_Load handles the load event.
Now see the Web Forms app below:
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
string s = "got here";
}
}
Page_Load is fired without any event handler code?
My question is: Are Page Life Cycle events automatically wired to function names e.g. Page_Load automatically handles the page load in c# ASP.NET? Why does this not apply to Windows Forms? Where do you put the Event Handler code in windows forms? the .designer?
In Asp.Net you can set AutoEventWireup value. Please check this article https://support.microsoft.com/en-us/kb/324151
However when I need to handle an event the easiest way for me is going to the aspx source view, find the the runatserver control and specify my handler there. For example:
<asp:TextBox ID="txtCustomer" runat="server" />
As you type "on..." the list of events is shown (events are identified by ray icon), select OnLoad and Create.
<asp:TextBox ID="txtCustomer" OnLoad="txtCustomer_Load" runat="server" />
Now go to your cs code behind file and you'll see default handler was created there.
protected void txtCustomer_Load(object sender, EventArgs e)
{
}
Another option is going to Design View, right click on the control and go to properties. Click on the ray icon and add your handler.
Winform do not auto fire event as Asp.Net because winform has not page life Cycle.
To handle a event in winform, you select a component in design mode. Look at the right panel, you will see the events tab. There are alot event here. Double click to handle it.

PostBack Option Not Working | ASP.NET

I'm working something in Visual Web Developer 2008 Exrepss Edition.
I have 2 aspx file, Default.aspx and Default2.aspx
In Defauly.aspx Design View i have one button, in her properties on option "PostBack URL" i choose Default2.aspx
When i run site and click on Button do not open Default2.aspx?
Can you help me!
Thanks
You can also do it by click event of the button
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Default3.aspx");
}
make sure that "UseSubmitBehavior" property for the button is set to true.

ASP.NET Change the current webform

I am working at a problem in ASP.NET.
I have to create 2 windows (i think that I need to make web forms, i don't know why they said windows) one is the login form, when i press ok and the username and password is ok, I need to
show my second window (webform)
How can I do that?
I tried to do
protected void Button1_Click(object sender, EventArgs e)
{
Form2 form = new Form2();
form.SetFocus("id");
}
But it gives me error
A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property.
What should I do?
Am i right, I have to do separate webforms for thoose windows?
This is the picture from the problem that they provided
If you use webforms you can just use the following code to redirect to second form:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Webform2.aspx");
}

How do I register event handlers for a web user control in my code behind?

I'm having a problem setting up an event on a form. Here's the setup:
I was given a page with two controls, two different versions of a form for the end-user to fill out- standard and advanced. The two forms have different code and javascript, so the original dev put them in separate web user controls. Aside from the controls is a LinkButton that switches to Advanced mode.
<uc1:Standard runat="server" ID="StandardForm" />
<uc1:Advanced runat="server" ID="AdvancedForm" />
<asp:LinkButton runat="server" ID="lnkAdvanced" Text="Go To Advanced" OnClick="lnkAdvanced_Click" />
lnkAdvanced_Click just takes all the info currently entered to the advanced and flips the Visible.
My problem is that one of the bosses wants the 'Go to Advanced' button inside the standard form, but the .Visible code is on the page. So I thought it could be done using an event, but it doesn't seem to be working.
I tried to set up the event like this:
public event EventHandler AdvanceClick;
protected void lnkAdvanced_Click(object sender, EventArgs e) {
AdvanceClick(sender, e);
}
And when that didn't work, I tried to set up a delegate:
public delegate void AdvancedEventHandler(object sender, EventArgs e);
public event AdvancedEventHandler AdvanceClick;
When I moved the button to the standard form, I expected to be able to type something like:
StandardForm.AdvanceClick += new AdvancedEventHandler(GoToAdvanced);
But it doesn't seem to recognize any events within the control! I get an error: "Standard does not contain a definition for 'AdvanceClick' and no extension method 'AdvanceClick accepting a first argument of type 'Standard' could be found" It finds the other properties just fine, am I going about this the wrong way?
// in your Standard user control
public event EventHandler AdvancedClick;
private void lbtnAdvanced_Click(object sender, EventArgs e)
{
OnAdvancedClick(e);
}
protected void OnAdvancedClick(EventArgs e)
{
if (AdvancedClick != null)
AdvancedClick(this, e);
}
// on your page
StandardForm.AdvancedClick += new EventHandler(StandardForm_AdvancedClick);
private void StandardForm_AdvancedClick(object sender, EventArgs e)
{
// toggle logic here
}
If the standard form has the "Switch to advanced" button. Then, clearly, it has to know about the Advanced form and thus they seem to be pretty tightly coupled. If this is the case, it seems to me that you might as well just have the advanced form as a child of the standard form then... or better yet, merge them into one control.
If you don't like these options you might want to create a third controls which hosts the button and the two forms, along with the logic to move data between them and toggle their visibility.
I personally recommend the single control option. Having tighly coupled controls usually just leads to confusion down the road. You could loosen up the dependency in various ways, but think hard about it before you do so.
In the legacy project I currently work on we have a bunch of examples such as serach forms and search results being split up into multiple controls, but then in the end needing each others instances to function properly. As I said earlier, I wont reccomend this path.
You shouldn't need the delegate because you've created a standard event.
Try in your form load or thereabouts:
StandardForm.AdvanceClick += new EventHandler(GoToAdvanced);
Then somewhere on the page that hosts the 2 user controls
protected void GoToAdvanced(object sender, EventArgs e)
{
//Code that was previously in lnkAdvanced_Click on page.
}
Edit:
It does sound like the setup is wrong.
Can you post the markup for the Host page (at this point we are assuming it is simply the 2 user controls).
Then we are also assuming that the AdvanceClick event is declared in the Standard UC but the error message would indicate that it doesn't.. and the lnkAdvanced_Click method is in the Standard UC?
Then we are assuming the code that is attempting to attach to the custom event is declared in the Host page.
If you could confirm or deny the assumptions i'm sure we could get this cleared up.

Categories

Resources