Postbackurl from .htm to .aspx?

Last post 08-27-2009 3:56 AM by babymonsta. 41 replies.

Sort Posts:

  • Postbackurl from .htm to .aspx?

    08-26-2009, 9:14 PM
    • Member
      179 point Member
    • babymonsta
    • Member since 08-13-2009, 10:42 AM
    • Singapore
    • Posts 573

    Is there a way to enable a postback from a .htm page to a .aspx page? For instance values are inputted by a user into the .htm page and when the user clicks the button, I want it to trigger a .aspx page which will recieve the inputted data and carry out a certain function. I only know how to use the postbackurl between .aspx pages but is there a way to do the similar thing from a .htm to .aspx?

    Jessie

    * C# Please :)
    * Newbie to ASP.NET, SQL. Please be kind to me :)
    * postbacks & databind HATES me :(
  • Re: Postbackurl from .htm to .aspx?

    08-26-2009, 10:36 PM
    • All-Star
      91,768 point All-Star
    • vinz
    • Member since 10-05-2007, 3:47 PM
    • Cebu, Philippines
    • Posts 13,769
    • TrustedFriends-MVPs

    What about using Querystring to pass data between pages as demonstrated here: http://forums.asp.net/t/1242371.aspx

    "Code,Beer and Music ~ my way of being a programmer"

  • Re: Postbackurl from .htm to .aspx?

    08-26-2009, 11:27 PM
    • Member
      179 point Member
    • babymonsta
    • Member since 08-13-2009, 10:42 AM
    • Singapore
    • Posts 573

    I went through the code, but I didnt get some parts of it. What does this fragment of code mean?

    function recordvalue(button)
    {
    var hiddentext=document.getElementById("Hidden1");

    And my .htm page has a 'drop down list' with values in it. I know in .aspx I can do it easily using the dropdownlist.selected etc but to be done from retrieving it in .htm and posting it to .aspx, have any ideas?
    Jessie

    * C# Please :)
    * Newbie to ASP.NET, SQL. Please be kind to me :)
    * postbacks & databind HATES me :(
  • Re: Postbackurl from .htm to .aspx?

    08-26-2009, 11:44 PM
    • Contributor
      4,405 point Contributor
    • fayaz_3e
    • Member since 09-14-2007, 10:15 AM
    • Hyderabad
    • Posts 901

    Hi,

    The function is taking hidden field value and assigning to a varaible.

    babymonsta:

    function recordvalue(button)
    {
    var hiddentext=document.getElementById("Hidden1");


    If you want DropDownList(since html guess it would be select) value you can do the same

    unction recordvalue()
    {
    var ddl=document.getElementById("DropDownListID");
    var mySelection = ddl.value;
    
    //It gives your ddl selected value
    //Do whatever you want here with this mySelection variable
    form1.action="Default.aspx?value="+mySelection
    }


    Fayaz
  • Re: Postbackurl from .htm to .aspx?

    08-26-2009, 11:53 PM
    • Member
      179 point Member
    • babymonsta
    • Member since 08-13-2009, 10:42 AM
    • Singapore
    • Posts 573

    Currently on my .htm page I have a couple of textboxes, a dropdownlist and a button. I tried to do a retrieve and post of the values inputted in the textbox however whenever I click my button, nothing seems to happen, so probably Ive done something wrong.

    Do I have to write several different record value functions for each textbox and another for my dropdownlist?

    The one I wrote for my textbox (trial and error) is

    function recordvalue()

    {

    var nametext = document.getElementById("name");

    form1.action="confirm.aspx?value="+nametext.value}

    However when I click my button, nothing happens. My confirm.aspx page doesnt come to play.

    I put this code in my .aspx.cs page

    protected void Page_Load(object sender, EventArgs e)
        {
            string str = Request.QueryString["value"].ToString();
            Label1.Text = str;
        }

    Did I miss something out?

    Jessie

    * C# Please :)
    * Newbie to ASP.NET, SQL. Please be kind to me :)
    * postbacks & databind HATES me :(
  • Re: Postbackurl from .htm to .aspx?

    08-27-2009, 12:07 AM
    • All-Star
      91,768 point All-Star
    • vinz
    • Member since 10-05-2007, 3:47 PM
    • Cebu, Philippines
    • Posts 13,769
    • TrustedFriends-MVPs

    Does the value of the querystring displayed in the url?

    "Code,Beer and Music ~ my way of being a programmer"

  • Re: Postbackurl from .htm to .aspx?

    08-27-2009, 12:10 AM
    • Member
      179 point Member
    • babymonsta
    • Member since 08-13-2009, 10:42 AM
    • Singapore
    • Posts 573

    vinz:

    Does the value of the querystring displayed in the url?


    Erm how do I do that?

    Jessie

    * C# Please :)
    * Newbie to ASP.NET, SQL. Please be kind to me :)
    * postbacks & databind HATES me :(
  • Re: Postbackurl from .htm to .aspx?

    08-27-2009, 12:17 AM
    • Participant
      1,402 point Participant
    • prashkumar22
    • Member since 03-31-2008, 4:01 AM
    • Chicago, IL
    • Posts 223

    This might be another way of doing

    //HTML Page
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body>
    <form method="post" action="test.aspx">  
     <input id="Text1" name="test" type="text" />  
         <input id="Text2" name="test" type="text" />  
        <select id="Select1" name="test">
            <option>one</option>
            <option>two</option>
        </select>
         <input id="Submit1" type="submit" value="submit" />  
         </form>
    </body>
    </html>
    
    
    //code-behind page of test.aspx
    
    protected void Page_Load(object sender, EventArgs e)
        {
            String[] values = Request.Form.GetValues("test");
                      
             foreach (String val in values)  
             {              
                 Response.Write(val + "<br/>");  
             } 
        }
    


    Prashant
  • Re: Postbackurl from .htm to .aspx?

    08-27-2009, 12:22 AM
    • All-Star
      91,768 point All-Star
    • vinz
    • Member since 10-05-2007, 3:47 PM
    • Cebu, Philippines
    • Posts 13,769
    • TrustedFriends-MVPs

    babymonsta:

    vinz:

    Does the value of the querystring displayed in the url?


    Erm how do I do that?

    First be sure that you call the function recordvalue in your Button like:

    <input id="Button1" type="button" value="1" onclick="recordvalue(this)" />

    Then check the url displayed in the browser once it navigates to confirm.aspx. the url should have something like this http://localhost/WebSiteName/Confirm.aspx?value = thevalueyoupass

    "Code,Beer and Music ~ my way of being a programmer"

  • Re: Postbackurl from .htm to .aspx?

    08-27-2009, 12:53 AM
    • Member
      179 point Member
    • babymonsta
    • Member since 08-13-2009, 10:42 AM
    • Singapore
    • Posts 573

    I tried both ways, but somehow when I click the button, it doesnt even divert to confirm.aspx at all :(

    Jessie

    * C# Please :)
    * Newbie to ASP.NET, SQL. Please be kind to me :)
    * postbacks & databind HATES me :(
  • Re: Postbackurl from .htm to .aspx?

    08-27-2009, 12:58 AM
    • Contributor
      2,408 point Contributor
    • NihirPorecha
    • Member since 06-26-2009, 8:39 AM
    • Ahmedabad
    • Posts 445

    prashkumar22:

  • <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  •   
  • <html xmlns="http://www.w3.org/1999/xhtml">  
  • <head>  
  •     <title></title>  
  • </head>  
  • <body>  
  • <form method="post" action="test.aspx">    
  •  <input id="Text1" name="test" type="text" />    
  •      <input id="Text2" name="test" type="text" />    
  •     <select id="Select1" name="test">  
  •         <option>one</option>  
  •         <option>two</option>  
  •     </select>  
  •      <input id="Submit1" type="submit" value="submit" />    
  •      </form>  
  • </body>  
  • </html>  
  •   
  •   
  • //code-behind page of test.aspx  
  •   
  • protected void Page_Load(object sender, EventArgs e)  
  •     {  
  •         String[] values = Request.Form.GetValues("test");  
  •                     
  •          foreach (String val in values)    
  •          {                
  •              Response.Write(val + "<br/>");    
  •          }   
  •     }  

  • Above will work perfectly for you.


    Please Mark as answer if it helps you.


    My blog
  • Re: Postbackurl from .htm to .aspx?

    08-27-2009, 1:04 AM
    • Member
      179 point Member
    • babymonsta
    • Member since 08-13-2009, 10:42 AM
    • Singapore
    • Posts 573

    I cant tell if its working or not because right now it doesnt divert to the .aspx page when the button is clicked. And Im not sure why :(

    Jessie

    * C# Please :)
    * Newbie to ASP.NET, SQL. Please be kind to me :)
    * postbacks & databind HATES me :(
  • Re: Postbackurl from .htm to .aspx?

    08-27-2009, 1:10 AM
    • Contributor
      4,405 point Contributor
    • fayaz_3e
    • Member since 09-14-2007, 10:15 AM
    • Hyderabad
    • Posts 901

    babymonsta:

    function recordvalue()

    {

    var nametext = document.getElementById("name");

    form1.action="confirm.aspx?value="+nametext.value}


    Instead of form1.action

    you can try this also

    window.location="confirm.aspx?value="+nametext.value;

    Fayaz
  • Re: Postbackurl from .htm to .aspx?

    08-27-2009, 1:17 AM
    • Participant
      1,402 point Participant
    • prashkumar22
    • Member since 03-31-2008, 4:01 AM
    • Chicago, IL
    • Posts 223

    You have to make sure that action property in the form tag is pointing to correct .aspx page and also its path. Try just by creating a new HTML and .aspx page if possible

    Prashant
  • Re: Postbackurl from .htm to .aspx?

    08-27-2009, 1:21 AM
    • Member
      179 point Member
    • babymonsta
    • Member since 08-13-2009, 10:42 AM
    • Singapore
    • Posts 573

    fayaz_3e:

    Instead of form1.action

    you can try this also

    window.location="confirm.aspx?value="+nametext.value;

    I tried this and my button finally worked, but I got this appear in my textbox.

    [object HTMLInputElement]

    When a name I inputted was supposed to appear.

    It now says undefined

    Jessie

    * C# Please :)
    * Newbie to ASP.NET, SQL. Please be kind to me :)
    * postbacks & databind HATES me :(
Page 1 of 3 (42 items) 1 2 3 Next >