ASCX - Function Not Being Called

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default 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='<%# 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:[url]http://gdurzi/framework/help/MyFelpFile.chm::/cs_completed.htm[/url]

    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 Guest

  2. Similar Questions and Discussions

    1. #40381 [NEW]: Segfault when function is called recursively
      From: guus dot leeuw at guusleeuwit dot com Operating system: RedHat FC6 x64 PHP version: 5.2.0 PHP Bug Type: Reproducible...
    2. a function is not called (simple)
      Hi everybody, Why does endFigure(0 is not called? Thanks, Jean Pierre
    3. URG... Function getting called multiple times for no reason
      This is really driving me crazy: I've got a simple picker menu, generated by AC. There is a master MC, which contains the different menu...
    4. [PHP] Determining where a function is called from..
      Thanks David, I noticed the __LINE__ and __FUNCTION__ magic constants too, but they don't really contain the values I was looking for, as they...
    5. Determining where a function is called from..
      Howdy Fellas, I've got this problem .. not really a problem but still some thing to my disliking. For a project I wrote some database handling...
  3. #2

    Default 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.NavigationURL = GenerateHelp();

    "George Durzi" <gdurzi@nospam_hotmail.com> wrote in message
    news:%23jr71aAPDHA.1608@TK2MSFTNGP11.phx.gbl...
    > 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:[url]http://gdurzi/framework/help/MyFelpFile.chm::/cs_completed.htm[/url]
    >
    > 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 Guest

  4. #3

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

    "Marina" <zlatkinam@nospam.hotmail.com> wrote in message
    news:exh7VrAPDHA.452@TK2MSFTNGP11.phx.gbl...
    > 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:%23jr71aAPDHA.1608@TK2MSFTNGP11.phx.gbl...
    > > 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:[url]http://gdurzi/framework/help/MyFelpFile.chm::/cs_completed.htm[/url]
    > >
    > > 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 Guest

  5. #4

    Default 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:eeQICvAPDHA.1584@TK2MSFTNGP11.phx.gbl...
    > 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" <zlatkinam@nospam.hotmail.com> wrote in message
    > news:exh7VrAPDHA.452@TK2MSFTNGP11.phx.gbl...
    > > 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:%23jr71aAPDHA.1608@TK2MSFTNGP11.phx.gbl...
    > > > 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:[url]http://gdurzi/framework/help/MyFelpFile.chm::/cs_completed.htm[/url]
    > > >
    > > > 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 Guest

  6. #5

    Default 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@nospam.hotmail.com> wrote in message
    news:%2365EY6APDHA.2316@TK2MSFTNGP11.phx.gbl...
    > 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:eeQICvAPDHA.1584@TK2MSFTNGP11.phx.gbl...
    > > 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" <zlatkinam@nospam.hotmail.com> wrote in message
    > > news:exh7VrAPDHA.452@TK2MSFTNGP11.phx.gbl...
    > > > 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:%23jr71aAPDHA.1608@TK2MSFTNGP11.phx.gbl...
    > > > > 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:[url]http://gdurzi/framework/help/MyFelpFile.chm::/cs_completed.htm[/url]
    > > > >
    > > > > 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 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139