EzDevInfo.com

webforms interview questions

Top webforms frequently asked interview questions

Turning off the WebFormViewEngine when using razor?

I downloaded Glimpse this morning to try it out and noticed this when I click on the views tab:

Glimpse Views Tab

It checks all of the loaded view engines. I found where the RazorViewEngine is specified in web.config, but I couldn't find where the WebFormViewEngine was. Since I know my project will never have an web form view in it,

  1. Is it ok/safe to turn off WebFormViewEngine?
  2. How can I turn off WebFormViewEngine?

Source: (StackOverflow)

jQuery Validation plugin in ASP.NET Web Forms

I would really like use the jQuery Validation plugin in my ASP.NET Web Forms application (not MVC). I find it easier than adding asp validators everywhere and setting the control to validate field on all of them.

I am just having some issues both when setting the class like this class="required email" which I think has something to do with having a form tag within the main form tag.

I also run into issues when calling the jquery validate using the names which become mangled in an asp control

// validate signup form on keyup and submit
$("#signupForm").validate({
    rules: { 
        username: {
            required: true,
            minlength: 2
        }, },
    messages: { 
        username: {
            required: "Please enter a username",
            minlength: "username at least 2 characters"
        }, 
    }.

.......

        <p>
            <label for="username">
                Username</label>
            <input id="username" name="username" />
        </p>

because this

<asp:TextBox ID="tbUsername"  runat="server"></asp:TextBox>

renders as

<input name="ctl00$ContentPlaceHolder1$tbUsername" type="text" id="ctl00_ContentPlaceHolder1_tbUsername" />

and mangles the name. I can get the ClientID using <%=tbUsername.ClientID %>but that doesnt work with ClientName

Has anyone had any success using the jquery validator plugin with asp.net? If so what about using multiple forms much like using seprate validation groups? thanks


Source: (StackOverflow)

Advertisements

Filter Extensions in HTML form upload [duplicate]

This question already has an answer here:

I have a simple HTML upload form, and I want to specify a default extension ("*.drp" for example). I've read that the way to do this is through the ACCEPT attribute of the input tag, but I don't know how exactly.

<form enctype="multipart/form-data" action="uploader.php" method="POST">
Upload DRP File:
<input name="Upload Saved Replay" type="file" accept="*.drp"/><br />
<input type="submit" value="Upload File" />
</form>

Edit I know validation is possible using javascript, but I would like the user to only see ".drp" files in his popup dialog. Also, I don't care much about server-side validation in this application.


Source: (StackOverflow)

Why does ASP.Net RadioButton and CheckBox render inside a Span?

I would expect this:

<asp:CheckBox    ID="CheckBox1"    runat="server" CssClass="myClass" />
<asp:RadioButton ID="RadioButton1" runat="server" CssClass="myClass" />
<asp:TextBox     ID="TextBox1"     runat="server" CssClass="myClass" />

...to render like this (with some attributes removed for simplicity):

<input id="CheckBox1"    type="checkbox" class="myClass" />
<input id="RadioButton1" type="radio"    class="myClass" />
<input id="TextBox1"     type="text"     class="myClass" />

...when in fact, the RadioButton and CheckBox get wrapped with a span tag and the CSS class gets applied there.

<span class="myClass"><input id="CheckBox1"    type="checkbox" /></span> 
<span class="myClass"><input id="RadioButton1" type="radio"    /></span> 
<input type="text" id="TextBox1" class="myClass" />

Is there a reason for this and is there a way to avoid it? It makes jQuery selectors ugly since you can't catch all of them with:

$("input.myClass")

Granted it is just going to:

$("input.myClass, span.myClass input")

...but that is ugly. I could write my own selector, but again not as elegant as it should be.


Source: (StackOverflow)

"The given path's format is not supported."

I gave following line of code on web service:

string str_uploadpath = Server.MapPath("/UploadBucket/Raw/");
FileStream objfilestream = new FileStream(str_uploadpath +
                fileName, FileMode.Create, FileAccess.ReadWrite);

Can some one help me resolve issue with this error message from line 2 of the code.

The given path's format is not supported.

Permission on the folder set to full access to everyone and it is actual path to the folder. break point gave me value of str_uploadpath as C:\\webprojects\\webservices\\UploadBucket\\Raw\\.

What is wrong with this string I can not see.


Source: (StackOverflow)

Radio buttons on Rails

Similar to this question: http://stackoverflow.com/questions/621340/checkboxes-on-rails

What's the correct way of making radio buttons that are related to a certain question in Ruby on Rails? At the moment I have:

<div class="form_row">
    <label for="theme">Theme:</label>
    <br><%= radio_button_tag 'theme', 'plain', true %> Plain
    <br><%= radio_button_tag 'theme', 'desert' %> Desert
    <br><%= radio_button_tag 'theme', 'green' %> Green
    <br><%= radio_button_tag 'theme', 'corporate' %> Corporate
    <br><%= radio_button_tag 'theme', 'funky' %> Funky
</div>

I also want to be able to automatically check the previously selected items (if this form was re-loaded). How would I load the params into the default value of these?


Source: (StackOverflow)

Disable form submission via Enter key on only _some fields

I want to retain the conventional 'form submits when i press Enter' behavior because users are familiar with. But by reflex, they often hit enter when they finish with a text input box - but before they are actually done with the complete form.

I'd like to hijack the Enter key only when then focus is on a certain class of input.

Looking Related Questions this looks like what I'm looking for:

if (document.addEventListener) {
    document.getElementById('strip').addEventListener('keypress',HandleKeyPress,false);
} else {
    document.getElementById('strip').onkeypress = HandleKeyPress;
}

but the if (document.addEventListener) { part is unfamiliar to me.


Source: (StackOverflow)

What's your choice for your next ASP.NET project: Web Forms or MVC? [closed]

Let's say that you will start a new ASP.NET web site/application tomorrow. Would you chose Web Forms or MVC, and why?


Source: (StackOverflow)

Asp.Net Web Forms and Asp.Net Web Pages

What is the difference between Asp.Net Web Forms and Asp.Net Web Pages?

Here it says that Web Pages and Web Forms different approaches.


Source: (StackOverflow)

Using jQuery for AJAX with ASP.NET Webforms

Anyone know of a link to a good article/tutorial for getting started using jQuery for AJAX calls rather than ASP.NET AJAX? I'm trying to avoid using UpdatePanels entirely in this app, which I haven't been able to accomplish in the past.


Source: (StackOverflow)

How to include a partial view inside a webform

Some site I'm programming is using both ASP.NET MVC and WebForms.

I have a partial view and I want to include this inside a webform. The partial view has some code that has to be processed in the server, so using Response.WriteFile don't work. It should work with javascript disabled.

How can I do this?


Source: (StackOverflow)

Best Practices for Passing Data Between Pages

The Problem

In the stack that we re-use between projects, we are putting a little bit too much data in the session for passing data between pages. This was good in theory because it prevents tampering, replay attacks, and so on, but it creates as many problems as it solves.

Session loss itself is an issue, although it's mostly handled by implementing Session State Server (or by using SQL Server). More importantly, it's tricky to make the back button work correctly, and it's also extra work to create a situation where a user can, say, open the same screen in three tabs to work on different records.

And that's just the tip of the iceberg.

There are workarounds for most of these issues, but as I grind away, all this friction gives me the feeling that passing data between pages using session is the wrong direction.

What I really want to do here is come up with a best practice that my shop can use all the time for passing data between pages, and then, for new apps, replace key parts of our stack that currently rely on Session.

It would also be nice if the final solution did not result in mountains of boilerplate plumbing code.

Proposed Solutions

Session

As mentioned above, leaning heavily on Session seems like a good idea, but it breaks the back button and causes some other problems.

There may be ways to get around all the problems, but it seems like a lot of extra work.

One thing that's very nice about using session is the fact that tampering is just not an issue. Compared to passing everything via the unencrypted QueryString, you end up writing much less guard code.

Cross-Page Posting

In truth I've barely considered this option. I have a problem with how tightly coupled it makes the pages -- if I start doing PreviousPage.FindControl("SomeTextBox"), that seems like a maintenance problem if I ever want to get to this page from another page that maybe does not have a control called SomeTextBox.

It seems limited in other ways as well. Maybe I want to get to the page via a link, for instance.

QueryString

I'm currently leaning towards this strategy, like in the olden days. But I probably want my QueryString to be encrypted to make it harder to tamper with, and I would like to handle the problem of replay attacks as well.

On 4 guys from Rolla, there's an article about this.

However, it should be possible to create an HttpModule that takes care of all this and removes all the encryption sausage-making from the page. Sure enough, Mad Kristenson has an article where he released one. However, the comments make it sound like it has problems with extremely common scenarios.

Other Options

Of course this is not an exaustive look at the options, but rather the main options I'm considering. This link contains a more complete list. The ones I didn't mention such as Cookies and the Cache not appropriate for the purpose of passing data between pages.

In Closing...

So, how are you handling the problem of passing data between pages? What hidden gotchas did you have to work around, and are there any pre-existing tools around this that solve them all flawlessly? Do you feel like you've got a solution that you're completely happy with?

Thanks in advance!

Update: Just in case I'm not being clear enough, by 'passing data between pages' I'm talking about, for instance, passing a CustomerID key from a CustomerSearch.aspx page to Customers.aspx, where the Customer will be opened and editing can occur.


Source: (StackOverflow)

Dropdownlist control with s for asp.net (webforms)?

Can anyone recommend a dropdownlist control for asp.net (3.5) that can render option groups? Thanks


Source: (StackOverflow)

How can I get the button that caused the submit from the form submit event?

I'm trying to find the value of the submit button that triggered the form to submit

$("form").submit(function() {

});

I could possibly fire a $("input[type=submit]").click() event for each button and set some variable, but that seems less elegant than some how pulling the button off of the the form on submit.


Source: (StackOverflow)

"Could not load type [Namespace].Global" causing me grief

In my .Net 2.0 Asp.net WebForms app, I have my Global.asax containing the following code:

<%@ Application CodeBehind="Global.asax.cs" Inherits="MyNamespace.Global" Language="C#" %>

However when I build I get an error stating-

Could not load type 'MyNamespace.Global'.

This seems to be because the MyNamespace namespace (defined in the code behind file Global.asax.cs) is not seen by the compiler in the Global.asax file (does not show in R# intellisence..). This turned out to be a very hard nut to crack... any help will be appreciated!

Note: The Global.asax and the Global.asax.cs are located in the same folder.

Note2: When compiling from the vs prompt with csc it compiles o.k.


Source: (StackOverflow)