locked
simple question regarding dlls and asp controls RRS feed

  • Question

  • User-334574633 posted

    Hello,

    I just cant seem to understand how this works, i want to dyn. print a control to the aspx page and then capture the result, but its not working, what am i missing? When i run this, it prints the form but i get nothing back when i press the submit.

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Web.SessionState;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;

    namespace MyControls
    {
    public class TestForm : WebControl
    { HttpRequest Request = HttpContext.Current.Request;
    HttpResponse Response = HttpContext.Current.Response;
    HttpServerUtility Server = HttpContext.Current.Server;
    HttpSessionState Session = HttpContext.Current.Session;

    private TextBox mName;
    private TextBox mCompanyName;
    private TextBox mInfo;

    protected override void OnLoad(EventArgs e)
    {
      if (this.Page.IsPostBack)
      {
        this.EnsureChildControls();
        Response.Write(
    HttpContext.Current.Server.HtmlEncode(this.mName.Text));
      }  
    }
    protected override void CreateChildControls()
    {
      this.Controls.Clear();
      PrintForm();
    }

    protected void PrintForm()
    {

      this.Controls.Add(new LiteralControl("Name: "));

      mName =
    new TextBox();
      mName.ID =
    "mName";
      this.Controls.Add(mName);   this.Controls.Add(new LiteralControl("<br />"));
     
    this.Controls.Add(new LiteralControl("Company: "));
     
      mCompanyName =
    new TextBox();
      mCompanyName.ID =
    "company";
      this.Controls.Add(mCompanyName);

      this.Controls.Add(new LiteralControl("<br />"));
      this.Controls.Add(new LiteralControl("Info: "));

      mInfo =
    new TextBox();
      mInfo.ID =
    "info";
      this.Controls.Add(mInfo);

      this
    .Controls.Add(new LiteralControl("<br />"));

      Button
    mBut = new Button();
      mBut.ID =
    "send";
      mBut.Text =
    "Postback";
      this.Controls.Add(mBut);
    }
    }
    }

    Tuesday, June 3, 2008 4:51 AM

Answers

  • User-1136466523 posted

    Hi,

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    From your description, it seems that you want to create a custom server control which handles Postback Data, right?

    <o:p> </o:p>

    If so, I suggest that you can try the following article which shows a tutorial on how to handle the postback data.

    <o:p> </o:p>

    http://www.dotnetjunkies.com/quickstart/aspplus/doc/webctrlauthoring.aspx#noncomposition

    <o:p> </o:p>

    Thanks.

    <o:p> </o:p>

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 5, 2008 12:04 AM

All replies

  • User-1107949042 posted

     hey my friend,

    I think you lost the part that you need write some code to onclick of button like this: in last line add this code:

    mBut.Click += new EventHandler(Button1_Click);
       


    also you need to add this code

       void Button1_Click(object sender, EventArgs e)
        {
           // do whatever you want to do !
        } 

     

    also I think you need to override render and in that just call the parent control Render

     

    Tuesday, June 3, 2008 5:02 AM
  • User-334574633 posted

    Hello,

    I tried it, but it still dosent do anything =/, any other ideas?

    Tuesday, June 3, 2008 5:08 AM
  • User-1107949042 posted

    what do you want to do exactly?

     

    Tuesday, June 3, 2008 8:08 AM
  • User-334574633 posted

    I just want to get the text that the user enters into the textboxes. In that code im just trying to see where i can catch and then display it to the user, but i cant seem to find out where to get the text that the user enters.

    Tuesday, June 3, 2008 10:06 AM
  • User-1136466523 posted

    Hi,

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    From your description, it seems that you want to create a custom server control which handles Postback Data, right?

    <o:p> </o:p>

    If so, I suggest that you can try the following article which shows a tutorial on how to handle the postback data.

    <o:p> </o:p>

    http://www.dotnetjunkies.com/quickstart/aspplus/doc/webctrlauthoring.aspx#noncomposition

    <o:p> </o:p>

    Thanks.

    <o:p> </o:p>

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 5, 2008 12:04 AM