ASCX - Function Not Being Called

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • George Durzi

    ASCX - Function Not Being Called

    I created a simple user control which contains a hyperlink to link the user
    to a topic in a compiled help file. I named all my help topics to have the
    same name as the aspx they are for.

    So in the user control help.ascx's html, I have this:
    <a href='<%# GenerateHelpLin k()%>' class="mischref content2" id="hrfHelp"
    runat="server" target="_blank" >Help</a>

    In the codebehind help.ascx.cs, I have this:
    #region GenerateHelpLin k
    protected void GenerateHelpLin k()
    {
    StringBuilder sb = new StringBuilder() ;
    sb.Append("ms-its:");

    sb.Append(Confi gurationSetting s.AppSettings["ApplicationURL "].ToString());
    sb.Append(Confi gurationSetting s.AppSettings["HelpFile"].ToString());
    string[] arScript =
    Request.ServerV ariables["SCRIPT_NAM E"].ToString().Spl it("/".ToCharArray() );
    string sScript = arScript[arScript.GetUpp erBound(0)].ToString();
    sb.Append(sScri pt.Substring(0, sScript.LastInd exOf(".")));
    sb.Append(".htm ");

    // you can ignore these details - this function simply returns a help
    URL

    return sb.ToString();
    }
    #endregion

    So if I'm at cs_completed.as px, the above function will return:
    ms-its:http://gdurzi/framework/help/MyFelpF..._completed.htm

    In cs_completed.as px, I do this:
    <%@ Register TagPrefix="fram ework" TagName="help" Src="ascx\help. ascx" %>
    and
    <framework:he lp id="_help" runat="server"> </framework:help>

    The text Help (what's inside the <a></a>) is displayed, but the hyperlink
    doesn't work. Upon debugging, I realized the function GenerateHelpLin k is
    never being called ...

    I want to accomplish this without having to write code into every page to
    call this function. I just wanted to plop the user control in there and let
    it do it's work.. Any idea?


  • Marina

    #2
    Re: ASCX - Function Not Being Called

    Instead of using an <a> tag, I would use a Hyperlink control.

    Then in page_load do something like:

    Hyperlink1.Navi gationURL = GenerateHelp();

    "George Durzi" <gdurzi@nospam_ hotmail.com> wrote in message
    news:%23jr71aAP DHA.1608@TK2MSF TNGP11.phx.gbl. ..[color=blue]
    > I created a simple user control which contains a hyperlink to link the[/color]
    user[color=blue]
    > to a topic in a compiled help file. I named all my help topics to have the
    > same name as the aspx they are for.
    >
    > So in the user control help.ascx's html, I have this:
    > <a href='<%# GenerateHelpLin k()%>' class="mischref content2" id="hrfHelp"
    > runat="server" target="_blank" >Help</a>
    >
    > In the codebehind help.ascx.cs, I have this:
    > #region GenerateHelpLin k
    > protected void GenerateHelpLin k()
    > {
    > StringBuilder sb = new StringBuilder() ;
    > sb.Append("ms-its:");
    >
    > sb.Append(Confi gurationSetting s.AppSettings["ApplicationURL "].ToString());
    > sb.Append(Confi gurationSetting s.AppSettings["HelpFile"].ToString());
    > string[] arScript =
    >[/color]
    Request.ServerV ariables["SCRIPT_NAM E"].ToString().Spl it("/".ToCharArray() );[color=blue]
    > string sScript = arScript[arScript.GetUpp erBound(0)].ToString();
    > sb.Append(sScri pt.Substring(0, sScript.LastInd exOf(".")));
    > sb.Append(".htm ");
    >
    > // you can ignore these details - this function simply returns a help
    > URL
    >
    > return sb.ToString();
    > }
    > #endregion
    >
    > So if I'm at cs_completed.as px, the above function will return:
    > ms-its:http://gdurzi/framework/help/MyFelpF..._completed.htm
    >
    > In cs_completed.as px, I do this:
    > <%@ Register TagPrefix="fram ework" TagName="help" Src="ascx\help. ascx" %>
    > and
    > <framework:he lp id="_help" runat="server"> </framework:help>
    >
    > The text Help (what's inside the <a></a>) is displayed, but the hyperlink
    > doesn't work. Upon debugging, I realized the function GenerateHelpLin k is
    > never being called ...
    >
    > I want to accomplish this without having to write code into every page to
    > call this function. I just wanted to plop the user control in there and[/color]
    let[color=blue]
    > it do it's work.. Any idea?
    >
    >[/color]


    Comment

    • George Durzi

      #3
      Re: ASCX - Function Not Being Called

      I would have to put code in the Page_Load of every ASPX page in my
      application. I am trying to avoid that.

      Any idea why the GenerateHelpLin k() function doesn't get called though? It
      doesn't make a diff if I use an <a> or a <asp:hyperlin k>

      "Marina" <zlatkinam@nosp am.hotmail.com> wrote in message
      news:exh7VrAPDH A.452@TK2MSFTNG P11.phx.gbl...[color=blue]
      > Instead of using an <a> tag, I would use a Hyperlink control.
      >
      > Then in page_load do something like:
      >
      > Hyperlink1.Navi gationURL = GenerateHelp();
      >
      > "George Durzi" <gdurzi@nospam_ hotmail.com> wrote in message
      > news:%23jr71aAP DHA.1608@TK2MSF TNGP11.phx.gbl. ..[color=green]
      > > I created a simple user control which contains a hyperlink to link the[/color]
      > user[color=green]
      > > to a topic in a compiled help file. I named all my help topics to have[/color][/color]
      the[color=blue][color=green]
      > > same name as the aspx they are for.
      > >
      > > So in the user control help.ascx's html, I have this:
      > > <a href='<%# GenerateHelpLin k()%>' class="mischref content2" id="hrfHelp"
      > > runat="server" target="_blank" >Help</a>
      > >
      > > In the codebehind help.ascx.cs, I have this:
      > > #region GenerateHelpLin k
      > > protected void GenerateHelpLin k()
      > > {
      > > StringBuilder sb = new StringBuilder() ;
      > > sb.Append("ms-its:");
      > >
      > >[/color][/color]
      sb.Append(Confi gurationSetting s.AppSettings["ApplicationURL "].ToString());[color=blue][color=green]
      > > sb.Append(Confi gurationSetting s.AppSettings["HelpFile"].ToString());
      > > string[] arScript =
      > >[/color]
      >[/color]
      Request.ServerV ariables["SCRIPT_NAM E"].ToString().Spl it("/".ToCharArray() );[color=blue][color=green]
      > > string sScript = arScript[arScript.GetUpp erBound(0)].ToString();
      > > sb.Append(sScri pt.Substring(0, sScript.LastInd exOf(".")));
      > > sb.Append(".htm ");
      > >
      > > // you can ignore these details - this function simply returns a[/color][/color]
      help[color=blue][color=green]
      > > URL
      > >
      > > return sb.ToString();
      > > }
      > > #endregion
      > >
      > > So if I'm at cs_completed.as px, the above function will return:
      > > ms-its:http://gdurzi/framework/help/MyFelpF..._completed.htm
      > >
      > > In cs_completed.as px, I do this:
      > > <%@ Register TagPrefix="fram ework" TagName="help" Src="ascx\help. ascx"[/color][/color]
      %>[color=blue][color=green]
      > > and
      > > <framework:he lp id="_help" runat="server"> </framework:help>
      > >
      > > The text Help (what's inside the <a></a>) is displayed, but the[/color][/color]
      hyperlink[color=blue][color=green]
      > > doesn't work. Upon debugging, I realized the function GenerateHelpLin k[/color][/color]
      is[color=blue][color=green]
      > > never being called ...
      > >
      > > I want to accomplish this without having to write code into every page[/color][/color]
      to[color=blue][color=green]
      > > call this function. I just wanted to plop the user control in there and[/color]
      > let[color=green]
      > > it do it's work.. Any idea?
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Marina

        #4
        Re: ASCX - Function Not Being Called

        No, you would need to put this code into Page_Load of the user control, not
        the page.

        I don't think the <%# %> tags work that way if it's not part of databinding
        code. If you did something like <% Response.Write( GenerateHelp()) ; %> that
        would probably do it.

        But this is doing it the old fashioned ASP way. I think putting all this
        type of code into Page_Load is a much neater way to do it. It follows the
        idea of separating UI and code that ASP.NET introduces.

        "George Durzi" <gdurzi@nospam_ hotmail.com> wrote in message
        news:eeQICvAPDH A.1584@TK2MSFTN GP11.phx.gbl...[color=blue]
        > I would have to put code in the Page_Load of every ASPX page in my
        > application. I am trying to avoid that.
        >
        > Any idea why the GenerateHelpLin k() function doesn't get called though? It
        > doesn't make a diff if I use an <a> or a <asp:hyperlin k>
        >
        > "Marina" <zlatkinam@nosp am.hotmail.com> wrote in message
        > news:exh7VrAPDH A.452@TK2MSFTNG P11.phx.gbl...[color=green]
        > > Instead of using an <a> tag, I would use a Hyperlink control.
        > >
        > > Then in page_load do something like:
        > >
        > > Hyperlink1.Navi gationURL = GenerateHelp();
        > >
        > > "George Durzi" <gdurzi@nospam_ hotmail.com> wrote in message
        > > news:%23jr71aAP DHA.1608@TK2MSF TNGP11.phx.gbl. ..[color=darkred]
        > > > I created a simple user control which contains a hyperlink to link the[/color]
        > > user[color=darkred]
        > > > to a topic in a compiled help file. I named all my help topics to have[/color][/color]
        > the[color=green][color=darkred]
        > > > same name as the aspx they are for.
        > > >
        > > > So in the user control help.ascx's html, I have this:
        > > > <a href='<%# GenerateHelpLin k()%>' class="mischref content2"[/color][/color][/color]
        id="hrfHelp"[color=blue][color=green][color=darkred]
        > > > runat="server" target="_blank" >Help</a>
        > > >
        > > > In the codebehind help.ascx.cs, I have this:
        > > > #region GenerateHelpLin k
        > > > protected void GenerateHelpLin k()
        > > > {
        > > > StringBuilder sb = new StringBuilder() ;
        > > > sb.Append("ms-its:");
        > > >
        > > >[/color][/color]
        > sb.Append(Confi gurationSetting s.AppSettings["ApplicationURL "].ToString());[color=green][color=darkred]
        > > >[/color][/color][/color]
        sb.Append(Confi gurationSetting s.AppSettings["HelpFile"].ToString());[color=blue][color=green][color=darkred]
        > > > string[] arScript =
        > > >[/color]
        > >[/color]
        >[/color]
        Request.ServerV ariables["SCRIPT_NAM E"].ToString().Spl it("/".ToCharArray() );[color=blue][color=green][color=darkred]
        > > > string sScript = arScript[arScript.GetUpp erBound(0)].ToString();
        > > > sb.Append(sScri pt.Substring(0, sScript.LastInd exOf(".")));
        > > > sb.Append(".htm ");
        > > >
        > > > // you can ignore these details - this function simply returns a[/color][/color]
        > help[color=green][color=darkred]
        > > > URL
        > > >
        > > > return sb.ToString();
        > > > }
        > > > #endregion
        > > >
        > > > So if I'm at cs_completed.as px, the above function will return:
        > > > ms-its:http://gdurzi/framework/help/MyFelpF..._completed.htm
        > > >
        > > > In cs_completed.as px, I do this:
        > > > <%@ Register TagPrefix="fram ework" TagName="help" Src="ascx\help. ascx"[/color][/color]
        > %>[color=green][color=darkred]
        > > > and
        > > > <framework:he lp id="_help" runat="server"> </framework:help>
        > > >
        > > > The text Help (what's inside the <a></a>) is displayed, but the[/color][/color]
        > hyperlink[color=green][color=darkred]
        > > > doesn't work. Upon debugging, I realized the function GenerateHelpLin k[/color][/color]
        > is[color=green][color=darkred]
        > > > never being called ...
        > > >
        > > > I want to accomplish this without having to write code into every page[/color][/color]
        > to[color=green][color=darkred]
        > > > call this function. I just wanted to plop the user control in there[/color][/color][/color]
        and[color=blue][color=green]
        > > let[color=darkred]
        > > > it do it's work.. Any idea?
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • George Durzi

          #5
          Re: ASCX - Function Not Being Called

          Thank you, that worked. For some reason I thought the Page_Load event of the
          user control wouldn't fire.

          "Marina" <zlatkinam@nosp am.hotmail.com> wrote in message
          news:%2365EY6AP DHA.2316@TK2MSF TNGP11.phx.gbl. ..[color=blue]
          > No, you would need to put this code into Page_Load of the user control,[/color]
          not[color=blue]
          > the page.
          >
          > I don't think the <%# %> tags work that way if it's not part of[/color]
          databinding[color=blue]
          > code. If you did something like <% Response.Write( GenerateHelp()) ; %> that
          > would probably do it.
          >
          > But this is doing it the old fashioned ASP way. I think putting all this
          > type of code into Page_Load is a much neater way to do it. It follows the
          > idea of separating UI and code that ASP.NET introduces.
          >
          > "George Durzi" <gdurzi@nospam_ hotmail.com> wrote in message
          > news:eeQICvAPDH A.1584@TK2MSFTN GP11.phx.gbl...[color=green]
          > > I would have to put code in the Page_Load of every ASPX page in my
          > > application. I am trying to avoid that.
          > >
          > > Any idea why the GenerateHelpLin k() function doesn't get called though?[/color][/color]
          It[color=blue][color=green]
          > > doesn't make a diff if I use an <a> or a <asp:hyperlin k>
          > >
          > > "Marina" <zlatkinam@nosp am.hotmail.com> wrote in message
          > > news:exh7VrAPDH A.452@TK2MSFTNG P11.phx.gbl...[color=darkred]
          > > > Instead of using an <a> tag, I would use a Hyperlink control.
          > > >
          > > > Then in page_load do something like:
          > > >
          > > > Hyperlink1.Navi gationURL = GenerateHelp();
          > > >
          > > > "George Durzi" <gdurzi@nospam_ hotmail.com> wrote in message
          > > > news:%23jr71aAP DHA.1608@TK2MSF TNGP11.phx.gbl. ..
          > > > > I created a simple user control which contains a hyperlink to link[/color][/color][/color]
          the[color=blue][color=green][color=darkred]
          > > > user
          > > > > to a topic in a compiled help file. I named all my help topics to[/color][/color][/color]
          have[color=blue][color=green]
          > > the[color=darkred]
          > > > > same name as the aspx they are for.
          > > > >
          > > > > So in the user control help.ascx's html, I have this:
          > > > > <a href='<%# GenerateHelpLin k()%>' class="mischref content2"[/color][/color]
          > id="hrfHelp"[color=green][color=darkred]
          > > > > runat="server" target="_blank" >Help</a>
          > > > >
          > > > > In the codebehind help.ascx.cs, I have this:
          > > > > #region GenerateHelpLin k
          > > > > protected void GenerateHelpLin k()
          > > > > {
          > > > > StringBuilder sb = new StringBuilder() ;
          > > > > sb.Append("ms-its:");
          > > > >
          > > > >[/color]
          > >[/color][/color]
          sb.Append(Confi gurationSetting s.AppSettings["ApplicationURL "].ToString());[color=blue][color=green][color=darkred]
          > > > >[/color][/color]
          > sb.Append(Confi gurationSetting s.AppSettings["HelpFile"].ToString());[color=green][color=darkred]
          > > > > string[] arScript =
          > > > >
          > > >[/color]
          > >[/color]
          >[/color]
          Request.ServerV ariables["SCRIPT_NAM E"].ToString().Spl it("/".ToCharArray() );[color=blue][color=green][color=darkred]
          > > > > string sScript = arScript[arScript.GetUpp erBound(0)].ToString();
          > > > > sb.Append(sScri pt.Substring(0, sScript.LastInd exOf(".")));
          > > > > sb.Append(".htm ");
          > > > >
          > > > > // you can ignore these details - this function simply returns a[/color]
          > > help[color=darkred]
          > > > > URL
          > > > >
          > > > > return sb.ToString();
          > > > > }
          > > > > #endregion
          > > > >
          > > > > So if I'm at cs_completed.as px, the above function will return:
          > > > >[/color][/color][/color]
          ms-its:http://gdurzi/framework/help/MyFelpF..._completed.htm[color=blue][color=green][color=darkred]
          > > > >
          > > > > In cs_completed.as px, I do this:
          > > > > <%@ Register TagPrefix="fram ework" TagName="help"[/color][/color][/color]
          Src="ascx\help. ascx"[color=blue][color=green]
          > > %>[color=darkred]
          > > > > and
          > > > > <framework:he lp id="_help" runat="server"> </framework:help>
          > > > >
          > > > > The text Help (what's inside the <a></a>) is displayed, but the[/color]
          > > hyperlink[color=darkred]
          > > > > doesn't work. Upon debugging, I realized the function[/color][/color][/color]
          GenerateHelpLin k[color=blue][color=green]
          > > is[color=darkred]
          > > > > never being called ...
          > > > >
          > > > > I want to accomplish this without having to write code into every[/color][/color][/color]
          page[color=blue][color=green]
          > > to[color=darkred]
          > > > > call this function. I just wanted to plop the user control in there[/color][/color]
          > and[color=green][color=darkred]
          > > > let
          > > > > it do it's work.. Any idea?
          > > > >
          > > > >
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          Working...