0

Well, I have a built registration form in (navBar.html) and im including this .html to every page in my website (header of the site). code of the form:

<form method="get" action="../RegisterDetails.aspx" id="registerForm" onsubmit="return validateRegister()">
        <h3>Register Form</h3>
        <hr /><br />
        <label id="fnameLabel">First Name: <span>*</span><label id="hiddenfname" class="h-hidden-label">Enter First Name Please</label></label>
        <br />
        <input type="text" id="fname" placeholder="First Name" /><br />
        <br />
        <label id="lnameLabel">Last Name: <span>*</span><label id="hiddenlname" class="h-hidden-label">Enter Last Name Please</label></label>
        <br />
        <input type="text" id="lname" placeholder="Last Name" /><br />
        <br />
        <input type="submit" id="registerSubmit" value="Send" />
        <input type="button" id="cancel" value="Cancel" />
        <br />
    </form>

the form is ok. It have working .js file and .css file. But when i use

<!-- #include file="Adders/navBar.html" -->

In the Home page and register then move to "RegisterDetails.aspx", I'm retrieving the parameters via request.querystring :

string fname = Request.QueryString["fname"];
string lname = Request.QueryString["lname"];

But then I can see that "fname" and "lname" equals to: "" (blank or nothing)

Any solutions for retrieving those parameters from included file ?

2 Answers2

0

Sometimes trapping variables from an include can be tricky. I tend to prefer server controls and then use "this.pageName.." to define exactly where the variables are coming from similar to a MasterPage. Also, you might want to consider some error handling to see exactly what is happening such as:

if(collection == null)
{
    throw new ArgumentNullException("collection");
}
  • Can't comment above (still too new) so will do so here. Be very careful using session state for variables. Very flaky and you end up with huge viewstate messes (not good for SEO etc.). My 2 cents from building giant tier apps.. – Steven Kamis Jan 31 '17 at 00:11
0

I have a built registration form in (navBar.html) and im including this .html to every page in my website (header of the site).

First of all, it is not a good practice. We should have only one form tag in ASP.Net Web Form.

Second, you should not forward user first name and last name in query string. Mainly, user could type anything, and URL might end up invalid. Another reason is user will freak out if they see their name in URL.

One easy way to fix the issue is to create User Control, and attach OnClick server event of registerSubmit button. Then store FirstName and LastName in Session State, and retrieve those values in RegisterDetails.aspx.

Win
  • 61,100
  • 13
  • 102
  • 181
  • Well, can i apply the CSS style on this button even if its known in the user control ? – Tom Altevet Jan 30 '17 at 18:33
  • Do I need to delete "navBar" or something ? or can i just attach this specific element ? – Tom Altevet Jan 30 '17 at 20:39
  • Well, *User Control* and *Session State* are very basic foundation of ASP.Net Web Form. I suggest you to read a book or two. Otherwise, you will be struggling with very basic stuffs. – Win Jan 30 '17 at 22:11