[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Converting from one page aspx to 2 pages using Code behinds.....

Posted on 2005-05-11
12
Medium Priority
?
219 Views
Last Modified: 2010-04-07
Dear all,

I want to seperate out the vb.net code in a current single page aspx. Is there an easy way to do this, or is it a matter of cutting and pasting code into the CBH file.

a) What is the easiest way

b) Some of the code is conditionally presents html controls, and uses variables which would not be visible if put in a CBH file.

e.g

<td colspan="2">
      <%  If Page.IsPostBack AndAlso Not DS Is Nothing %>
      <b>Result:</b><br>
      <textarea cols="80" rows="25">
      <%
      If GetSchemaChecked
                      DS.WriteXmlSchema(Response.Output)
      Else If GetDataChecked
            DS.WriteXml(Response.Output, XmlWriteMode.IgnoreSchema)
      Else
            DS.WriteXml(Response.Output, XmlWriteMode.WriteSchema)
      End If
      %>
      </textarea>
      <%  End If  %>
</td>

In this case 'DS' is not available. How does one deal with this situation? do you rewrite the conditional presentational logic to be in a CBH, say by setting .visible properties on controls, or do you just make the variable/member public.

Thanks,

Sam
0
Comment
Question by:SamJolly
  • 6
  • 5
12 Comments
 

Author Comment

by:SamJolly
ID: 13982436
Also how does the "OnSelectedIndexChanged" attribute appear in the following. Do you have to type it in explicitly, or does it appear due to some action in the IDE. This is another part of the above code.

<asp:DropDownList runat="server" id="table" OnSelectedIndexChanged="table_SelectedIndexChanged" AutoPostBack="True" />

Full codebase is at:

http://www.dotnetjunkies.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/data/xmlgen.src

thanks,

Sam
0
 
LVL 9

Assisted Solution

by:riyasjef
riyasjef earned 400 total points
ID: 13983872
I would prefer controls to be generated dynamically..

In the aspx file (uses a panel control)
----------------
<td colspan="2">
      <asp:Panel id="Panel1" runat="server"><asp:Panel>    
</td>

In the page load (Code behined)
----------------------------

If Page.IsPostBack AndAlso Not DS Is Nothing
   
    Dim Label1  As Label
    Dim TextBox1 As TextBox
    Label1.Text = "Result"
    Panel.Controls.Add(Label1)
    TextBox1.TextMode = "MultiLine"
    ...........
    Panel.Controls.Add(TextBox1)    
   
End If


>> <asp:DropDownList runat="server" id="table" OnSelectedIndexChanged="table_SelectedIndexChanged" AutoPostBack="True" />
Its inline ..so u have to type the code..

If u are using VS.net just click the control, VS will generate code for you..

In C# like this

private void InitializeComponent()
{
 ...........
 this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
}


private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{

}

and in VB.net, I guess

DropDownList1.addhandler addressOf DropDownList1_SelectedIndexChanged
0
 
LVL 23

Accepted Solution

by:
b1xml2 earned 1600 total points
ID: 13985134
<asp:PlaceHolder Id="TextAreaHolder" Runat="Server" Visible="False">
<tr>
      <td colspan="2">
        <b>Result:</b><br>
        <asp:TextBox Id="txtSchema" Runat="server" TextMode="MultiLine" />
      </td>
</tr>
</asp:PlaceHolder>
<asp:PlaceHolder Id="GridHolder" Runat="server" Visible="False">
<tr>
      <td colspan="2">
      
      <b>Data:</b><br>
      <asp:DataGrid id="MyDataGrid"
            BackColor="#EDBE7B"
            BorderColor="black"
            ShowFooter="false"
            CellPadding=3
            CellSpacing="0"
            Font-Name="Verdana"
            Font-Size="8pt"
            HeaderStyle-BackColor="#DC6035"
            EnableViewState="false"
            runat="server"
      />
      
      </td>
<tr>
</asp:PlaceHolder>

use placeholders as they do not emit any HTML tag.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:SamJolly
ID: 13985218
Thanks, interesting.

What about the business of creating a Code behind page from a single aspx page which contains html and vb.net code. Is there an automatic way in VS.NET, or is it a matter of hand seperation.

Sam
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13985253
<asp:TextBox Id="txtSchema" Runat="server" TextMode="MultiLine" Rows="25" Columns="80"/>


Imports System.IO
Imports System.Xml

Private Sub Page_Load(ByVal sender As Object,ByVal e As EventArgs) Handles MyBase.Load
      'existing code
      
      If IsPostBack AndAlso Not DS Is Nothing Then
            GridHolder.Visible = True
            TextAreaHolder.Visible = True
            
            Dim writer As New StringWriter
            If GetSchemaChecked Then
                  DS.WriteXmlSchema(writer)
            ElseIf GetDataChecked Then
                  DS.WriteXml(writer,XmlWriteMode.IgnoreSchema)
            Else
                  DS.WriteXml(writer,XmlWriteMode.WriteSchema)
            End
            txtSchema.Text = writer.ToString
            writer.Close()
      Else
            GridHolder.Visible = False
            TextAreaHolder.Visible = False
      End If
End Sub
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13985267
I must say that although this is a dotnetjunkies, the code if any is anything but one from a junkie. I am appalled by the inline <% if %> ... <%end if %> crap. The idea may be good on the page but the code is crap.
0
 

Author Comment

by:SamJolly
ID: 13986124
b1xml2,

hmmmm... yes I can agree with you on the inline code, abit like bad asp smuggling itself into .net where code should be seperated into CBHs.

Then my suspicions that converting this non CBH code to CBH is a manual process, yes.... no...... ???

thanks,

Sam
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13986151
The VB code is not even correct. I suspect the coder is a C# programmer with a poor grasp of ASP.NET.

It is a manual process because the code is bad, bad and very bad.
0
 

Author Comment

by:SamJolly
ID: 13986395
How bad is it......... :)

Out of interest, what route have you found to be the best at developing your .NET, apart from cutting code ie training courses?, recommended books, recommended web resources, other...????

Thanks,

Sam

0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13986539
I have never attended any training course for ASP.NET and C#. I learnt on my own in 2001 with Beta 1/2 and then the RTMs.

I picked up VB.NET within 1 month last year. There are quirks with VB.NET (well at least from my perspective with the silly keyword "OverLoads") It is simple once you know the framework. I generally noticed that C# programmers can write in C# and VB.NET. But not as common (I would hesitate however to use the term rarely) the other way round (VB.NET to C#)

The best way in developing .NET is developing software with modelling, reading up lots of documentation on the net, listening and participating in forums such as this.

Im my opinion, the best way to improve yourself in the shortest period of time is to offer your help to others here. Be prepared not to get any points initially. but when you start trying to solve harder problems, your typing gets faster and you start to think ahead of your coding.

Half the solutions I write is from notepad/SciTe without opening up VS.NET.
0
 

Author Comment

by:SamJolly
ID: 13986586
Thanks all,

Sam
0
 

Author Comment

by:SamJolly
ID: 13991573
Sorry my points did not get added, try again...

Sam
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month20 days, 6 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question