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

  • SEARCH
  • Home
  • 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 7570781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:30:27+00:00 2026-05-30T15:30:27+00:00

I write script like this in my .cs file : StringBuilder script = new

  • 0

I write script like this in my .cs file :

 StringBuilder script = new StringBuilder();
 script.Append("<script type=\"text/javascript\"> function submitform(){");
 script.Append(" document.forms['" + ((HtmlGenericControl)frm).Attributes["id"] + "'].submit();} </");
 script.Append("script>");

How can i call this function in the OnClientClick of my link button ?

LinkButton hl_process = new LinkButton();
hl_process.OnClientClick = ""

Edit1:

protected Control CreateCommForm()
{
    HtmlGenericControl frm = new HtmlGenericControl("form");
    frm.Attributes.Add("id", "sal");
    frm.Attributes.Add("method", "post");
    frm.Attributes.Add("action", "https://------");
    /////////////////////////////////////////
    HtmlGenericControl hdn_sal_a = new HtmlGenericControl("input");
    hdn_sal_a.Attributes.Add("id", "hdn_sal_a");
    hdn_sal_a.Attributes.Add("name", "hdn_sal_a");
    hdn_sal_a.Attributes.Add("type", "hidden");
    hdn_sal_a.Attributes.Add("value", Session["emp_num"].ToString());
    /////////////////////////////////////////
    HtmlGenericControl hdn_sal_b = new HtmlGenericControl("input");
    hdn_sal_b.Attributes.Add("id", "hdn_sal_b");
    hdn_sal_b.Attributes.Add("name", "hdn_sal_b");
    hdn_sal_b.Attributes.Add("type", "hidden");
    hdn_sal_b.Attributes.Add("value", Session["user_name"].ToString());

    frm.Controls.Add(hdn_sal_a);
    frm.Controls.Add(hdn_sal_b);

    column1.Controls.Add(frm);
    return frm;

}
  • 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-30T15:30:28+00:00Added an answer on May 30, 2026 at 3:30 pm

    Use jquery to bind to the click event instead of doing this on the server side:

    <a href="#" class="blah">Submit Me</a>
    

    then in javascript something like:

    <script type="text/javascript">
    $('.blah').click(function() {
       document.forms[0].submit();
    });
    </script>
    

    Edit:

    While you can generate UI elements with codebehind it’s not quite the asp.net way. Use repeaters if you must repeat the generation of controls. Actually, creating multiple forms is not the asp.net way either, as it assumes only one form running at the server context and everything else binds to an event on submission. Anyways, it seems you’re still learning asp.net and probably coming form PHP or something similar.

    To accommodate your request, I’d advice to stay away from from generating JS on the server side. Give different class names to your forms and use the same method above. You don’t need a LinkButton to submit the form, a simple anchor <a> fits the bill.

    You can use the ClientID property (if you don’t use classes), but you must first attach the parent control to the page for the algorithm to kick in.

    So, your code would be something like:

    protected Control CreateCommForm()
    {
       ...
       column1.Controls.Add(frm);   
    
       HtmlGenericControl a = new HtmlGenericControl("a");
       a.Attributes["onclick"] = "$('#" + frm.ClientID + "').submit();";
       a.InnerText = "Submit me";
       frm.Controls.Add(a);
       return frm;
    }
    

    The alternative way (better separation of concerns)

    protected Control CreateCommForm()
    {
       ...
       column1.Controls.Add(frm);   
    
       HtmlGenericControl a = new HtmlGenericControl("a");
       a.Attributes["class"] = "submitter";
       a.InnerText = "Submit me";
       frm.Controls.Add(a);
       return frm;
    }
    

    And in javascript we find the parent form and submit it (this can be in a static js file):

    <script type="text/javascript">
    $('.submitter').click(function( 
      $(this).parents('form').submit();
    ));
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a python script that takes record data like this
I have an XML document that looks like this: <file> <name>NAME_OF_FILE</name> </file> <file> <name>NAME_OF_FILE</name>
I have a hindi script file like this: 3. भारत का इतिहास काफी समृद्ध
I have write a script for renaming it is like this for i in
I have a script that will write a given string to a text file...
I would like to write script which deletes New Folder.exe regsvr.exe viruses: My algorithm
Is Delphi have any ability to write script of IDE actions? I would like
I'd like to write a script/batch that will bunch up my daily IIS logs
I'd like to write a script that (under certain conditions) will execute gdb and
I'd like to write my own script in C# to test my own dictionary

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.