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

  • SEARCH
  • Home
  • 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 6997147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:14:49+00:00 2026-05-27T20:14:49+00:00

I’m reading data from database and showing it in a page for editing: <h2>Create

  • 0

I’m reading data from database and showing it in a page for editing:

    <h2>Create new topic: 
    <asp:Label ID="_lblTopicName" runat="server" Text=""></asp:Label></h2>
      <p>
      Edit Level:
      <br/>
      <asp:DropDownList ID="_dtlEditRole" runat="server"></asp:DropDownList>
      <br/>
      View Level:
      <br/>
      <asp:DropDownList ID="_dtlViewRole" runat="server"></asp:DropDownList>
      <br/>
      <asp:TextBox ID="_tbxTopicText" TextMode="MultiLine" runat="server" Height="204px" 
        Width="885px"></asp:TextBox>
    </p>
  <asp:Button ID="_btnSaveTopic" runat="server" Text="Save" onclick="_btnSaveTopic_Click" />

I fill the fields in Page_PreRender() like so:

    private string _topicString;
    private Topic _topic = null;
    private Topics_GetTopicByTopicResult _findTopicResults = null;

    protected void Page_PreRender(object sender, EventArgs e)
    {
        // Load the User Roles into checkboxes.
        _dtlEditRole.DataSource = Roles.GetAllRoles();
        _dtlEditRole.DataBind();
        _dtlViewRole.DataSource = Roles.GetAllRoles();
        _dtlViewRole.DataBind();

        _topicString = Request.QueryString["Topic"];

        if (String.IsNullOrEmpty(_topicString))
        {
            Response.Redirect("~/Default.aspx");
        }
        else
        {
            _topic = new Topic();
            _findTopicResults = _topic.FindTopic(_topicString);

            if (_topic != null)
            {
                // Check if the user has permission to access
                if (RoleHelper.IsEditAllowed(_findTopicResults.ViewRoleName))
                {
                    _lblTopicName.Text = _findTopicResults.Topic;
                    _tbxTopicText.Text = _findTopicResults.Text;

                    _dtlEditRole.SelectedValue = _findTopicResults.EditRoleName;
                    _dtlViewRole.SelectedValue = _findTopicResults.ViewRoleName;
                }
                else
                {
                    Response.Redirect("~/Error.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.RawUrl));
                }
            }
            else
            {
                Response.Redirect("~/CreateTopic.aspx?Topic=" + _topicString);
            }
        }
    }

But now when i click _btnSaveTopic button the fields:

    private string _topicString;
    private Topic _topic = null;
    private Topics_GetTopicByTopicResult _findTopicResults = null;

They are all NULL and im not able to update aything.

Here’s my button click event:

    protected void _btnSaveTopic_Click(object sender, EventArgs e)
    {
            _topic.UpdateTopic(_findTopicResults.ID, _findTopicResults.Topic, _tbxTopicText.Text,
                               _dtlViewRole.SelectedItem.Text, _dtlEditRole.SelectedItem.Text);
            Response.Redirect("~/ViewPage.aspx?Topic=" + _topicString);
    }

What would be the right way doing this?

  • 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-27T20:14:50+00:00Added an answer on May 27, 2026 at 8:14 pm

    ASP.NET Page Life Cycle states that Page_Init should be used to ‘initialize control properties’ which looks like what you are doing.

    Also, it’s usually good practice to breakup such large sections of code into smaller refactored methods. Try to keep the amount of code directly placed in event handlers to a minimum.

    You can start by right-clicking a section of highlighted code in visual studio -> refactor -> extract method

    Also, if you need more help understanding how to improve your code, you should ask a question pointing to this question on the code review site: here

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string

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.