Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3626596
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:46:56+00:00 2026-05-18T23:46:56+00:00

I am using ASP.NET MVC2 application in C#. I have two HTML forms on

  • 0

I am using ASP.NET MVC2 application in C#. I have two HTML forms on my content page.

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2><%: ViewData["Message"] %></h2>
<form id="form1">
<input id="text1" type="text" />
<input type="submit" value="submit" />
</form>

<form id="form2">
<input id="text2" type="text" />
<input type="submit" value="submit" />
</form>
</asp:Content>

What I want to do is to set the focus to Text Box after post back. After “form1” is submitted, “text1” should have focus and similarly after “form2” is submitted, “text2” should have the focus so that the user doesn’t have to use mouse to put the focus back in text box and continue typing.

The following code works fine for a single HTML form on the page.

<html>
<head>
<script>
void function setfocus() {
    document.getElementById("text1").focus();
}
</script>
</head>
<body onload="setfocus();">
<form method="post" action="">
<input type="submit" value="submit">
<input id="text1" type="text">
</form>
</body>
</html>

*The problem is I have two HTML forms on the page. Another issue is my web forms are on the content page of asp.net master page which reside inside the and only master form has tag which has “onload” property.

A friend of mine suggested me to use Ajax’s ScriptManager and UpdatePannel. However, the UpdatePannel doesn’t like HTML’s elements inside it. It seems only support asp.net control elements.

Very grateful for your guidance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T23:46:56+00:00Added an answer on May 18, 2026 at 11:46 pm

    Try this

    <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        <h2><%: ViewData["Message"] %></h2>
        <form id="form1">
            <input id="text1" type="text" />
            <input name="selectedTextBox" type="hidden" value="text1" />
            <input type="submit" value="submit" />
        </form>
    
        <form id="form2">
            <input id="text2" type="text" />
            <input name="selectedTextBox" type="hidden" value="text2" />
        <input type="submit" value="submit" />
    </form>
    <script>
        var textBoxID = "<%: Context.Request.Form["selectedTextBox"] %>";
        void function setfocus() {
            var textBox = document.getElementById(textBoxID);
            if(textBox) textBox.focus();
        }
    </script>
    

    Edit: Prefix Context to Request object

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have asp.net MVC2 application. I am using VS2008 and want to hook up
I've built an MVC 2 application (ASP.net 3.5) using Entity Framework, and am doing
I have Ninject working nicely in an ASP.NET MVC3 web application. I'd like to
I'm writing a hello world example using ASP.net MVC 2 framework with two text
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace MvcApplication3.Controllers { public
I need to write a little wizard application into which a user inputs some
This is vexing and searching around it is producing a lot of useless results
I am currently evaluating dotConnect for Oracle as an alternative to switching to SQL
I know this is a rather odd question, please don't flame me :) I
I am wanting to add a menu look and operation similar to this blog

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.