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

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
SamJollyAsked:
Who is Participating?
 
b1xml2Connect With a Mentor Commented:
<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
 
SamJollyAuthor Commented:
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
 
riyasjefConnect With a Mentor Commented:
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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
SamJollyAuthor Commented:
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
 
b1xml2Commented:
<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
 
b1xml2Commented:
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
 
SamJollyAuthor Commented:
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
 
b1xml2Commented:
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
 
SamJollyAuthor Commented:
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
 
b1xml2Commented:
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
 
SamJollyAuthor Commented:
Thanks all,

Sam
0
 
SamJollyAuthor Commented:
Sorry my points did not get added, try again...

Sam
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.