Parsing HTML Input to C# code on Page Load - c#

I have a tricky question. Hope somebody can answer this for me.
I am using a Site based on DOtnetNuke CMS. I have a page which has an input field
<input name="ct100$dynamicinputfield1" id=ct100$dynamicinputfield1 value="abc">
This input field is auto generated and i cannot change the code for this.
Now i have another module which runs on Page_load
The module has A stored Procedure which expects an input parameter which is the value of the Input field mentioned above.
I supply the parameter to the code using this line
string Id = Request.Form["ctl00$dynamicinputfield1"];
I get the following Error
Error:System.Data.SqlClient.SqlException (0x80131904): Procedure or
function 'GetAddressByID' expects parameter '#ID', which was not
supplied.
I believe this happens because the Server side code executes before the client side. and thus the Request.form cannot find the dynamicinputfield1. How can i solve this Issue.

After posting the form from client side you must have to get this property value.
Before posting the form how can u get one.
second thing you must get the value of the item on server side before posting to client with the original name of the input field.
hope this answer helps.

Related

How to send local variables via post

Via a hidden input field I want to send a value from Site 1 to Site 2.
But at Site 2 it says the value is null.
I guess this is because it is local value. But it has to be local and I'm not sure.
Here is my code where I declare the value (page 1):
string stringproductid = Request.QueryString["id"].tostring();
int productid = stringproductid.AsInt();
Here I send it via a hidden field inside a form (page 1):
<input type="hidden" id="#productid" value="#productid" name="#productid">
Here I try to receive it (at page 2):
string idstring = Request.Form["productid"].ToString(); //error
It should be name="productid" . The # you're using there is making Razor put the value of productID into that attribute. So if you look at your raw generated HTML it is going to be something like name="346".
That belongs in the "value" attribute, which you did correctly, but what you need to be putting in the "name" is the name of the field, so that the browser posts it back correctly with that field name. :-)
On your 2nd page, you should use
string idstring = Request.Form["#productid"].ToString(); //error
On a side note, both Request.QueryString[] and Request.Form[] are always strings, so you don't need to include the .ToString(). I understand it may be defensive coding, but you are just adding CPU cycles. They add up over time.

Parameters not being passed correctly through code

My report gets data from a stored procedure. Two of the six parameters are dates (toDate and fromDate.) I integrate the report with C# Winforms and I pass the parameters through code the code with:
reportDocument.setParamterValue(0,paramValue);
The report works fine but does not render data despite showing the column header properly. When I refresh the report, it pops up the parameter window again. When I enter the parameters through that window the data shows, including column headers. But it doesn't work when I pass parameters through code.
How can I resolve this?
It looks like this:
CRPT.SetParameterValue("smonth", Servercls.month);
See this link for more info.
I suggest first of all call procedure in c# environment and save result in datatable and then send datatable to crystal report.
I found the error.
First it was not working with setting parameters through indexing. so i set the parameters through name as reds suggested.
second i was missing the parameters binding with report viewer object.
so i added the following line and it worked
crystalReportViewer.ParameterField.addRange(reportDocument.ParameterFields);
Thanks for the answers guys.

SSRS report parameter

I have a problem with rendering report with correct parameter.
We have RDL report that has date parameter with default value which is an expression "=today()".
In project i have the following code in c#
for(int i = 0; i < 15; i++)
{
serverReport.SetParameters(new ReportParameter("dt1",date.ToString()));
File.WriteAllBytes(path, serverReport.Render("PDF"));
}
For first iteration sql stored procedure is called with the default parameter and following iterations are called with passed date(i checked it with sql profiler).
I want to mension that in loop i have many other reports with exact same default date parameter but the problem is with this one. I have compared all parameter properties in 2 repors(one that works and the other that is not working properly), but they are identical. I cant find any difference.
If i delete default value "=today()" then report is working fine.
Maybe sameone had similar problem and recommend me something about this. Thanks in advance.
A few things to check:
SetParameters takes IEnumerable<ReportParameter> not a single ReportParameter object. Call it like this instead:
serverReport.SetParameters(new ReportParameter[] { ReportParameter("dt1", date.ToString()) } );
Make sure that the parameter does not have the available values filled in as well as the default value. If the date passed is not one of the valid values (if applied) it won't work. For example, if the available values are set to =Today then the only report that will run properly is the first one that coincidentally uses that value.
Are you sure that date.ToString() is passing an appropriate and valid date?
Does the server's report parameter match the development environment? Parameter settings aren't automatically updated so that any modifications made on the server aren't overwritten by deploying the report again. Check the server's report parameters and update if necessary, or simply delete and redeploy the report.
Try to completely remove the not working report within the server (and to test,also one of the working) and re-deploy both to the server. you could also check in reporting manager for the parameter settings, because there the difference might be visible.
I had that kind of issues before with report parameters and know that the parameter settings are not overwritten correctly all the time you deploy the report.

Problem passing filename between pages (query string)

I've tried and tried but just cannot get a hold of this so let me explain my problem.I have a survey website using xml survey files. On one page I have a category menu which passes relative surveys filename to another page in the redirect as a query string.
~/websurvey.aspx?Survey=gamesurvey.xml
so the name of the survey file is gamesurvey.xml. On another page I have the following to read the filename into a string.
string c = Request.QueryString["Survey"];
now here lies my problem. The control that I have to pass the filename to does not recognise any attempts I make at trying to "dereference" the string. Here is the part in question.
<sstchur:WebSurvey id = "ws"
SurveyFile = "gamesurvey.xml"
AnswersFile = "answers.xml"
runat = "server"/>
</form>
Above where you see gamesurvey.xml thats where I need to pass the string. Here it is hardcoded.This is a problem because I want to be able to call any survey by way of query string without having to make new pages for each of them.
If I put things like
""+c+"" or .toString() or SurveyFile = c
it tells me the server tag is not well formed.
To sum up my problem I need to pass a filepath directly from page to page. By the way, when I put SurveyFile = c I get a pageload error saying the file c cannot be found, i.e. this control will only take a filename not a variable containing it.
Sorry if this is hard to understand but my head is just melted with it now I had to ask.
Any help would be appreciated.
The control im using is the WebSurvey control 4GuysFromRolla and yes I have checked all the documentation and the few forum posts related to it.
And what prevents you from setting that control property in your code-behind?
If you've your "page.aspx.cs", just do that in the Page.Init Page.Load event and you'll be fine!
Maybe I'm wrong and you can't use code-behind or something like that.
i am giving u few options
use
SurveyFile= <% c %>
or since you are not passing the full file path so ur file is not found. give it like ~//root//directory//filename.extension
or may be
u can find some methods to set that parameter using the code behind page.
do tick my answer correct if found useful

Pass string parameter to SqlDataSource in asp.net

i have placed a SqlDataSource component on my aspx page but while configuring the SqlDataSource in the "Test Query" Step I am passing the following parameters :
But when i click ok it returns following error:
This error occurs when i pass the string :
INFO, WARN, ERROR,
I have tried a lot of combinations but nothing works. It works only if i pass one of the three words in single quotes like this :
'ERROR'
Infact the INFO WARN and ERROR are the various levels available in the table. Each record can have only one level and in the sql query i am using IN("-----") to match the criteria, hope you understand.
Any idea to pass the string with comas between them will be highly appreciated.
After you create the page with the dialogue helpers, just switch to code view of your html and change them by hand on the created code...
I have resolved the problem by passing each level in single quotes without , after the last level as shown in the image below:
Anyway thanks for your help Aristos!

Categories

Resources