.NET Questions (CLOSED)

Questions and Answers on any aspect of .NET. Now closed.

This discussion group is now closed.

Have a question about .NET development? Try stackoverflow.com, a worldwide community of great developers asking and answering questions 24 hours a day.

The archives of .NET Questions contain years of Q&A. Even older .NET Questions are still online, too.

Pre-load ASP Label from Query_String

I've done this before, but I'm having a mental block
on the details.

Have a label and a gridview.  Gridview has to get records from database by account number.  Account number comes from query string (CGI param).  Label also shows account number, so Gridview's DS can fetch from label or from query_string.  Either way, label must be loaded from query string.

I do remember how to do it in the VB file, but I'd rather do it in the ASP so I don't have to do a postback to load the GridView.  I thought it should be
<asp:Label ID="Account" runat="server" Text="<%$ Request:QueryString("Account") %>">
but "The server tag is not well formed"
Wes Groleau Send private email
Tuesday, January 15, 2008
 
 
In general, you can't do that. If you don't need to ever manipulate that label other than to set its text, you could just drop the label and do it the old fashioned way. Otherwise, set it from your code-behind.
clcr
Tuesday, January 15, 2008
 
 
Well, perhaps I'm mistaken, but I think I've done it before.

Setting it from the code-behind is easy BUT that requires suppressing the databinding on the GridView till afterword, and do a Postback after setting the label.

Not major, but if there's a better way....
Wes Groleau Send private email
Wednesday, January 16, 2008
 
 
Got rid of the "not well-formed by changing the quote marks to text='<%$ R.QS("name") %>' (Can't nest a quote inside another quote with the same kind of quote mark)

Then it tells me I should use Literal with Request: (colon) instead of label with Request. (dot),
but that is rejected because Request: is not a "registered label"

Got rid of all error messages and got the page to render with

<asp:Label ID="Patient" runat="server" Text='<%# "Account: " & Request.QueryString("Account") %>'>

but the generated HTML is

<span id="Patient"></span>
Wes Groleau Send private email
Wednesday, January 16, 2008
 
 
Well, I must have been mistaken, because I finally found a way to do it that is absolutely not worth the trouble.

Byending ExpressionBuilder, compiling it, making sure the assembly is on the webserver, putting its path in the web.config, tagging it to evaluate during page load, ....

Sheesh, and I was complaining about having to do a postback.
Wes Groleau Send private email
Wednesday, January 16, 2008
 
 
I don't know why I didn't think of it before, but this works:


<asp:Label ID="Patient" runat="server">Account: <%=Server.HtmlEncode(Request.QueryString("Account")) %></asp:Label>
clcr
Wednesday, January 16, 2008
 
 
Thanks!  I will definitely try that.
Wes Groleau Send private email
Thursday, January 17, 2008
 
 
I _did_ do it before, and I finally found the code I did it in.  My O.P. wasn't very clear.  The key was this line:

"Gridview's DS can fetch from label or from query_string"

The answer is going with the _second_ term of the OR:

SelectCommand="SELECT <SQL stuff> WHERE ([Account] = @Account)">
<SelectParameters>
<asp:QueryStringParameter Name="Facility"
        QueryStringField="Hosp" Type="String" />
</SelectParameters>
Wes Groleau Send private email
Thursday, January 17, 2008
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz