Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4621884
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:45:52+00:00 2026-05-22T02:45:52+00:00

I am working on a task where I am creating some input control dynamically

  • 0

I am working on a task where I am creating some input control dynamically and i am creating a js file using streamwriter in c# code to validate the input control. Now I want to add reference to the currently created js file in my aspx page.

my create input control method is a webmethod and I call it using ajax-json from client side.
web method:

[WebMethod]
public static string LoadDatanGenerateControls(int PostTypeID, int CategoryID)
{
    DataTable dtControls = new DataTable();
    StringBuilder sb = new StringBuilder();
    dtControls = PostingExtendedFields.GetExtendedDFields(PostTypeID, CategoryID);
    sb.Append("<table>");
    foreach (DataRow dr in dtControls.Rows)
    {
        sb.Append("<tr><td>");
        sb.Append("<input value=';" + dr["RequiredError"].ToString() + "'; type=';text'; size=';20'; id=';txt_" + dr["FieldName"].ToString() + "'; class=';riTextBox riEmpty'; style=';width:450px;'; onfocus =';Focus(this);'; onblur=\"Blur(this,';" + dr["RequiredError"].ToString() + "';);\"/>");
        sb.Append("</td></tr>");
    }
    sb.Append("</table>");
    //create the js file
    string path = HttpContext.Current.Server.MapPath("") + "\\";
    if (File.Exists(path + "sale.js")) File.Delete(path + "sale.js");//delete if exist
    using (StreamWriter sw = new StreamWriter(path + "sale.js"))
    {
        sw.WriteLine("function Focus(obj) {");
        sw.WriteLine("var id = obj.id;");
        sw.WriteLine("$(';#'; + id).val(';';);");
        sw.WriteLine(" }");
        sw.WriteLine("function Blur(obj, title) {");
        sw.WriteLine("var id = obj.id;");
        sw.WriteLine("if ($(';#'; + id).val() == ';';) {");
        sw.WriteLine("$(';#'; + id).val(title);");
        sw.WriteLine("}");
        sw.WriteLine(" }");
    }
    return sb.ToString();
}

On the aspx page:

 function LoadControls() {
        try {
            var types = $find("<%= ddlPost.ClientID %>");
            var Category = $find("<%= ddlCategory.ClientID %>");
            var typeID = types.get_value();
            var catID = Category.get_value();
            ///web method
            $(';#TDDynamicContents';).html(';';);
            $.ajax({
                type: "POST",
                url: "Default.aspx/LoadDatanGenerateControls",
                data: "{';PostTypeID';:';" + typeID + "';,';CategoryID';:';" + catID + "';}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                    if (msg.d.length > 0) {
                        $(';#TDDynamicContents';).html(msg.d);
                        //add js file path
                        addjsfile("sale.js", "js")
                    }
                },
                async: false,
                error: function(xhr, status, error) {
                    alert(xhr.statusText);
                }
            });
        } catch (e) { }
    }

    function addjsfile(filename, filetype) {
        alert(filetype);
        if (filetype == "js") {
            var fileref = document.createElement(';script';);
            fileref.setAttribute("type", "text/javascript");
            fileref.setAttribute("src", filename);
        }
        if (typeof fileref != "undefined") {
            document.getElementsByTagName("head")[0].appendChild(fileref);
            alert(fileref);
        }
    }

but my addjsfile function is not working at all.
its not adding the refrence in the Head section and I am unable to use functions in the js file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:45:53+00:00Added an answer on May 22, 2026 at 2:45 am

    the solution to your problem is to use the following line of code in the event wherever you are using the js functionality or simply on the page load
    ClientScript.RegisterClientScriptInclude(“MyScript”,”MyJavaScript.js”)
    more detailed discussion goes here


    if you only intend to use javascript block to do this then have a look at it if it can be of any help

    Click Here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've inherited the task of creating a schema for some XML which already exists
I'm creating a page that has some dynamically generated images built from data that
I'm working with some code that does a bunch of asynchronous operating with various
I am working on vb.net win form. My task is display the file names
A common task in programs I've been working on lately is modifying a text
Working with python interactively, it's sometimes necessary to display a result which is some
Working in Eclipse on a Dynamic Web Project (using Tomcat (v5.5) as the app
Working with an Oracle 9i database from an ASP.NET 2.0 (VB) application using OLEDB.
I am creating a script on the fly to ftp some files from a
When working on small projects or some test classes , I would prefer to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.