ASCX - Function Not Being Called

Discussion in 'ASP .Net' started by George Durzi, Jun 26, 2003.

  1. George Durzi

    George Durzi Guest

    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='<%# GenerateHelpLink()%>' class="mischrefcontent2" id="hrfHelp"
    runat="server" target="_blank">Help</a>

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

    sb.Append(ConfigurationSettings.AppSettings["ApplicationURL"].ToString());
    sb.Append(ConfigurationSettings.AppSettings["HelpFile"].ToString());
    string[] arScript =
    Request.ServerVariables["SCRIPT_NAME"].ToString().Split("/".ToCharArray());
    string sScript = arScript[arScript.GetUpperBound(0)].ToString();
    sb.Append(sScript.Substring(0, sScript.LastIndexOf(".")));
    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.aspx, the above function will return:
    ms-its:http://gdurzi/framework/help/MyFelpFile.chm::/cs_completed.htm

    In cs_completed.aspx, I do this:
    <%@ Register TagPrefix="framework" TagName="help" Src="ascx\help.ascx" %>
    and
    <framework:help 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 GenerateHelpLink 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?
    George Durzi, Jun 26, 2003
    #1
    1. Advertising

  2. George Durzi

    Marina Guest

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

    Then in page_load do something like:

    Hyperlink1.NavigationURL = GenerateHelp();

    "George Durzi" <gdurzi@nospam_hotmail.com> wrote in message
    news:%...
    > 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='<%# GenerateHelpLink()%>' class="mischrefcontent2" id="hrfHelp"
    > runat="server" target="_blank">Help</a>
    >
    > In the codebehind help.ascx.cs, I have this:
    > #region GenerateHelpLink
    > protected void GenerateHelpLink()
    > {
    > StringBuilder sb = new StringBuilder();
    > sb.Append("ms-its:");
    >
    > sb.Append(ConfigurationSettings.AppSettings["ApplicationURL"].ToString());
    > sb.Append(ConfigurationSettings.AppSettings["HelpFile"].ToString());
    > string[] arScript =
    >

    Request.ServerVariables["SCRIPT_NAME"].ToString().Split("/".ToCharArray());
    > string sScript = arScript[arScript.GetUpperBound(0)].ToString();
    > sb.Append(sScript.Substring(0, sScript.LastIndexOf(".")));
    > 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.aspx, the above function will return:
    > ms-its:http://gdurzi/framework/help/MyFelpFile.chm::/cs_completed.htm
    >
    > In cs_completed.aspx, I do this:
    > <%@ Register TagPrefix="framework" TagName="help" Src="ascx\help.ascx" %>
    > and
    > <framework:help 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 GenerateHelpLink 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, Jun 26, 2003
    #2
    1. Advertising

  3. George Durzi

    George Durzi Guest

    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 GenerateHelpLink() function doesn't get called though? It
    doesn't make a diff if I use an <a> or a <asp:hyperlink>

    "Marina" <> wrote in message
    news:...
    > Instead of using an <a> tag, I would use a Hyperlink control.
    >
    > Then in page_load do something like:
    >
    > Hyperlink1.NavigationURL = GenerateHelp();
    >
    > "George Durzi" <gdurzi@nospam_hotmail.com> wrote in message
    > news:%...
    > > 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='<%# GenerateHelpLink()%>' class="mischrefcontent2" id="hrfHelp"
    > > runat="server" target="_blank">Help</a>
    > >
    > > In the codebehind help.ascx.cs, I have this:
    > > #region GenerateHelpLink
    > > protected void GenerateHelpLink()
    > > {
    > > StringBuilder sb = new StringBuilder();
    > > sb.Append("ms-its:");
    > >
    > >

    sb.Append(ConfigurationSettings.AppSettings["ApplicationURL"].ToString());
    > > sb.Append(ConfigurationSettings.AppSettings["HelpFile"].ToString());
    > > string[] arScript =
    > >

    >

    Request.ServerVariables["SCRIPT_NAME"].ToString().Split("/".ToCharArray());
    > > string sScript = arScript[arScript.GetUpperBound(0)].ToString();
    > > sb.Append(sScript.Substring(0, sScript.LastIndexOf(".")));
    > > 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.aspx, the above function will return:
    > > ms-its:http://gdurzi/framework/help/MyFelpFile.chm::/cs_completed.htm
    > >
    > > In cs_completed.aspx, I do this:
    > > <%@ Register TagPrefix="framework" TagName="help" Src="ascx\help.ascx"

    %>
    > > and
    > > <framework:help 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 GenerateHelpLink

    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?
    > >
    > >

    >
    >
    George Durzi, Jun 26, 2003
    #3
  4. George Durzi

    Marina Guest

    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:...
    > 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 GenerateHelpLink() function doesn't get called though? It
    > doesn't make a diff if I use an <a> or a <asp:hyperlink>
    >
    > "Marina" <> wrote in message
    > news:...
    > > Instead of using an <a> tag, I would use a Hyperlink control.
    > >
    > > Then in page_load do something like:
    > >
    > > Hyperlink1.NavigationURL = GenerateHelp();
    > >
    > > "George Durzi" <gdurzi@nospam_hotmail.com> wrote in message
    > > news:%...
    > > > 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='<%# GenerateHelpLink()%>' class="mischrefcontent2"

    id="hrfHelp"
    > > > runat="server" target="_blank">Help</a>
    > > >
    > > > In the codebehind help.ascx.cs, I have this:
    > > > #region GenerateHelpLink
    > > > protected void GenerateHelpLink()
    > > > {
    > > > StringBuilder sb = new StringBuilder();
    > > > sb.Append("ms-its:");
    > > >
    > > >

    > sb.Append(ConfigurationSettings.AppSettings["ApplicationURL"].ToString());
    > > >

    sb.Append(ConfigurationSettings.AppSettings["HelpFile"].ToString());
    > > > string[] arScript =
    > > >

    > >

    >

    Request.ServerVariables["SCRIPT_NAME"].ToString().Split("/".ToCharArray());
    > > > string sScript = arScript[arScript.GetUpperBound(0)].ToString();
    > > > sb.Append(sScript.Substring(0, sScript.LastIndexOf(".")));
    > > > 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.aspx, the above function will return:
    > > > ms-its:http://gdurzi/framework/help/MyFelpFile.chm::/cs_completed.htm
    > > >
    > > > In cs_completed.aspx, I do this:
    > > > <%@ Register TagPrefix="framework" TagName="help" Src="ascx\help.ascx"

    > %>
    > > > and
    > > > <framework:help 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 GenerateHelpLink

    > 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, Jun 26, 2003
    #4
  5. George Durzi

    George Durzi Guest

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

    "Marina" <> wrote in message
    news:%...
    > 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:...
    > > 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 GenerateHelpLink() function doesn't get called though?

    It
    > > doesn't make a diff if I use an <a> or a <asp:hyperlink>
    > >
    > > "Marina" <> wrote in message
    > > news:...
    > > > Instead of using an <a> tag, I would use a Hyperlink control.
    > > >
    > > > Then in page_load do something like:
    > > >
    > > > Hyperlink1.NavigationURL = GenerateHelp();
    > > >
    > > > "George Durzi" <gdurzi@nospam_hotmail.com> wrote in message
    > > > news:%...
    > > > > 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='<%# GenerateHelpLink()%>' class="mischrefcontent2"

    > id="hrfHelp"
    > > > > runat="server" target="_blank">Help</a>
    > > > >
    > > > > In the codebehind help.ascx.cs, I have this:
    > > > > #region GenerateHelpLink
    > > > > protected void GenerateHelpLink()
    > > > > {
    > > > > StringBuilder sb = new StringBuilder();
    > > > > sb.Append("ms-its:");
    > > > >
    > > > >

    > >

    sb.Append(ConfigurationSettings.AppSettings["ApplicationURL"].ToString());
    > > > >

    > sb.Append(ConfigurationSettings.AppSettings["HelpFile"].ToString());
    > > > > string[] arScript =
    > > > >
    > > >

    > >

    >

    Request.ServerVariables["SCRIPT_NAME"].ToString().Split("/".ToCharArray());
    > > > > string sScript = arScript[arScript.GetUpperBound(0)].ToString();
    > > > > sb.Append(sScript.Substring(0, sScript.LastIndexOf(".")));
    > > > > 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.aspx, the above function will return:
    > > > >

    ms-its:http://gdurzi/framework/help/MyFelpFile.chm::/cs_completed.htm
    > > > >
    > > > > In cs_completed.aspx, I do this:
    > > > > <%@ Register TagPrefix="framework" TagName="help"

    Src="ascx\help.ascx"
    > > %>
    > > > > and
    > > > > <framework:help 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

    GenerateHelpLink
    > > 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?
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    George Durzi, Jun 26, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Quentin
    Replies:
    1
    Views:
    474
    Quentin
    Jul 29, 2003
  2. Jason Shohet
    Replies:
    1
    Views:
    474
    Kevin Spencer
    Nov 10, 2003
  3. Holger (David) Wagner
    Replies:
    2
    Views:
    1,930
    Holger (David) Wagner
    Jul 3, 2004
  4. Joe
    Replies:
    1
    Views:
    364
    Jeffrey Tan[MSFT]
    Feb 16, 2004
  5. Felix
    Replies:
    1
    Views:
    330
    Felix
    Sep 29, 2006
Loading...

Share This Page