简体   繁体   English

通过“ request.querystring”从包含的html文件中检索参数

[英]retrieving parameters via “request.querystring” from included html file

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). 好吧,我在(navBar.html)中有一个内置的注册表格,我将这个.html包括在我网站的每个页面(该网站的标题)中。 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. 它具有有效的.js文件和.css文件。 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 : 在主页中进行注册,然后移至“ RegisterDetails.aspx”,我通过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) 但是然后我可以看到“ fname”和“ lname”等于:“”(空白或不显示)

Any solutions for retrieving those parameters from included file ? 从包含的文件中检索那些参数的任何解决方案?

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. 我倾向于使用服务器控件,然后使用“ this.pageName ..”来准确定义变量与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");
}

I have a built registration form in (navBar.html) and im including this .html to every page in my website (header of the site). 我在(navBar.html)中有一个内置的注册表单,即时消息中包括了该.html到我网站的每个页面(网站标题)中。

First of all, it is not a good practice. 首先,这不是一个好习惯。 We should have only one form tag in ASP.Net Web Form. 在ASP.Net Web表单中,我们应该只有一个表单标签

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. 主要是用户可以输入任何内容,并且URL最终可能无效。 Another reason is user will freak out if they see their name in URL. 另一个原因是,如果用户在URL中看到自己的名字,他们会大吃一惊。

One easy way to fix the issue is to create User Control , and attach OnClick server event of registerSubmit button. 解决此问题的一种简单方法创建User Control ,并附加registerSubmit按钮的OnClick服务器事件。 Then store FirstName and LastName in Session State , and retrieve those values in RegisterDetails.aspx. 然后将FirstNameLastName存储在Session State中 ,并在RegisterDetails.aspx中检索这些值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM